Archive for the ‘Open Source’ Category

The Ultimate Device

Tuesday, June 10th, 2008

I see that Apple are deigning to release the new iPhone in New Zealand soon. I’ve had an iMate Jam for almost three years now and only use it as a phone and an MP3 player (since moving to Linux I’ve been unable to sync my calendar and emails). I’m not going to be rushing out to get the new iPhone either. Why? Because I already know what I want in a device and I just know I’m going to be deeply dissatisfied with anything for the next ten or twenty years.

Here’s my specs for the ultimate device:

  • Small enough to be worn on the wrist (perhaps twice the size of a watch but more fitted)
  • An in-built or pull-out screen that suffices and has a minimum 800×600 resolution
  • A universal docking port.
  • Open source software AND hardware
  • Phone
  • Good quality camera (~4 megapixels + optical zoom)
  • Audio and Video playback
  • Desktop-equivalent processor + 4gb ram (to replace current PC but can be hotplugged into screen, keyboard, mouse and other devices wherever I happen to be)
  • At least 160GB storage.
  • Bottle opener
  • Assorted knives, saws, scissors and picky things (air travel issues here)
  • GPS
  • Heart rate and other physiological monitors
  • IR and radio remote control and key control for car, TV and house
  • Credit card built in
  • Solar panel on the back in case I can’t get near a power point
  • Emergency beacon
  • Tape measure
  • Minesweeper and solitaire (isn’t that obligatory?)
  • Total lockdown of sensitive information

And that’s all I can think of right now. Anything less is just not going to blow my socks off.

When my iMate finally dies I’m probably going to go back to my trusty Nokia 8210 which pretty much does everything I currently need a phone to do.

Preload to make Linux faster

Wednesday, February 27th, 2008

If you’re running Linux you’ll be aware that it’s crazyfastâ„¢ already. Want even more speed? Get Preload. If you’re running Ubuntu you can get it by opening your console and typing sudo apt-get install preload.

EOL is live!

Wednesday, February 27th, 2008

I’ve just received the following email announcing that the Encyclopedia Of Life has finally gone live with the first 30,000 pages:

The new Encyclopedia of Life portal has gone live with more than one million species pages!
In celebration of this big event, our first EOL newsletter is available at:

http://www.eol.org/content/page/newsletter.

You can see the new pages at http://www.eol.org. We also invite you to take the survey at the site so you can help us improve.

Unfortunately I’ve been unable to get on it due to the sheer volume of people who must be hitting it right now.

The EOL aims to catalogue the 1.8 million known species and is an open collaboration that’s expected to take 10 years or so. Take a look at EO Wilson’s talk that started it all off:

Some Handy Regular Expressions

Saturday, February 9th, 2008

At least something
/.+/

A positive integer
/^\d*$/

A decimal number
/^\d*\.?\d/

A valid email address
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/

A valid web address
/^(http:\/\/)?\w+([\.-]?\w+)*\w+([\.-]?\w+)*(\.\w+)+(\/)?(\w+)?$/

A hexadecimal colour (6 chars)
/^#?[0-9A-Fa-f]{6}$/

How to use in Javascript:
var testString = "ff0000";
var pattern = /^#?[0-9A-Fa-f]{6}$/;
if (testString.match(pattern)) DoSomething();

How to use in PHP:
$testString = 'ff0000';
$pattern = '/^#?[0-9A-Fa-f]{6}$/’;
if (preg_match($pattern, $testString) DoSomething();

How to use in C#:
string testString = "ff0000";
string pattern = @"^#?[0-9A-Fa-f]{6}$”;
Match m = Regex.Match(testString, pattern);
if (m.Success) DoSomething();

Time For a Cool Change

Friday, January 25th, 2008

Tonight I set myself a challenge to redesign the look and feel of this blog without using any images. Lots of grey, lots of white space and all typography. And if you are viewing this on Linux it’s likely you’ll be treated to an eyeful of Deja Vu Sans+Serif Condensed - the sweetest open source font IMHO. Windows and Mac users get Helvetica, Arial and Trebuchet.

How to increase the number of recent comments in WordPress

Monday, January 21st, 2008

If you have direct access to your database you can change the number of recent comments that are displayed on your homepage in WordPress. I use phpMyAdmin to manage my database. Here’s what you need to do:

  1. Go to the wp_options table in your database
  2. Browse the data in this table and find the option with the name ‘widget_recent_comments’
  3. Edit this option and change the last number (it should be ‘5′ by default) to the number of recent comments you would like to display: a:2:{s:5:"title";s:0:"";s:6:"number";i:5;}

Of course, it’s quite likely that there is a setting for this in the admin panel that I’ve overlooked - I was unable to find it.

Search and Replace text in files with Python

Thursday, November 29th, 2007

#!  /usr/bin/python2.5
import os

mydir = "/path/to/directory"
mysearch = "text to find"
myreplace = "Text to replace"

def doReplace(filePath):
    fin = open(filePath, "r")
    s = fin.read()
    fin.flush()
    fin.close()
    fout = open(filePath, "w")
    s = s.replace(mysearch, myreplace)
    fout.write(s)
    fout.close()

for root, dirs, files in os.walk(mydir):
    for f in files:
        name, ext = os.path.splitext(f)
        if ext == '.html':
            doReplace(root + '/' + f)

Explanation: This will find all files ending in .html in the directory specified in mydir along with all matching files in any subfolders and will replace the text specified in mysearch with the text in myreplace. It’s only been tested on Linux but with a bit of tweaking will run on Windows and Mac.

Never Botch an Email Attachment Again

Wednesday, October 31st, 2007

Ever accidentally hit ’send’ when composing an email before you’ve attached whatever file you were intending to send? And then you have to send a quick “DOH!” follow-up email with the forgotten attachment.

I do this all the time and it makes me look like a flaming eejit.

Well, a couple of weeks ago I upgraded from Ubuntu 7.04 to 7.10 and with it came an updated version of Evolution (the Linux equivalent of Outlook). They’ve added a feature that detects if you’ve typed the word ‘attached’ but not attached any files and gives you a warning. Brilliant!

attachment message

ATI vs NVidia on Ubuntu

Tuesday, October 23rd, 2007

For the last few months I have spent countless hours battling with the proprietary (and open source) drivers for my ATI Radeon X700 card under Ubuntu. Yesterday I upgraded to Ubuntu 7.10 Gutsy Gibbon and spent a good four hours trying to get my dual screen setup working again but without any luck.

So, this morning I decided to give NVidia a go and went and purchased a new Asus EN7200GS card for a miserly NZ$80. Success! Straight off the bat too. Well, almost. I plugged it in, enabled the restricted driver, restarted and enabled the second monitor and it’s all working perfectly apart from the fact that I can’t run the ge-whiz Compiz Fusion fancy interface. Everything else is nice though - I’m finally running Google Earth and Stellarium smoothly too.

ATI have been making noises for a while now that they are going to release open source drivers but I say too little too late. I won’t be going back to ATI for a loooooong time.

If you’re running Ubuntu, have two screens and don’t want to ever have to type sudo vim /etc/X11/xorg.conf again then I recommend NVidia.

The Problems With MVC Frameworks

Wednesday, October 3rd, 2007

After experimenting with CakePHP, Zend, Ruby on Rails, Django, Turbogears, Pylons and DotNetNuke I have given up on lumbering MVC frameworks. The kind of work I do is either too small or too specialised and using a MVC framework is either massive overkill or I have to spend days trying to hack the code to join a database table in just the way I want it or connect to a webservice.

This kind of sweeping statement is not going to earn me a lot of friends. The people who are into these frameworks are devout to say the least.

Probably my biggest gripe is that the whole idea of a MVC framework is to have separation of Model, View and Controller but if you ever build a site using one of these frameworks and attempt to uncouple these components you’ll quickly see that the touted separation is not all it’s cracked up to be.

The idea of having a templating language is inspiring but the fact that there is no defined standard for templating means that Smarty only works with PHP, Kid only works with Python and so on. I take it back; XSLT is a standard but it’s got to be the ugliest, most convoluted language out there.

Defining your model is exciting when you’re starting a Hello World project from scratch but can be pretty tiring when you’ve had to make it fit an existing database that doesn’t conform to the pluralised, *_id-ised requirements of your particular framework. And on top of that you have to relearn your particular framework’s substitutions for the SQL you’ve already had to learn. “DRY” anyone?

Don’t get me wrong, the MVC way of working makes a lot of sense. I use mod_rewrite call a Controller file which in turn feeds data from my Model class to my View class. But I don’t make my Model speak anything other than SQL if I’m accessing a MySQL database and I use <?php ?> blocks in my templates if I’ve chosen PHP as my language du jour. Why learn two additional, less powerful languages?

I agree that there are many situations where you would be better off developing a large website using a traditional MVC framework but I would be under any illusion that it’ll be any more flexible a year down the track.

For me, redemption would come in the form of a standardised templating language and a standardised set of classes for models that easily integrate into existing databases as well as being able to generate new ones.

If you’re creating a small or a fiddly website then I would advise you separate your data from your logic from your presentation but steer clear of the lumbering behemoths that occupy the MVC space at the moment.