Archive for Notes

Sep
24

Debugging CGI Using ptkdb

Posted by: | Comments (0)

ptkdb is a graphical Perl debugger. To use it when debugging command line scripts is very straight forward. Just type in the command line:


perl -d:ptkdb script.pl

and you’re good to go.

However, using it to debug CGIs needs some tweaking to your CGI source. Replace the usual

#!/usr/bin/perl

line at the top of the CGI script with this one:


#!/usr/bin/perl -d:ptkdb
BEGIN {$ENV{DISPLAY} = "$ENV{REMOTE_ADDR}:0.0";}

Go to your browser and invoke your CGI and a debugger window should pop up.

Categories : Notes, Perl
Comments (0)
Sep
10

Change Behavior of iTunes Arrows

Posted by: | Comments (0)

Starting with iTunes 4.5, Apple implemented those little grey arrows next to the song title, artist, and album, which will take you to the corresponding match in the iTunes Music Store. To change the behavior of these arrows so that instead of going to the store, it will take you to your library instead, you can do either one of two ways:

  1. Hit option key when you click the arrow.
  2. Change it permamnently by executing this from the terminal:
    defaults write com.apple.iTunes invertStoreLinks -bool YES

    Make sure iTunes is not running when you execute this command.

Categories : Mac OS X, Notes
Comments (0)
Sep
08

Enable Safari Debug Menu

Posted by: | Comments (0)

To enable Safari Debug menu from the command line:

% defaults write \
com.apple.Safari IncludeDebugMenu 1

Make sure Safari is not running when you run this command.

Categories : Mac OS X, Notes
Comments (0)
Sep
07

Determine Disk Usage

Posted by: | Comments (0)

This command will show the number of KBs used for all non-hidden files and folders in the current directory:

du -sk * | sort -rn
Categories : Linux, Notes
Comments (0)
Aug
11

Find By Contents

Posted by: | Comments (0)

This will recursively search all the files, with a certain filename pattern (in this case *.h) in a certain directory, that contains a certain text pattern in its contents (in this case ‘DeviceDriver’).

find . -name '*.h' -print0 \
| xargs -0 grep -n -e DeviceDriver
Categories : Linux, Notes
Comments (0)
Aug
02

CGI To Display Module Documentation

Posted by: | Comments (0)

Here’s a CGI to display a module’s POD. The module has to be in the $INC. This is great for providing documentation to internal modules.


# save this as showdoc.cgi
#!/usr/local/bin/perl
use strict;

use Pod::Html;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

# Send out the header
print "Content-type: text/html", "\n\n";

my $q = new CGI;

my $module = $q->param('module');
require $module;

$| = 1;

chdir ("/tmp");

my $fullpath = $INC{$module}
    or die "$module not found";

pod2html("--infile=$fullpath", "--flush");

# Clean up the junk left by pod2html
END {
        unlink("pod2html-dircache");
        unlink("pod2html-itemcache");
}

To use this, say you want to view POD for Data::Dumper:



http://localhost/cgi-bin/showdoc.cgi?module=Data/Dumper.pm

Categories : Notes, Perl
Comments (0)
Jul
24

crontab Format

Posted by: | Comments (0)

[I could never remember this so I'm putting it here.]
These are the fields of a crontab file:


a b c d e /full/path/to/script

where

a = minute (0-59),
b = hour (0-23),
c = day of the month (1-31),
d = month of the year (1-12),
e = day of the week (0-6 with 0=Sunday).

* = every min, hour, day, etc.
*/10 = every 10 min, hour, day, etc.
Categories : Linux, Notes
Comments (0)
Jul
21

Read A Text File

Posted by: | Comments (0)

This will open a text file and read it line by line. As it is, it will just print each line to the screen, so very much like the unix ‘cat’ command, but could very well do anything on the line just read by replacing the cout statement.


#include <fstream>
#include <iostream>
#include <string>

void main() {
    string s;
    ifstream infile;

    infile.open("aaa.txt");

    while(infile >> s) {
        cout << s << endl;
    }
}
Categories : Cpp, Notes
Comments (0)
Jul
12

Create Skeleton Module

Posted by: | Comments (0)

Use this to create a skeleton module:


h2xs -AXn Your::Module
Categories : Notes, Perl
Comments (0)
Jul
08

stty Settings

Posted by: | Comments (0)

This is my stty setting (all in one line):


stty intr '^c' erase '^?' kill '^u' echoe \
echoctl echoke -ixany
Categories : Linux, Notes
Comments (0)