Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

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!

Tuesday, February 05, 2008

Add multiple linux timing results (output in seconds)

If there are multiple files with timing results resulting from Linux 'time' command:
$ cat outputFile* | grep real
real 4m5.047s
real 2m51.264s
real 2m52.414s
real 2m52.293s

And these timings need to be converted into seconds and added into a single number (e.g., 761.018), use the following command:
cat outputFile* | grep real | cut -f 2 | sed 's/m/*60+/' | sed 's/s//g' | bc | awk '{ printf "%s", $0 "+" }' | sed '$s/.$/\n/' | bc

Convert output of linux 'time' command to show seconds only

After executing Linux 'time' command, the following output is obtained:
real 2m52.293s
user 1m39.670s
sys 0m4.370s

Use the following command to extract value for 'real' time only and convert the output to seconds only (i.e., convert 2m52.293s into 172.293):
cat outputFile* | grep real | cut -f 2 | sed 's/m/*60+/' | sed 's/s//g' | bc

Wednesday, July 11, 2007

Using Threads in Java

The way threads work in Java is that there has to be a class implementing either Runnable interface of extends Thread class. Either way, run method must be overridden wihh desired functionality. From the client class, a new thread must be created (as below) where the first argument passed is an an instance of the class you want executed as a separate thread. Once this is done, the thread can be started by invoking start method.

Thread thrd = new Thread(new ClassImplementingThreadFunc(param1,param2));
Thread thrd2 = new Thread(new ClassImplementingThreadFunc(newParam1,newParam2));
thrd.start();
thrd2.start();

Tuesday, July 10, 2007

Numerical sort in Perl

If trying to sort a hash based on key where keys are numerical, using just
foreach $Key (sort keys %Output_Hash) will sort/output values as follows:
1
10
11
...
2
20
21
...

In order to get proper numerical sort, modify above code as this:
foreach $Key (sort {$a <=> $b} keys %Output_Hash)
This will make a comparison on each of the keys and result will be what is needed:
1
2
3
...
10
11