≡ Menu

Install Perl module in your home directory

To install a Perl module in your home directory is helpful for a couple of reasons. 1) It doesn’t require root permission. 2) It’s installed separately from the site-wide installed modules, hence can coexist with those modules and useful when trying a module that has different version with what’s already installed.


$ perl -MCPAN -e shell PREFIX=~/lib/perl LIB=~/lib/perl
cpan> install
cpan> quit

Assuming that you want it installed on the directory lib/perl on your home directory. Also, don’t forget to set PERL5LIB:

export PERL5LIB=~/lib/perl:$PERL5LIB

{ 2 comments }

Rollback a file in a subversion repository

To rollback a file in the working directory to a previous version in the repository:
svn -r <revnum> update <filename>

Where is the revision number you want to rollback into; is the file you want to rollback.

{ 0 comments }

Finding python’s site-packages directory

Python modules or packages that you install yourself are installed in a directory called site-packages. The location of this directory is subdivided into the specific python version you are running and is also different for each platform for obvious reasons. To determine your system’s site-packages directory, run this from the command line:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

{ 0 comments }

Enabling AirDrop on older systems

You can enable AirDrop for many older Lion systems at the Terminal command line. Enter:

defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1

After setting the defaults, you’ll need to restart Finder:

killall Finder
{ 0 comments }

Ejecting a stuck CD or DVD on a Mac

If you have a stuck CD or DVD on your Mac, and the desktop icon for the media has disappeared from the desktop so that you can no longer drag it to the trash, you can manually eject the media without rebooting the machine by executing the following command from the Terminal:

drutil tray eject
{ 0 comments }

I just upgraded my MacBook Pro’s hard drive to one with a bigger capacity. After restoring the contents from the old drive to the new one using an image created by SuperDuper!, I keep on getting this error every time I launch the Terminal application:

dyld: shared cached was built against a different libSystem.dylib, ignoring cache

After googling around, I found this discussion thread from Apple’s Support Forum on how to fix the error:
sudo update_dyld_shared_cache -force
{ 0 comments }

Wish you were here!

… but this is probably the next best thing! 🙂 Took some panorama shots of the front and back yards today. It’s been a while since I’ve done my last panoramas, so it’s almost like learning from the beginning once again. Anyway, here’s the result and pardon some of the photo misalignments.


Frontyard


Backyard

Note:This requires the Flash Player to view the panoramas. For more information about Flash Player, please visit http://www.macromedia.com/software/flash/about/.If you cannot view the panorama, please download and install the latest version of Flash 10 player.

{ 0 comments }

Base64 Encoding and Decoding

At one time, I needed to encode and decode strings in Base64 but I was on a very old Perl version that does not include the MIME::Base64 core module, nor am I able to install the said module. So, here’s the source for encoding and decoding Base64 ripped from the MIME::Base64 module:

sub EncodeBase64
{
    my $s = shift ;
    my $r = '';
    while( $s =~ /(.{1,45})/gs ){
        chop( $r .= substr(pack("u",$1),1) );
    }
    my $pad=(3-length($s)%3)%3;
    $r =~ tr|` -_|AA-Za-z0-9+/|; 
    $r=~s/.{$pad}$/"="x$pad/e if $pad; 
    $r=~s/(.{1,72})/$1n/g; 
    $r; 
} 
 
sub DecodeBase64 
{ 
    my $d = shift; 
    $d =~ tr!A-Za-z0-9+/!!cd; 
    $d =~ s/=+$//; 
    $d =~ tr!A-Za-z0-9+/! -_!; 
    my $r = ''; 
    while( $d =~ /(.{1,60})/gs ){ 
        my $len = chr(32 + length($1)*3/4); 
        $r .= unpack("u", $len . $1 ); 
    } 
    $r; 
}
{ 0 comments }

Read string from stdin using fgets

#include <stdio.h>
#include <string.h>

int main(void)
{
  char str[80];
  int i;

  printf("Enter a string: ");
  fgets(str, 10, stdin);

  /* remove newline, if present */
  i = strlen(str)-1;
  if( str[ i ] == 'n')
      str[i] = '';

  printf("This is your string: %s", str);

  return 0;
}
{ 0 comments }

How to determine DST time changes

Here’s how to determine the dates when the Daylight Savings Time changes for a given year (I keep forgetting how to do this.):

zdump -v /etc/localtime|grep 2008 /etc/localtime Sun Mar 9 06:59:59 2008 UTC = Sun Mar 9 01:59:59 2008 EST isdst=0 gmtoff=-18000 /etc/localtime Sun Mar 9 07:00:00 2008 UTC = Sun Mar 9 03:00:00 2008 EDT isdst=1 gmtoff=-14400 /etc/localtime Sun Nov 2 05:59:59 2008 UTC = Sun Nov 2 01:59:59 2008 EDT isdst=1 gmtoff=-14400 /etc/localtime Sun Nov 2 06:00:00 2008 UTC = Sun Nov 2 01:00:00 2008 EST isdst=0 gmtoff=-18000

Obviously, change 2008 to whatever year you want.

{ 0 comments }