Wednesday, December 01, 2010

Create a .mo file from .po file for i18n

Quite simple (on a OS X 10.6, at least), simply run:
msgfmt -o [output_file].mo [input_file].po

Monday, November 29, 2010

Don't require password for sudo

Simple but forgettable because it's done only once...
$ sudo visudo #add desired username to the file in the following format:
[user_name] ALL=NOPASSWD: ALL

Wednesday, November 10, 2010

Enable color-coding for diff in TextMate

You can pipe output from diff command as well as pipe the output of a diff from a source control tool directly into TextMate (e.g., diff v1 v2 | mate or hg diff | mate).
However, you may be missing the nice coloring in the newly opened window that is supporte by TextMate by default. As it often is the case, getting this to work is easy but you first need to find how to get there. So, to toggle the coloring, simply press Ctrl+Option+Shift+D (if this does not work on your system, go to Bundles->Bundle Editor->Show Bundle Editor click on Diff bundle. In the Activation text field is the keyboard shortcut you can use to toggle color coding for diff). Enjoy!

Wednesday, September 01, 2010

Profile SGE queues

As root, run the command "qconf -tsm" on your head node. That will cause a one-time scheduler profiling run to be dumped to a text file called "schedd_runlog" in your $SGE_ROOT/ $SGE_CELL/common/ directory. This file can then be examined for any anomalies if things are otherwise not running smoothly.

Saturday, July 10, 2010

Replace entire line that contains given text

I need to replace an entire line that contains a certain string with another line. This is especially useful in case of editing configuration files that have predefined fields but values may be different.


Say the string you are looking for is STRING_TO_BE_REPLACED.
And the line you want to insert is LINE_TO_REPLACE_WITH.
 

sed 's/^.*STRING_TO_BE_REPLACED.*$/LINE_TO_REPLACE_WITH/'  input_file > new_file

The ^ is a start of line anchor, the '.*' is a wildcard, the $ is a end of line anchor.

Tuesday, February 02, 2010

Unable to find a $JAVA_HOME at … on Mac OSX

Every time I would use java on my Mac,  I kept getting the following error:
>java -version
Unable to find a $JAVA_HOME at “/usr”, continuing with system-provided Java

I tried setting the environment variable JAVA_HOME=/usr but the error remained when running java.

I found the following solution here:
First, find out where java actually is:
>ls -l' `which java`
/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

I noticed a command called java_home in that same directory. Running that command yields the correct java home directory.
>/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

To correctly set the my JAVA_HOME environment variable in future, I added the following to my ~/.profile
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home`
Restart terminal and enjoy.

Wednesday, January 27, 2010

Prepend every line in a file with some text

Say you have a file 'files.txt' looking like this:
p1-c-b-1.fastq.gz
p1-c-b-2.fastq.gz
p1-c-c-1.fastq.gz


Now, you would like to add a full URL path to each of those lines, prepending existing text.
Use awk as follows:
$ cat files.txt | awk '{ print "http://www.complete.url.com/", $0; }' > links.txt

You get a file names 'links.txt' looking like this:
http://www.complete.url.com/ p1-c-b-1.fastq.gz
http://www.complete.url.com/ p1-c-b-2.fastq.gz
http://www.complete.url.com/ p1-c-c-1.fastq.gz


To get rid of introduced extra white space, use sed:
$ cat links.txt | sed 's/ //g'

Tuesday, January 26, 2010

Monitor network traffic on OpenSolaris from command line

To check a summary of network activity for a NIC, use:
# netstat -i 1
    input   xnf0      output       input  (Total)    output
packets errs  packets errs  colls  packets errs  packets errs  colls
1111615 0     745655  0     0      1111684 0     745724  0     0    
399     0     306     0     0      399     0     306     0     0    
416     0     343     0     0      416     0     343     0     0 


To expolore actual packets crossing the network, use snoop command. It captures both TCP and UDP traffic. It is a tool that is shipped with Solaris.

Here is sample output:
# snoop
Using device xnf0 (promiscuous mode)
cbcb-vs.umiacs.umd.edu -> domU-12-31-39-04-EC-47.compute-1.internal TCP D=60088 S=8021 Ack=4204280156 Seq=2401233531 Len=1460 Win=92
domU-12-31-39-04-EC-47.compute-1.internal -> cbcb-vs.umiacs.umd.edu TCP D=8021 S=60088 Ack=2401246671 Seq=4204280156 Len=0 Win=49640 Options=

domU-12-31-39-04-EC-47.compute-1.internal -> dhcp243113.rollins.emory.edu TCP D=49769 S=22 Push Ack=4234202219 Seq=2467318705 Len=192 Win=49232




It shows source and destination servers, type of traffic, source and destination ports, as well as some packet info.