Posts Tagged cool

Advanced Perl debugging with Aspect

So I had this huge bunch of Spreadsheet::WriteExcel code where I was generating Excel sheets from some statistics I was gathering and I noticed that everytime I opened the Excel file I got a message with something along the lines “File error: data may have been lost”, but on a casual look the spreadsheet looked fine… but of course the devil is in the details. It turns out that if you happen to Spreadsheet::WriteExcel::write in the same cell twice (or more I guess :) ) that error message is what my Excel produces…. So how to find where the problem is… in this huge bunch of writes…

Enter Adam Kennedy’s excellent Aspect library for Perl, a truly brilliant module!! Thanks Adam!

How did I use it in this case? Here goes…

.... lots of other code....

use Aspect;

my $pointcut = call qr/Spreadsheet::WriteExcel::Worksheet::write$/;
# Observe the $ at the end, otherwise write_string will also match, and we don't want that

...... code passes ...

sub in_my_big_excel_write_block {

my %spcoords = ();
my $before_write = before {
my @args = @{$_->params};
if ( $spcoords{$args[1]}{$args[2]} ) {
croak "Will do double write at coord: ["
. $args[1] . "," . $args[2] . "] = >" . $args[3] . "<\n" . "Previous write at coord: [" . $args[1] . "," . $args[2] . "] = >" .
$spcoords{$args[1]}{$args[2]} . "<\n"; } $spcoords{$args[1]}{$args[2]} = $args[3]; } $pointcut; .... lots of $worksheet->write(...) code....


Now my poor perl script will die with a message telling me where and what I tried to write double and what I wrote there previously, now it’s easy to find!


A more general debugging tip would be this simple “before” advice:

before {
if( ($cnt % 1000) == 0 ) {
my @args = @{$_->params};
print "Calling " . $_->sub_name . " with args : " . Dumper(@args) . "\n";
sleep 1;
} $pointcut;

Neat huh!? And trust me, this is only some small simple example of the power of the Aspect library.

Tags: , , ,

A real Turing Machine

Isn’t this too cool!!??

I want one!

Tags: , , , ,

Pipe Emacs buffer through Perl

Ok, this is sooo cool! :) For us who love Perl and often have the feeling of “If I could just filter this emacs buffer through Perl, how happy I would be!” here’s a tip:

Step 1: Mark the buffer (or the parts of it that you are interested on running through Perl).
Step 2: Type M+| (“Escape” + “|” (vertical bar) on your normal keyboard) or
Step 2 (alt): Issue the “shell-command-on-region” elisp function
Step 3: Enter your perl magic, for instance ‘perl -ne “print if /gnu/”‘ to remove all lines which does not match “gnu”
Step 4: Be amazed!

Now, the result will end up in the minibuffer if it can fit on one line, otherwise a new “shell command output buffer” will be created and hold your stuff.

Tags: , , ,

Firefox download manager

Just discovered the other day that the Firefox “Downloads” (“Filhämtaren”) thingy is really a full fledged “Download Manager”, i.e you can drag-and-drop url’s on it and it will download them for you. Now, maybe it is only me in the whole world that didn’t know that, but from time to time I have been looking for a simple download manager to solve this particular problem for me, without realizing I had one under my nose the whole time. :)

Tags: , ,

Google Goggles

Google fortsätter att vara innovativa:
Google Goggles söker på bilder! Coolt!

Tags: ,

High flying

Idag, sista dagen på Ericsson Rational User Conference i Kista Science Tower sprang jag på en gammal polare, Daniel som jobbar på SenseGraphics som har sina kontor på våning 30 i denna maffiga byggnad, jag hade sån tur att han hade några minuter över och erbjöd mig en titt upp i deras kontor, och det tackar man ju inte nej till, och vilken utsikt dom hade!!! Det fina vädret just idag försämrade ju inte direkt upplevelsen heller! SenseGraphics håller på med riktigt coola saker, haptiska interface dvs man har fysiska objekt som man kan kontrollera och manipulera objekt i datorn med, den fysiska interfacet kommer sen att simulera motstånd, vikt, yta, position etc. i den virtuella miljön.


Coola Mods

Hittade en site av en snubbe som håller på med “Mods”, riktigt coola och proffsiga grejjer faktiskt