ru Русский

Reticularium

NETWORKS PLACE

Useful to sync gems across servers. Converts gem list --local output to a bunch of gem install commands. Rails related gems are removed from the initial list.


gem list --local | grep -v '\*' | grep -v ^$ | grep -v ^action | grep -v ^active | grep -v ^rails | grep -v ^rack | grep -v ^rake | sed 's|(|-v=|' | sed 's|)||' | sed 's|^\(.*\),|\1\n\1|' | sed 's|=.*[[:space:]]|=|' | sed 's|^|gem install |'

I am used to ask Linux utility date about everything related to date/time, like date -d "next friday" or date -d "+245 min", but it doesn’t answer one question I have pretty often: what time is it now in certain timezone?

So I had to create a simple script for this:

1
2
3
4
5
6
7
#!/bin/bash

localtime=`date +"%x %X"`
zonediff=`date -d "$1" +"%H:%M"`
hours="`echo $zonediff | cut -d':' -f1` hours"
minutes="`echo $zonediff | cut -d':' -f2` minutes"
date -d "-$hours -$minutes" +"%x %X"

Zone here is represented by alphabetic abbreviation, that is if you named this script e.g. “timein”, you use it like this:

timein EDT

Well, quite self-explanatory. Only Bash and Ruby. Options “folder” and “name” are examples, replace them with what you need… Shared in hope this can help someone.

Read the article

This is a really annoying problem we meet pretty often. You can meet it even if you don’t use Bash. For example, you upload an image named “my lovely cat.jpg” to your website and find no image there. Or it has no thumbnail. This may happen because you are using some program for making thumbnails that is being called from, say, PHP via backtick operator (that is, using unix shell) and that program interprets the file name passed to it as three different command line options: my, lovely and cat.jpg.

Read the article

It’s not easy to remember, so here’s the reference.

var=aaa.bbb.ccc

  % %% # ##
  .*  ${var%.*} => aaa.bbb ${var%%.*} => aaa ${var#.*} => aaa.bbb.ccc (doesn’t work) ${var##.*} => aaa.bbb.ccc (doesn’t work)
  *.  ${var%*.} => aaa.bbb.ccc (doesn’t work) ${var%%*.} => aaa.bbb.ccc (doesn’t work) ${var#*.} => bbb.ccc ${var##*.} => ccc
Read the article

I like HD, it makes possible to see more details.

In Die Hard 4, in the scene where Matthew is chatting with Warlock right before McClain visit, Matthew’s desktop is visible on his Apple monitor. First interesting thing, there is Windows. Not looking like default Windows theme of course, but some icons on the desktop make it apparent (e.g. Cain and Abel – Windows password recovery tool).

Another funny thing is some kind of console there that is running.. what do you think? – of course nmap! Since The Matrix nmap is a must have utility for any serious movie about hackers (product placement, huh?). But what Matthew is running it against? Some Government or Pentagon servers? Not at all, the exact command is:

nmap -v -T4 -A insecure.org scanme.nmap.org

So he is doing his hard everyday hackers work scanning the nmap utility developers’ website and the host specially created for everybody could test nmap against it :)

I am not blaming anybody, this movie is much better in this regard than most of others. After all, what else would they scan?

I was doing a simple test of pwgen (handy utility to generate passwords) and since this test was creating a lot of files in a folder I decided to combine it with a test of ls speed vs find speed:

Read the article

If you have Vim syntax highlighting enabled, the code example below will be highlighted incorrectly: 2, 3 and 4 lines (as well as the all lines below) will be all in blue as if they are comments. This happens because Vim considers everything after /* as a commentary.

1
2
3
4
for script in ${rpath}/*.mon.sh
do
   $script ${1}
done
Read the article

Bash files test operators reference. Everybody using Bash actively should know at least -e -f and -d operators, but there are many others :)

Read the article

Bash special variables reference. Everybody using Bash actively should know at least positional variables, Return value variable, Process ID variable, but there are also many others..

Read the article