Posts

Showing posts from February, 2009

Javascript and NaN

I always seem to forget but you have to use the function isNaN to test javascript variable. I always want to write it wrong with value == NaN ... Here is an example of it (not a great one but a general idea of what's going on): var num = Number(v); if ( isNaN(num)) console.debug("v is not a number"); Such a strange thing that num isn't null or that it doesn't throw an exception. The crazy typing stuff inside of languages :)

Template Toolkit virtual methods with less mess

Template Toolkit has a very cool feature called Virtual Methods . It provide methods on native Perl5 data types. An example is this (In TT syntax): [% listy = [ 47, -47, 42, -55, 4, -24 ] %] [% listy.size %] [% listy.join(', ') %] Often its called autoboxing . Well TT allows you to define your own. The details are available in the TT VMethod Manual . In that page there is a TODO about a method called define_vmethod . Since I like to use TT from CGI::Application and I don't like to actually see its guts. I choose to find a way to add a vmethod without the unpretty $Template::Stash::LIST_OPS->{} syntax. I think that is quite unfriendly to TT noobs like most of my coworkers. I found that define_vmethod is available off the TT Context object. This is available with $tt->context or in my case off plugin TT object in CGI App $self->tt_obj->context . The parameters are context->define_vmethod( $type, $name, \&implementation ) $type - data type, 'scalar...

vim - insert current filename

When writing comments in source code or for some other reason than I can think of right now, I like to include the current filename into current vim session. How? Enter insert mode use following key sequence: ctrl-r % POOF! You have the filename (it does include the path). In vim % is the current filename. It is very useful when writing mappings or running commands from the : prompt.

Frozen Perl 2009

Frozen Perl 2009 is right around the corner, well its on Sat Feb 6. Be there or be cubed (ice cube)...

Not really goodbye to Google Notebook

I really like Google Notebook but it seems that Google doesn't see it as having many more features to add. Fair enough, they aren't killing it, just not adding to it. Maybe that is called feature complete. Today at work I was wishing for an Open Source version of it that I could install locally for priority work stuff. Maybe its time to start creating one... with all that free time :) Google Notebook Blog - Statement about Development Stopage

Weird make/gmake error

When gmake'ing tools, I started to get strange errors like: /bin/bash: complete: command not found /bin/bash: /home/users/lcarmich/etc/bash_completion: line 220: syntax error near unexpected token `((' What I forget is that I build my own newer bash version (3.x) to be able to use the shell completions (and many other features) and the system default is 2.x. Don't ask about that. But gmake grabs the shell first in your path (older bash in my case). I found that you can grab different version parts from bash in the BASH_VERSINFO array. Well I only really care about major version and this is available in variable BASH_VERSINFO or array element 0 BASH_VERSINFO[0] I updated my bashrc to check version then load completions: if [ -r $BASH_COMPLETION -a $BASH_VERSINFO -ge 3 ]; then . $BASH_COMPLETION fi For future reference you can get array elements in bash with ${VARNAME[INDEX]} . For example: mnsdev11 (netcat-0.7.1)$ echo $BASH_VERSION 3.2.0(1)-release mnsdev11 (netcat-0.7.1)...