Tag Archives: tutorial

Where Do I find My WiFi MAC Address on My BlackBerry? CodeUnit 05 AUG 2011

To get your BlackBerry MAC address off most of the recent BlackBerry models is pretty simple.

Navigate to the home screen (the one with all the icons on it) and select the Options launcher. Click on that and then scroll down and select the Status option.

The resulting screen will show your MAC address, amongst the other useful bits of information you might not have known regarding your current device!

Nifty.

Simple Zend Tutorial for People Starting Out… with Zend CodeUnit 14 MAR 2011

This post serves more as a bookmark for me than anything else, now that I have been tasked with learning the icky world of Zend and its MVC pattern from the powers above here at work. Learning Zend is not for the faint hearted, that is for sure, and just finding your feet takes a fair bit of reading.

One of the best introductory and explanatory tutorials introducing new users to Zend that I have come across yet, is written by one Nicholas Chase, a consultant at Backstop Media who writes for the IBM developerWorks website.

Originally written way back in 2006 and consequently updated in January 2011, this excellent nine part tutorial covers just about everything someone starting out needs to know, including database work, feed and inputFilter usage, HTTPClient and PDF, e-mail sending and searching, connecting to outside services like Flickr and even adding AJAX to your application.

The tutorial segments are all well written, well laid out, with detailed explanations seemingly always forthcoming.

And hey, after going through everything you’ll even have your very own RSS reader to show off! ;)

You can kick off the tutorial by clicking here.

Nifty.

Related Link: http://www.ibm.com/developerworks/opensource/library/os-php-zend1/

Blogroll: How to Export and Import WordPress Blog Links CodeUnit 26 FEB 2011

To export and import a WordPress blogroll, or links if you prefer, is actually pretty easy, seeing as WordPress already comes with everything necessary for this built in.

Your WordPress blog’s links and links categories are accessible by hitting this URL:

http://www.myblog.co.za/wp-links-opml.php

Now that you know this, importing links from one WordPress blog to another becomes trivial. Simply browse down the wp-admin menu on the left until you find the Tools -> Import menu item. Clicking on the Import menu you will be presented with a number of different import choices. Select Blogroll (import links in OPML format).

The screen presented allows you an option of inserting an OPML URL, in other words the URL we used above. After inputting the URL and clicking import, voila, you will see a list of the imported links, ready for you to play around with to your heart’s content.

Nifty.

PHP Script to Trim and Replace Apostrophes for Each Value in Each Column of Each Table in a MySQL Database CodeUnit 31 MAY 2010

Annoyingly, I got saddled with a database for a system which contained a whole lot of “uncleaned data”, in other words data with a lot of trailing and leading, uncessary whitespace characters, as well as a generous helping of apostrophes and quotation marks – the cause of many a headache when working on a web-based application using PHP and MySQL.

Needless to say, inherent relationships and thus joins were failing left, right and center thanks to this badly formed data and as such I needed to quickly whip up a script that would strip all leading and trailing whitespace plus replace any apostrophes or quotation marks with their web code equivalent for each and every value that appeared in every row, column and table in the database.

And this is the little PHP script that did it for me:

//just to help prevent the script from timing out
ini_set('memory_limit', '100M');
ini_set('default_socket_timeout',600);
ini_set('max_input_time',600);
ini_set('max_execution_time',600);

//give us something to look at on the screen
echo "Start Process...";

//create a database connection
$mysql_hostname = 'localhost';
$mysql_user = 'username';
$mysql_password = 'password';
$mysql_database = 'databaseName';
$conn = mysql_connect($mysql_hostname,$mysql_user,$mysql_password);
mysql_select_db($mysql_database, $conn);

//build up the list of tables to process
$sql = "SHOW TABLES";
$tables = array();
echo 'Building audit tables list...';
$tablestemp = $db->query($sql,2);
foreach ($tablestemp as $tabletemp)
{		
  $tables[] = $tabletemp;
}
echo 'Audit table list built.';

//run through each table, build up a column list and then run an update SQL statement against the column
foreach($tables as $table)
{
  set_time_limit(80);
	$sql = "SHOW COLUMNS FROM `$table`";
	$columns = array();
	echo 'Building audit columns list for ' . $table . '...';
	$columnstemp = $db->query($sql,2);
	foreach ($columnstemp as $columntemp)
	{		
			$columns[] = $columntemp;
	}
	echo 'Audit column list for ' . $table . ' built.';
	
	foreach($columns as $column)
	{
		set_time_limit(80);
		//trim and replace in one foul SQL swoop!
    $sql = "UPDATE `$table` SET `" . $column['Field'] . "` = TRIM(REPLACE(REPLACE(REPLACE(`" . $column['Field'] ."`,"'","'"),'"','"'),'~','''))";
    echo "$sql";
    mysql_query($sql);
	}
}
mysql_close($conn);
echo "End Process.";

And there you go, pretty handy little helper script to have in your possession when you are presented a database with some dirty data included inside! :)

How to Install Foxit PDF Reader 1.1 in Ubuntu Karmic Koala CodeUnit 12 MAY 2010

Foxit Reader 1.1 is an incredible little PDF viewer that features some powerful tools while remaining pretty damn quick. It’s free for non-commercial usage and features most of the viewing tools you’ve come to expect from the big daddy of PDF readers, namely Adobe Acrobat. Among these tools included in Foxit is the standard zoom functionality, full document navigation, bookmarks, thumbnails, text selection, snapshot image grabbing as well as the old faithful, full screen document viewing.

The download .deb package weighs in at a handy 3.6 MB and when running, has a claimed memory consumption that remains less than 15 MB. It launches instantly when called and can load a PDF document in under 3 seconds.

And installing it in Ubuntu is an absolute breeze.

First, download the .deb package of Foxit’s official download page at http://www.foxitsoftware.com/pdf/desklinux/download.html. Once it is downloaded to the appropriate folder on your system, install it using the dpkg Debian package manager. To do this run a terminal in administrator mode and call:

sudo dpkg -i FoxitReader_1.1.0_i386.deb

And that’s it really. Foxit will be installed on your system and you’ll see the menu shortcut being added under the Office tab on the Applications main menu. It is also added as a right-click context menu selection for PDF files. Couldn’t be simpler and works like an absolute charm! :)

(Oh, and finally, for the future when you might find something even better, you can uninstall it in the usual way using: dpkg -r FoxitReader)

Related Link: http://www.foxitsoftware.com/pdf/desklinux/index.html

jQuery: Checking or Unchecking All Checkboxes CodeUnit 08 APR 2010

Providing functionality to check all, uncheck all or even to invert the checkboxes currently selected on a page is pretty simple to achieve with either plain old JavaScript or the newer, more flashy jQuery library. Important too if you think just how much more usable your site becomes with these handy shortcuts available to the user.

Now to select all checkboxes on a page and then check them, one simply has to make use of the handy INPUT[type=’checkbox’] jQuery selector call and then follow that up with an attr call in order to change the checked attribute status to true. Finally, you bundle this all up and apply it to the click event of some handy button or span and end up with this:

$('#selectall').click(function(){
	$("INPUT[type='checkbox']").attr('checked', true);
});

Similarly to untick all checkboxes on your page you would go with something like this:

$('#selectnone').click(function(){
	$("INPUT[type='checkbox']").attr('checked', false);
});

The final little piece of magic on display for today is the function to invert the current checkbox tick selection. Basically here we are going to scroll through each checkbox using jQuery’s handy each function and set the checked attribute accordingly based on its currently held value, which in code would look something like this:

$('#selectinvert').click(function(){
	$("INPUT[type='checkbox']").each(function(){
        	if (this.checked == false) {
			this.checked = true;
		} else {
			this.checked = false;
		}
	});
});

Deceptively simple, was it not? :P

How to Check if Your Javascript Function Exists CodeUnit 28 MAR 2010

So I updated a panel generating script to adhere to some campaign rules, meaning that certain graphing functions were no longer being generated by the PHP script. Great, as easy as that I thought to myself as I patted myself on the back and uploaded the updated code, only to recoil in horror when the site stopped working correctly all of a sudden.

Debugging the errors, I discovered that the thing was falling over whenever a previously untouched bit of code was trying to reference my Javascript scripts – some of which were obviously no longer in existence!

So the question I was then left with is how to check for the existence of a function before actually calling that function, the solution to which turns out to be fairly simple.

All you need to do is this:

if(typeof yourFunctionName == 'function') {
yourFunctionName();
} 

where obviously yourFunctionName is the name of the function you wish to test.

Works like a charm and after implementing this on all of my function calls, no more broken site, meaning happy me and thus a well deserved pat on the back.

Nice.

Photoshop: Text Tool Keyboard Shortcuts CodeUnit 10 MAR 2010

In order to speed up your work using Photoshop’s powerful but sometimes quite frustrating text tool, here are a couple of handy keyboard shortcuts you might like to remember:

  • Commit text changes by pressing CTRL+Enter. (Pressing Enter on its own will just start a new line obviously!)
  • With all text selected, you can hide the selection colour with CTRL+H to see an accurate preview. Useful when working with colour in particular!
  • CTRL+Shift+Left or Right arrow keys selects the whole next or previous word.
  • CTRL+Shift+< or > decreases or increases the font-size by 2 points.
  • CTRL+Shift+ALT+< or > decreases or increases the font-size by 10 points.
  • CTRL+ALT+Left or Right arrow keys increase or decrease letter kerning by 100.
  • ALT+Left or Right arrow keys increase or decrease letter kerning by 20.
  • CTRL+ALT+Up or Down arrow keys move the text baseline up or down by 10.
  • ALT+Up or Down arrow keys move the text baseline up or down by 2.
  • CTRL+Shift+L, R or C aligns the paragraph of text left, right or center.

Finally, and although not a keyboard shortcut, double clicking on the T icon in the layers panel will actually select all text in that layer.

Useful.

Inserting Backslashes into a Database Table with PHP CodeUnit 06 MAR 2010

Sometimes you need to store things like file paths into a database table during your PHP script’s execution. However, on going back to the database after running your script, you might come across your path with all of its backslashes () missing!

So just what is going on here?

In most cases you will be using a string construct to send your SQL command, in other words, mysql_query() will be sending along a string SQL statement to be processed by the database. However, recall that backslashes usually need to be escaped in order to display a backslash, and in PHP for example, escaping characters is done by using a backslash – so in other words to display a backslash in a string, you actually need to put down two of the things: \

However, when pushing your escaped string through to the database, remember that mySQL also needs to escape the backslashes it receives via your SQL statement, meaning that in actual fact you need to be double escaping your escaped backslashes!

To make this simpler to understand, you want to use this in your SQL string: \\. So what happens now is that the PHP script escapes the above to \ which is then passed along to mySQL which then further escapes it to , leaving you with a nice shiny backslash in your record as a result.

Got it?

Anyway, naturally PHP makes things a little easier for us by providing the handy mysql_real_escape_string() function which will handle the escaping of all special characters for use in a SQL statement, even taking into account the current character set of the connection specified!

Now you know.

Related Link: http://www.php.net/manual/en/function.mysql-real-escape-string.php