Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for February, 2008

How-To: Debugging Javascript in IE with Microsoft Script Debugger

Debugging javascript in IE is often like walking on a minefield with a blindfold on. You have no idea where you are when bombs go off. Thankfully, Microsoft provides a debugging tool called Microsoft Script Debugger which makes debugging javascript much easier. You can download the tool from here. Once installed you get a full [...]

Comments (1)

SVN: How to Ignore a File

To ignore a file or directory inside a SVN repository use the following command: svn propset svn:ignore <filename> This also works for directories. 

Leave a Comment

URL Encoding a string with javascript

The following javascript function returns a URL encoded string so that it is safe to use in URLs or as a GET request: function URLDecode (encodedString) { var output = encodedString; var binVal, thisString; var myregexp = /(%[^%]{2})/; while ((match = myregexp.exec(output)) != null && match.length > 1 && match[1] != ”) { binVal = [...]

Leave a Comment

How-To: Capture ‘return key’ from a field with Protoype.js

Prototype provides an excellent abstraction mechanism for event handling in javascript. I needed to capture when a user hit the ‘return key’ inside a text box, and then perform a specified action. Using the observe function and the KEY_RETURN constant, you can easily detect when this is done. Simply place the following code in a [...]

Comments (4)

Installing Crypt::Blowfish on Windows from PPD

I have had a requirement to encrypt in Perl and decrypt in Php. As a result, I’ve been looking at ways to get this to work. There are a number of people who have managed to get this working using the Crypt::Blowfish module in perl and mcrypt_cbc function in Php. That’s great unless you are [...]

Comments (1)

How-To: Connect HUAWEI E220/E270/E272/E169G/E160/E180 Modem with Mac OS X 10.5 (Leopard)

digg_url = ‘http://digg.com/apple/How_To_Setup_3G_USB_Modem_for_Mac_OS_X_Leopard’; I’ve been trying to get my USB Broadband Modem to work with Leopard for the past few days. Unfortunately the instructions that come with the modem from 3 (my network provider in australia) are out-of-date and don’t work. So here are the steps to get the modem working: 1. Ignore the instructions [...]

Comments (334)

Help Us Help the Earth Campaign goes live!

I’ve been working on a water calculator for the past few weeks and it has just gone live! Check it out here: http://www.helpushelptheearth.com.au/ This is a partnership between Landcare Australia, Banrock Station Winery and WSP. The water calculator helps Australian’s determine their water usage, potential water savings and determine how much they water they could [...]

Leave a Comment

Stopping firefox auto-completing fields on a form

Firefox has a very handy (or very annoying) feature which pre-populates fields on a form if you have previously entered data on the form and then reload the page. Sometimes you don’t want this to happen! To stop it, do the following: More information is available from mozilla here.

Leave a Comment

SVN: Creating a new project using command line

I always forget the syntax for creating a new project using SVN via the command line. So here it is: svn import <directory> <repository path> -m “Initial checkin” Where the directory should contain the files you want to add to the repository, and the repository path should be something like: svn+ssh://evan@charzard/usr/local/svn/repository/trunk/1.0/<project name>

Leave a Comment

php $_SESSION variable doesn’t stay persistent

Recently I was creating a new website from scratch, which required authentication and the use of PHP’s sessions functionality. I used the session to store information which I needed to be persistent between pages: Page 1 Page 2 However page 2 would never display the user ID value. I couldn’t work out what was causing [...]

Leave a Comment

Typecasting Strings to Numbers in Javascript

If you are using the values on a page (e.g. the values of form elements) directly in mathematical formulas in javascript, you can have issues with ambiguity of types. For instance: var total = 0; total += document.myForm.element.value; // e.g. value = 5 alert(total); The above example can lead to a result of “05″ instead [...]

Comments (1)

AJAX Loading Image

Building an AJAX based web site?  Want to let your users know that something is happening in the background?  The best way to do this is with an AJAX loading image.  I use the site http://www.ajaxload.info/ which allows you to generate spinners as required and is very handy.

Leave a Comment

Converting CSV files to Mysql – Free Online Tool

I often require the ability to convert simple spreadsheets into data in a database. As far as I could tell, there is no easy way to do this without writing your own code or paying $40 for a windows application. So I wrote a free online CSV to SQL converter which converts CSV files to [...]

Leave a Comment

Javascript validation of Email Address, Numeric Values and an Input Mask for Numbers Only

A couple of very simple yet handy routines for validation of form fields: Function to validate an email address (see original post): function ValidateEmail(email){ var emailReg = “^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$”; var regex = new RegExp(emailReg); return regex.test(email); } Function to validate a number: function ValidateNumber(num) { return num.match(/^\d+$/); } Input mask for a field to only accept [...]

Comments (2)

Creating Objects with Javascript

Recently I’ve started overhauling all our old javascript libraries to make them more object-based and easier to maintain. As a result, I’ve needed to get familiar with how to create objects and assign properties and methods. This is surprisingly easy in javascript: Creating an object (Constructor) with properties: function MyObject(param1, param2) { this.myProperty = param1; [...]

Leave a Comment