programming

Perl Spreadsheet::ParseExcel to convert Excel Spreadsheets

#!/usr/bin/perl -w
# For each tab (worksheet) in a file (workbook),
# spit out columns separated by “,”,
# and rows separated by c/r.

use Spreadsheet::ParseExcel;
use strict;

my $filename = shift || “Book1.xls”;
my $e = new Spreadsheet::ParseExcel;
my $eBook = $e->Parse($filename);
my $sheets = $eBook->{SheetCount};
my ($eSheet, $sheetName);

foreach my $sheet (0 .. $sheets – 1) {
$eSheet = $eBook->{Worksheet}[$sheet];
$sheetName = $eSheet->{Name};
print “#Worksheet $sheet: $sheetName\n”;
next unless (exists ($eSheet->{MaxRow}) and (exists ($eSheet->{MaxCol})));
foreach my $row ($eSheet->{MinRow} .. $eSheet->{MaxRow}) {
foreach my $column ($eSheet->{MinCol} .. $eSheet->{MaxCol}) {
if (defined $eSheet->{Cells}[$row][$column])
{
print $eSheet->{Cells}[$row][$column]->Value . “,”;
} else {
print “,”;
}
}
Read More »

Block changes to a tag in Subversion with pre-commit hooks

Start by going to the hooks directory in your repository and copying pre-commit.tmpl as pre-commit. Then add the line to disallow changes to tags and run it. All is well, the change didn’t get committed, right? What just happened was the commit failed because the pre-commit wasn’t marked executable!

Running bash shell scripts in debug mode to trace execution

This is so handy, I can’t believe i’ve never used or even heard of this until today! You can easily run your bash shell scripts in debug mode to watch what they’re doing behind the scenes in real time. You get to see the levels of nesting when you’re inside loops and variables get replaced with their actual contents at the time of execution.
This might come in handy if you have multiple levels of nesting in ‘for’ and ‘while’ loops or a few if/then/else statements and you want to see just what is getting passed in the comparisons.

Simple php function to check if post variables are set without triggering warnings

If you check the contents of a post variable that never got passed, you get warnings. If you like keeping your verbosity set that high and want to avoid this warning, or you just want to avoid checking against a non-existent variable, try this

Send gzipped PHP output to users browser’s to save bandwidth

The oneliner ob_gzhandler only works for Apache and you have to have the mod_gzip module loaded. This method is crap. So to send gzipped PHP output to users browser’s to save bandwidth, try this. It also helps for slow Internet connections and large pages too.

Toggling debug output within a PHP class

I don’t care what anyone says, I like lots of debug output available in my programs. It helps me crank out code faster with less errors. You can keep a private member called debug and just flip it on and off when you want to see the output. It’s a lot cleaner than interjecting prints and echos all over the place.

How to pass multiple post array variables in PHP

Now when go.php loads, you can check to see if there’s anything in the post_arr, and if there is, cycle through the array and store all the elements. I couldn’t find a working example of this just by googling. It seemed like tons of people would ask for this, but any responses on forums would be, “well what are you really trying to do”. So here it is.