Friday, June 5, 2009

Make your config files very flexible (w/ Perl eval)

I have to make my config files flexible so that I can allow my users a lot of options and even override functions. I can do this by making my config file "eval"-able. Meaning that the config file is actually Perl code that can be interpreted by the calling Perl script.

Most of the code was taken from:

http://www.usenix.org/publications/perl/perl13.html

Here is my proof of concept code:

##### FILE: evalConfigExample.pl #####


#!/usr/bin/perl -w
# Filename: evalConfigFileExample.pl
# This is a proof of concept script to show how one can use a perl script as a config.
# file. This allows much more freedom when declaring a configuration file. One can
# call functions, redefine functions and generally do anything that you could.
# normally do in a regular perl script. Ex:
#; ~/bin/evalConfigFileExample.pl -file ~/bin/evalConfigFileExample.cfg

use Getopt::Long;
use Data::Dumper;
use Pod::Usage;

my $page_info ;
my %opts = ();
my $ok = GetOptions(\%opts,
'file=s',
'help'
);
if ( !$ok ) { die; }
pod2usage(1) if (exists ( $opts{help} ) );

sub printer {
print "In Perl prog\n";
}

sub hello_world {
print "Calling hello_world from eval'd config file!\n";
}

sub parse_cfg {
my($file) = @_;
delete($INC{$file});
eval('require("$file")');
die "*** Failed to eval() file $file:\n$@\n" if ($@);
print ("VENDOR = $VENDOR \n");
}

printer();
parse_cfg( $opts{file} );
print ("VENDOR = $VENDOR \n");
printer();

##########################################
# END OF FILE
##########################################



##### FILE: evalConfigExample.cfg #####


#evalConfigFileExample.cfg
$VENDOR = "Sun";
$HARDWARE = "Sparc";
$OS = "Solaris";
$VERSION = "2.5";
$HOSTNAME = `/bin/hostname`;
$PSCMD = "/usr/bin/ps -ef";
hello_world();

sub printer {
print "In required file\n";
}

##########################################
# END OF FILE
##########################################



The output should look like this:


> evalConfigFileExample.pl -file evalConfigFileExample.cfg
In Perl prog
Subroutine printer redefined at evalConfigFileExample.cfg line 9.
Calling hello_world from eval'd config file!
VENDOR = Sun
VENDOR = Sun
In required file

Sunday, February 1, 2009

Sunday, October 14, 2007

Vimperator -- vimified browsing (at last)

I have found the coolest productivity tool since vim. Vimperator! This allows you to do modal browsing much in the same way that vim does. The greatest thing is that it allows you to write maps (keybindings) that can dramatically improve your productivity on the web. What is so great about modal editing and browsing? You don't have to use that pesky mouse as much anymore. Your fingers stay near home row more often and allow you to control almost everything from they keyboard.

Here is a link from linux.com that has a somewhat decent discussion about it. I am sure there will be many more articles written bout this great tool. Here is the offical wiki.


It is only at version 0.52 as of this writing so I am sure there are improvements to come but it already has vastly sped up my surfing. One vim like feature I would like to see is the visual mode for selecting things. Your mappings and customizations (like vimrc file) are stored in a file named vimperator. Here is what my vimperatorrc file looks like so far:


set activate=quickmark,paste
set nobeep
set complete=sbfh
set defsearch=google
set guioptions=
set maxhints=1000
set preload
set previewheight=20
set showmode
set showstatuslinks
set showtabline=2
set titlestring=Vimperator Dev
set verbose=9
set wildmode=list:full

" start MozRepl
js < :restart

" select next/previous tab
map gt
map gT
map ,src :source ~/.vimperatorrc

" move current tab left/right
map :tabmove! +1
map :tabmove! -1

" move up and down one page
map
map

" Tab maps
map :tabopen
map :tabnext
map :tabprevious

" backward and forward
map gk :back
map gj :forward

map :quit

echo .vimperatorrc sourced

" vim: ft=vimperator sw=2 sts=2

Thursday, July 13, 2006

New Job

I gave my resignation to Sigmatel on Monday. I will be doing the same kind of work (pre-silicon verification) but as a contractor/consultant at Analog Devices here in Austin. They are a pretty good company and they are starting to use some of the newer verification methodologies so I will be helping them bring this up. Should be very exciting. The world of verification is getting very exciting!

Read more at blog.360.yahoo.com/blog...

Friday, June 23, 2006

CNN.com - Study: Earth 'likely' hottest in 2,000 years - Jun 22, 2006

First to add a comment to this news. I just wanted to test to see how adding a new comment to a page would look. Hopefully this will motivate people to do something about global warming.

Read more at www.cnn.com/2006/TECH/s...

Simpy and GoogleAdSense

Simpy adds GoogleAdSense to users pages. This is simpy amazing! There are such incredible synergies happening here with all the Web2.0 stuff. You can now make money off the links that you create. You will not become a millionare from this but it does encourage people to make links and tags more relevant. Keep watching this space for more Web2.0 magic!

Read more at www.simpy.com/3p

Simpy - tagging, social bookmarking and personal search engine

I find this social bookmarking tool to really be a nice experience. It also can import my delicious bookmarks.

Read more at www.simpy.com/