Monday, 1 November 2010

Problems with your local perl install?

Try the following uber 1337 commands (based on this):

mv ~/perl5 ~/notperl5
wget -O - http://cpanmin.us | perl - -L ~/perl5 --self-upgrade local::lib


ZOMG!



OK, now add your ~/perl5 dir into git...
cd ~/perl5/ ; git init ; git add . ; git commit -m 'initial import'

This will help you keep things in order over time.


Example:
cpanm Bio::DB::Sam


You can then use git to see exactly what you did, and commit if it worked OK. i.e.
git add . ; git commit -m 'BioPerl and Bio::DB::Sam installed'

(Once you have confirmed that it's working.)


Once your local::lib is in git, you can do lots of stuff like if something is breaking, just edit it in there to insert debugging or whatever and then just reset --hard to get rid of it after you figure out what is going on, etc.



Thanks to rbuels on irc://irc.freenode.net/#bioperl for helping with this!
(All the above is his doing).

Tuesday, 8 June 2010

Testing MediaWiki (MW) & Semantic MediaWiki (SMW)

Long time coming...


http://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker#Testing



First, set up the MW testing environment:

Grab the latest MW (1.15 branch):

Somewhere in the web-directory:
svn co http://svn.wikimedia.org/svnroot/mediawiki/branches/REL1_15/phase3/ MW1_15

Configured using all the default settings.


Next, grab some extensions:
http://svn.wikimedia.org/svnroot/mediawiki/branches/REL1_15/extensions/


Write some tests using http://seleniumhq.org/

1) Install the Selenium-IDE (Firefox plugin)

Wednesday, 6 January 2010

Configure the ssh *client* to stay alive

http://embraceubuntu.com/2006/02/03/keeping-ssh-sessions-alive/

Friday, 27 November 2009

Resurrect screen?

You were just using screen, but now it says

dmb@dallas0 [~]# screen -r
There is no screen to be resumed.

Try this:
ps x | grep -i screen

Note the PID... and:
kill -CHLD screenpid



http://www4.informatik.uni-erlangen.de/~jnweiger/screen-faq.html

Tuesday, 27 October 2009

"What links here" for symlinks?

Ever been frustrated by knowing that you have created a link to your `pwd` 'somewhere' on the file system, but you are unable to remember where?

Ever wished you could just hit "What links here" to discover the location of the symlink from the target?

Tough.

There is no good solution.


Here are some ugly hacks:

#!/bin/bash
for file in `find / -type l 2> /dev/null`; do
ls $file -l 2> /dev/null | grep "target" 2> /dev/null
done


or

find ./ -type l -exec ls -l '{}' \; | awk '{print $11}' | grep "target"


These 'hacks' will thrash your disk, but what are you going to do? Unless we can make a file system based on a wiki ... (imagine a history page for all your config files?) or a database ... (imagine querying for all the files greater than 1 Gb older than 1 year?) we are stuck with these... Unless you know better?

Thursday, 22 October 2009

Perl wrapper for R

This Perl wrapper for R fills in some missing functionality (line number and context on error) and automatically 'dumps' the output of the script.

I can be improved in many ways, but here it is, as is....


   1. #! /usr/bin/perl -w
   2.
   3. unless (@ARGV){
   4.   warn "\n";
   5.   warn "Runs an R script with STDERR dumped to STDOUT\n\n";
   6.   warn "Usage: $0 \n\n";
   7.   exit(1);
   8. }
   9.  
  10. my $rFile = shift @ARGV;
  11.  
  12. die "Stubbornly refusing to run R on a file that doesn't end .R!\n"
  13.   unless $rFile =~ /\.R$/;
  14.  
  15. my $oFile = `basename $rFile .R`; chomp( $oFile );
  16.  
  17. my $args = join(" ", @ARGV);
  18.  
  19. if ($args){
  20.   $args = "--args $args";
  21. }
  22.  
  23. warn "Using: R $args < $rFile > $oFile.dump\n";
  24.  
  25.  
  26.  
  27. open ( OH, ">$oFile.dump" )
  28.   or die "cant : $! \n";
  29.  
  30. my $pid =
  31.   open( PH, "R $rFile -q --vanilla $args < $rFile 2>&1 |" )
  32.     or die "cant : $? : $! \n";
  33.  
  34. my $lineNumber;
  35.  
  36. while(){
  37.   $lineNumber++ if /^(\>|\+)/o;
  38.   print OH;
  39. }
  40.  
  41. close( OH );
  42. close( PH );
  43.  
  44. if ($?) {
  45.   #warn "killed by $?\n";
  46.   warn "FAILED AT LINE $lineNumber\n";
  47.   system("tail -n 5 $oFile.dump");
  48.   exit(1);
  49. }
  50.  
  51. warn "OK (NO ERRORS DETECTED)\n";

Friday, 14 August 2009

vpnc timeout problem solved with Perl

Or ... EXPECT PAIN!!!

I've seen lots of people complaining about a time out problem with vpnc. This happens to me even if I'm ping-ing like crazy or not, so its nothing to do with activity on the connection (I think).

The problem with automatically re-connecting was the need to interactively type a password at prompt. Note that this was not my "Xauth password". For some reason my organisation requires an extra password (there are many ways a VPN can be configured).

If you just need to type one username and password, its probable that you can set up your config file to contain:

Xauth username meUserName
Xauth password meSekretPassword


With the above you could just automatically restart vpnc every time it drops out (i.e. using bash). I have this extra password to deal with though, so its a bit harder. Here is the solution achieved using Perl, Expect [1], and a lot of help from the friendly mst in irc://irc.freenode.net/#Perl

  1. use Expect;
  2. while(1){
  3. $e=Expect->new("vpnc", ("--no-detach", "/home/me/my.VPN.conf"));
  4. $e->debug(1);
  5. $e->log_file("log");
  6. if($e->expect(15, "-re", "Password for VPN")){
  7. $e->send("sekret pwd\n");
  8. $e->interact
  9. }
  10. else{
  11. die "fail!!!\n"
  12. }
  13. print "woop\n";
  14. }


[1] http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod


Take care,
Dan.