Thursday, September 16, 2010

Portable script shebang

Let say you need a script to execute on multiple systems but the admins and OS's all have there own idea on where things belong. Here is a quick way to get the script to locate the interpreter 99% of the time

#!/usr/bin/env perl

Tuesday, September 14, 2010

Quick and dirty hex converter

void convertHex()
{
    string exchangeHex = "0123";
    int exchange;

    //exchangeHex
    std::stringstream ss;
    ss << std::hex << exchangeHex;
    ss >> exchange;
 
    cout << exchange << endl;
}

Tuesday, September 7, 2010

Googles got a bouncy logo

UPDATE: Rob Hawkes has recreated it in html5 here;

http://rawkes.com/experiments/google-bouncing-balls-canvas/

And Mark Brenig-Jones has mod'ed it slightly
http://dotty-dots.appspot.com/?h=40526f624861776b6573

http://rawkes.com/blog/2010/09/07/recreating-googles-bouncing-balls-logo-in-html5-canvas



ORIGINAL POST:
http://www.google.fr/

probably just for today..

a fatal relocation error

A fatal relocation error:

This error means that you have included a dynamic library in your build but at run time the library that it uses is mismatched. This can happened if you rebuilt the lib after the exe, or failed to move the new lib into place etc.

Monday, September 6, 2010

xterm colors and settings

Edit ~/.Xresources and add the following

xterm*foreground: white
xterm*background: black

Then execute this command
xrdb ~/.Xresources
Then open a new terminal to test.

Here is a more complex version of it
http://www.xfce.org/various/Xresources.txt

Wednesday, September 1, 2010

graphviz map of the linkage between .a files

This hacked up piece of perl script will generate a dot compatible piece of text that will display the mapping of the libs in a project.

#!/usr/bin/perl 

my $path = "path/to/libs"

# get the nm results for the system
@ret = `find $path | grep "\.a$" | xargs nm -A`;
#@ret = `cat data.tmp`;

# 0 = lib[object]
# 6 = DEF/UNDEF 
# ./path_to_lib.a[object_in_lib.o]: [152]   |             0|           0|FUNC |GLOB |0    |UNDEF  | func_name_in_obj

my $count = 20;

my %defs     = ();
my %connects = ();

# break appart the result and map what are uages of functions and what are definations

print " // mapping functions...\n";
foreach $line (@ret)
{
    chomp($line);
    @cols = split(/\|/, $line);

    $file  = $cols[0];
    $undef = $cols[6];
    $func  = $cols[7];

    # $file =~ s/:.*//;  # for in lib object inter-dependency...
    $file =~ s/\[.*//;    # for lib file inter-dependency...
    if( $undef =~ /UNDEF/ )
    {
 $connects{ $func }{ $file } = 1;
    }
    else
    {
 $defs{$func} = $file;
    }
}

# now merge the usage with the definition as the file linkage
my %map = ();

print " // merging func usage to definition...\n";
foreach $func (sort keys %connects)
{
    $files = $connects{$func};
    $def_file = $defs{$func};

    foreach $file (sort keys %$files)
    {
 $map{$def_file}{$file} = 1;
    }
}

my %node = ();
my $node_count = 0;

print " // generating node index...\n";
foreach $src_file (sort keys %map)
{
    unless( exists( $node{$src_file} ) )
    {
 $node{$src_file} = $node_count;
 $node_count = $node_count + 1;
    }

    $files = $map{$src_func};
    foreach $tar (sort keys %$files)
    {
 unless( exists( $node{$tar} ) )
 {
     $node{$tar} = $node_count;
     $node_count = $node_count + 1;
 }
    }
}

print " // generating dot file...\n";

print "digraph linkmapping {\n";
foreach $key (sort keys %node)
{
    $idx = $node{$key};
    print "    n$idx [label=\"$key\"];\n";
}

foreach $src_file (sort keys %map)
{
    $files = $map{$src_func};
    $src_node = $node{$src_file};

    foreach $tar (sort keys %$files)
    {
 $tar_node = $node{$tar};
 print "    n$tar_node -> n$src_node;\n";
    }
}
print "}";

Execute with the following (assuming you called the saved file "nm_deps.pl"
nm_deps.pl > map.dot
dot map.dot -Tpng -omap.png

count the occurace of words in a file

cat filename | tr '[:punct:]' ' ' | tr ' ' '\012' | sort | uniq -c | sort -n