Lowercase Filenames With Ruby

Posted by admin Fri, 28 Jan 2011 12:31:00 GMT

ruby -e 'Dir.glob("*").each { |fn| File.rename(fn, fn.downcase) }'

Obviously this would work with method #upcase as well.

Credit goes to poster "Florian Gilcher", here:

http://www.eggheadcafe.com/software/aspnet/35719452/oneliner-for-lowercasing-files.aspx

Posted in ,  | Tags ,  | no comments | no trackbacks

Which Process Is Using Port ?

Posted by admin Wed, 28 Jul 2010 15:01:00 GMT

For some reason, the "-o" option is missing from netstat on OS X Snow Leopard (10.6.4, anyway), so if you need to know which processes are using a given port, try:

sudo lsof -i -P | grep 36364

Of course substitute your own port number (36364 is used by Skype, btw).

Posted in  | Tags , , , , , , , , , ,  | no comments | no trackbacks

Chuck + Ngrep: Listening to the Network

Posted by admin Sun, 11 Jul 2010 15:01:00 GMT

chuck: http://chuck.cs.princeton.edu/

ngrep: http://ngrep.sourceforge.net/

Using chuck and ngrep, you can translate the ascii output of ngrep into midi sounds in real time by reading from a file with chuck which is being appended by ngrep:

sudo ngrep -d en1 '' > network

chuck listen.ck < network

listen.ck source:

// computer key input, with sound
KBHit kb;

// patch
Impulse i => BiQuad f => dac;
// set the filter’s pole radius
.99 => f.prad;
// set equal gain zeros
1 => f.eqzs;
// initialize float variable
0.0 => float v;
// set filter gain
.5 => f.gain;

// time-loop
while( true )
{

    // wait on event
    kb => now;
    // generate impulse
    1.0 => i.next;
    // loop through 1 or more keys
    while( kb.more() )
    {

        // set filter freq
        kb.getchar() => int c;
        if(c < 58) 58 %=> c;
        if(c > 120) 120 %=> c;
        c => Std.mtof => f.pfreq;
        // print int value
        <<< ascii:, c >>>;

    }

}

Sounds a bit like a colorful geiger counter.

Maybe you can ngrep for something specific and learn to recognize the sound of it amongst other traffic.

Posted in ,  | Tags , , , , , , , , , , , , , , ,  | no comments | no trackbacks

List Filenames without Extensions

Posted by admin Fri, 11 Jun 2010 17:42:00 GMT

ls -1 | sed 's/.[.]*$//'

Posted in  | Tags , , , ,  | no comments

dos2unix didn't work

Posted by admin Sun, 02 May 2010 16:47:00 GMT

Fine, then, we'll use Perl. OUTTA THA WAY!!!!!

Remove pesky windows carriage returns:
perl -pi.bak -e 's/\r/\n/g;' ./thefile

Posted in ,  | Tags , , , , , , ,  | no comments

Line 1: One-Liner

Posted by admin Sun, 02 May 2010 14:12:00 GMT

Turn a list into quoted comma separated values for a perl array:

perl -i.bak -ne 's/^(.*?)\n$/\"$1\",/;print' ./list_of_bare_strings



 



Oh,  but your list is just a bunch of filenames you copied from the output of 'ls' and you need them one-per-line:



printf "%s\n" $(>pasted_ls_output) < list_of_bare_strings

Posted in ,  | Tags , ,  | no comments | no trackbacks