05/11/2009
Craig Lotter
No Comments

Linux ls Colour-coding in PuTTY

PuTTY is a damn useful app for when it comes to gaining remote access into a machine via SSH or Telnet, and has more than proven its worth to serious geeks over the years since it was first released.

But here’s a question that you’ll be asking if you are new to the whole command line SSH into Linux access thing:

“Just what does all the colour-coding (when it comes to folder listings) displayed in PuTTY mean?”

Well, basically the colour-coding is to expediate file type recognition. For example, the default colour set is as follows (thanks Google!):

  • * Normal file: White (or the default colour used by the command line window)
  • * Directory: Blue
  • * Symbolic link: Cyan
  • * Pipe: Yellow
  • * Socket: Magenta
  • * Block device driver: Bold yellow foreground, with black background
  • * Character device driver: Bold yellow foreground, with black background
  • * Orphaned syminks: Blinking Bold white, with red background
  • * Missing links: Blinking Bold white, with red background
  • * Archives or compressed files: Red (e.g. .tar, .gz, .zip, .rpm)
  • * Image files: Magenta (.jpg, gif, bmp, png, tif)

To manipulate or view just what colours your system is spitting out you, simply pay a visit to /etc/profile.d/colors.sh and /etc/profile.d/colors.csh

There, hope that helps! :)

(Tip: If you wish to disable the list colouring, simply remove the alias that attaches ls –color=tty to ls – run `alias` to see what I’m referring to.)

04/11/2009
Craig Lotter
4 Comments

Little PHP Tip: Array Iteration that Produces both Key and Value

PHP tutorial logoA PHP quick tip on something I keep on forgetting. Now while the foreach functionality is great in iterating through an array and returning the array’s values, sometimes one wishes to also capture the key against which a particular value is stored and for this one should use the overloaded form of the foreach function (usually foreach ($arr as $value) ), namely:

foreach ($arr as $key => $value)

This returns two variables in the form of $key which is the actual key name used for the array item and $value which is the actual value stored for that particular array item.

Nifty.

If you want to test it out for yourself, simply plug an array of your own making into this little blob of code: 

foreach ($arr as $key => $value) {
    echo "Key: $key; Value: $value<br />\n";
}

04/11/2009
Craig Lotter
No Comments

jQuery: Iterate Through a Form’s Elements

jQuery-logoTo iterate though a web form’s contents using jQuery is as easy as 123. First, make use of the $(’:input’) selector and force it to grab the contents of a particular form by extending the selector with $(’:input’, ‘#yourFormID’) where yourFormID is obviously the ID of the form you are interested in iterating through.

The next step is to make use of the each function to iterate through the selector’s returned array and using the this keyword, you should now be good to go.

The example below simply iterates through a form’s contents and spits out an alert detailing the input’s name and current value. (Note that for radio buttons you will need to take the inputs tagName value into consideration in order to figure out which radio button is currently selected.) 

$(document).ready(function() {
    $('#yourButtonID').click(function () {
        $(':input', '#yourFormID').each(function() {
            alert(this.name + ': ' + this.value);
        });
    });
});

04/11/2009
Craig Lotter
1 Comment

jQuery: Scroll to the Top of a Page

jQuery-logoMy current project requires me to split up a particularly long survey into chunks, allowing a survey taker to only submit those chunks that he/she feels like submitting and ignoring the rest.

Now to be all spiffy I simply fade out the affected chunk once the user clicks submit and then throw back a growl notification at him thanking him for his submission. However, it was at this point that I hit a small snag in that the growl works visually best if you scroll all the way back up to the top of the page and thus I set about looking on the web for a decent scrollTo jQuery plugin as quite simply I don’t have the time to whip up my own.

All of which brought to me the discovery of Ariel Flesler’s nifty jQuery.ScrollTo plugin which you can read more about (and grab) here: http://flesler.blogspot.com/2007/10/jqueryscrollto.html

Add the link to the plugin in your page and hey presto, when you want to scroll the screen all the way up, simply do this:

$.scrollTo(0);

 Nifty.

03/11/2009
Craig Lotter
No Comments

How to install XBMC in Karmic Koala

Ubuntu LogoXBMC hasn’t yet shipped out a release to work natively with the newly released Ubuntu 9.10 Karmic Koala release, so you’ll need to install if via XBMC’s SVN.

Realistically, all that this means is that you still need to follow the step by step instructions given on XBMX’s how-to wiki exactly as before, but this time around you do need to replace the software sources additional line deb http://ppa.launchpad.net/team-xbmc/ppa/ubuntu/ jaunty main with http://ppa.launchpad.net/team-xbmc-svn/ppa/ubuntu karmic main.

In other words, the install steps should now look like this:

Adding the XBMC Repo

Adding the XBMC Repo tells your system where to look for xbmc for installation and future updates

  • From the Desktop, click System -> Administration -> Software Sources.
  • Click the “Third Party Sofware” tab.
  • Click “Add”. For the Apt line type the following:
deb http://ppa.launchpad.net/team-xbmc-svn/ppa/ubuntu karmic main
  • Click “Close”. If you see a GPG Error upon closing the window, not to worry. That will be handled in the next step.

Adding PPA Keys

These packages are signed with a unique key for added security. Synaptic needs to know this key in order to verify the packages’ authenticity.

  • Click here to view the PGP key
  • Select the text from the beginning of the keyblock to the end (including those lines)
  • Copy that text to the clipboard (Edit -> Copy)
  • Open your text editor from Applications -> Text Editor.
  • Paste the key contents (Edit -> Paste)
  • Save the document in your home folder as xbmc-ppa.key
  • Reopen Software Sources, this time choosing the “Authentication” tab.
  • Click “Import Key File” and choose the newly created xbmc-ppa.key and press OK.

Installing XBMC

Now that the repo and key have been added, install XBMC like any other program.

  • Click System -> Administration -> Synaptic Package Manager
  • Click “Reload”
  • Search for “xbmc”
  • Mark xbmc and xbmc-standalone for installation and mark additional changes when prompted.
  • Click “Apply” and agree to the changes after reading them.

XBMC is now installed and ready for use.

Autostart XBMC (optional)

By following these instructions, your system will boot directly into XBMC rather than your desktop from now on. It is advised that you delay this step until XBMC is setup as you’d like it.

  • From the desktop click System -> Administration -> Login Window
  • From the “Security” tab choose “Enable Automatic Login” and select your username.
  • Click “OK” to exit.
  • Logout of your system.
  • From the Login screen choose “Select Session”
  • Choose “XBMC” and click “Change Session”

(Sorry for the copy/paste hack from the original steps, but it does the trick doesn’t it?)

02/11/2009
Craig Lotter
No Comments

Karmic Koala Up and Running

Ubuntu LogoAwesome. I’ve finally taken the step to ditch Windows XP and my custom BigVid media player from my little PC sitting next to the TV in the lounge and have instead embraced the newly released Ubuntu 9.10 Karmic Koala operating system which I must say was quite a breeze to install. The new human theme is pretty (but ghostly) and I was impressed at how seamlessly Ubuntu picked up both my wireless network adaptor and wireless keyboard and mouse system, without any intervention required from my side at all!

I haven’t yet spent much time exploring this new release, but I see we now have a more organised and updated Software Center from which to add/remove new apps, something I quickly delved into in order to grab XBMC, one of the premier open source media center platforms currently out there.

Tombuntu ran an excellent article on converting your machine to a media center using XBMC a while ago, and although the official XBMC site promises nothing when it comes to this latest Ubuntu release, you can pretty much guess how I plan on entertaining myself tonight! :)

29/10/2009
Craig Lotter
3 Comments

Little Vista Tip: Quick Launch Quick Launch Items

So we all know about the cool little Quick Launch panel sitting on the left hand side of the Taskbar (just next to the Windows Start button) at the bottom of the screen, which usually holds a variety of shortcuts to ‘often used applications’ (like Internet Explorer for example) and applications for which you simply weren’t bothered to uncheck the ‘Add Quick Launch’ option when you installed them.

But did you know that you can quick launch your Quick Launch items?

No?

Well it’s quite simple really. Look at the sequence of the items on your Quick Launch bar. See the ‘Show Desktop’ shortcut sitting at position 1? Well hold down the Windows key and press 1.

Back again? This obviously applies to all options sitting in your Quick Launch bar, so using the example image below, Windows key + 3 would result in Windows Media Player launching.

Windows Quick Launch Menu

Nifty!

22/10/2009
Craig Lotter
No Comments

Little Vista Tip: Quick Zoom in Explorer

Magnifying GlassA nice little trick that Vista allows for is the simple zooming in and out of the various explorer folder views by simply holding down Ctrl and using the mouse scroll-wheel to resize the icons either up or down. Of course, you could do exactly the same by simply clicking on the views menu option and changing it accordingly, but this way is far quicker and far more satisfying to those people who hate having to change mouse focus when they’re working on something in the first place.

And as an added bonus, this Ctrl+Scroll-wheel technique even works on your desktop (your beautiful desktop icons resized all the way up to 256×256 photographic-quality renditions! :P) as well as Internet Explorer 8.

Just a note though, don’t test it out on your desktop unless you like having your neatly arranged desktop icons left completely all over the place. I learnt this the hard way unfortunately.

19/10/2009
Craig Lotter
No Comments

PHP: Obfuscate Your Query Strings

PHPIt is sometimes a good idea to obfuscate your query strings between web scripts, if only to prevent user URL tampering that could effect the outcome of your processing scripts, and if you don’t need particularly strong security (i.e. non reversible coded strings) then the following method could prove invaluable to you:

Firstly, replace your existing query string with a new singular string (I’ve named it ‘id’ for this demo’s sake). For easier processing, I suggest you fuse your query string into a single string, using an easily recognisable delimiter (like ‘||||’ in my example). Then, run what would have been your query string first through a base64_encode and then follow that up with a str_rot13 calculation to provide your ‘new’ obfuscated query string.

For example:
$url = ‘/submitting_page.php?id = ‘ . str_rot13(base64_encode(localhost/index.php||||aerdg6||||fastcars));

Then, on the processing side of the receiving page, you first run a str_rot13 calculation on the encoded query string variable, followed up with a base64_decode to get it back into it’s original state.

From this point on it is a simple matter of exploding the resulting decoded string using the delimiter you previously selected, resulting in a nice usable array of values to work with.

For example:
$querystring = base64_decode(str_rot13($_GET['id']));
$querystrings = explode(’||||’, $querystring);
$url = $querystrings[0];
$hash = $querystrings[1];
$table = $querystrings[2];

Nifty.

09/10/2009
Craig Lotter
No Comments

MySQL: Average Time Difference for Datetime Records

If your table contains two datetime columns for which you wish to calculate, and display in readable format, the average time difference for the entire table, the simplest (and probably fastest) way to achieve this is by doing the calculation in your SQL statement directly.

To achieve this you first work out the time difference between the two fields using the TIMESTAMPDIFF functionality (specifying seconds as the unit to work in). Then you run AVG across that result set which will group and return the average time difference for the table as whole. Finally, use SEC_TO_TIME to convert the average result (which is now in seconds) into a user friendly display string.

Putting this all together, you SQL statement should now look like this:

“SELECT SEC_TO_TIME ( AVG ( TIMESTAMPDIFF ( SECOND, `datetime1`,`datetime2`))) FROM tabletoprocess

… the output of which will be in the format 00:00:00

Nifty.

←Older