Viewing Category : programming

Post thumbnail of Pointers, the way I learned them in school!
5 October 2009
Continue reading Pointers, the way I learned them in school!

Pointers, the way I learned them in school!

In the following code, we are creating a new variable called my_character and storing ‘a’ there.” This will be one byte in size. Whenever you create a string of text in the C language with quotes, you are actually storing that string somewhere in memory. That means that a string of text, just like all variables, has some address in memory where it lives. Now a pointer can only contain a memory address, so “Hello World!” must be a memory address.

Post thumbnail of Perl Spreadsheet::ParseExcel to convert Excel Spreadsheets
14 September 2009
Continue reading Perl Spreadsheet::ParseExcel to convert Excel Spreadsheets

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) {

Post thumbnail of Block changes to a tag in Subversion with pre-commit hooks
3 September 2009
Continue reading Block changes to a tag in Subversion with pre-commit hooks

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!

Post thumbnail of Running bash shell scripts in debug mode to trace execution
26 August 2009
Continue reading Running bash shell scripts in debug mode to trace execution

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.

Post thumbnail of Simple php function to check if post variables are set without triggering warnings
13 August 2009
Continue reading Simple php function to check if post variables are set without triggering warnings

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

Post thumbnail of Send gzipped PHP output to users browser’s to save bandwidth
10 August 2009
Continue reading Send gzipped PHP output to users browser’s to save bandwidth

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.

Post thumbnail of Toggling debug output within a PHP class
6 August 2009
Continue reading Toggling debug output within a PHP class

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.

Post thumbnail of How to pass multiple post array variables in PHP
6 August 2009
Continue reading How to pass multiple post array variables in PHP

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.

Post thumbnail of Using PHP’s explode to split a full path into directory and file name
3 August 2009
Continue reading Using PHP’s explode to split a full path into directory and file name

Using PHP’s explode to split a full path into directory and file name

This is the easiest way I could think of to figure out the directory given a full path in PHP. I reverse the whole string, then look for the first slash and break off that part. Then reverse it back. You could drop each part into an array, so the first element could be the path to the present working directory, and the second element would be the directory itself. Or you could write a second function called getPWD and return the path instead of the directory.

Post thumbnail of Secure Delete shell script - Simple but complete
9 July 2009
Continue reading Secure Delete shell script - Simple but complete

Secure Delete shell script - Simple but complete

So I just wrote this in 2 minutes so I could kill some things in /etc and /home and be done with it. Short and simple, don’t you think?

 Page 5 of 7  « First  ... « 3  4  5  6  7 »
Powered by Wordpress   |   Lunated designed by ZenVerse