It gave me migraines till I discovered jQuery. Now I can validate a form with some simple CSS and a couple of lines of jQuery code. And today I had a rather odd requirement to toggle the colour of cells in a table when you click on them. In the old days, I wouldn’t even have attempted this. In my new jQuery heaven, I did this:


(document).ready(function() {
$("td.standard").click(
function(){
var currentclass = $(this).attr("class");
if (currentclass.indexOf("highlightcell") == -1) {
$(this).addClass("highlightcell");
} else {
$(this).removeClass("highlightcell");
}
}
);
});

VoilĂ !

I’ve written about date manipulation in PHP before. There are some truly horrible hacks out there. Today I needed to detect whether a given year was a leap year, in order to write future-proof code for a calendar. PHP has got to have a way of doing this. I Googled and found this. And this, which is almost as bad. Urgh. Sorry, but that is one of those occasions when the coder should have asked him/herself if there wasn’t a better way, and at least considered looking at the manual for the date function. There is of course a quick and simple way. Here it is.

So I wrote one line of code:
$maxfebday = date('L', strtotime("$currentyear-01-01")) ? 29 : 28;

I have been through quite a few different ways of blogging over the years. The personal blog I started back in 2001 originally used the ur-blogging tool GreyMatter, written by photographer Noah Grey — this was before such idiot-proof tools as Blogger and Typepad came along, so you had to be comfortable editing impenetrable Perl code to use it.

Later, when development of GreyMatter became stagnant and its shortcomings were evident, I moved on to MovableType, which for a while was the undisputed king in the increasingly crowded blogging software realm. It still required a certain level of expertise to install, but it was easier and more flexible than GreyMatter. All went well until many A-list bloggers had a falling out with SixApart, the creators of MovableType, because they decided to — gasp — charge for their software, which while free of charge had never been open-source.

Meanwhile, open-source application WordPress had been creeping up on the inside, and MovableType bloggers deserted to it in droves. That seems to have been the beginning of the end for MovableType. It was still free for single-user, non-commercial blogs, worked well, and I happily went on using it for my personal and recipe blogs.

Eventually, SixApart saw the error of their ways and released a version with an open-source licence. I made the mistake of upgrading my recipe blog to the latest version a few weeks ago. All of a sudden things that used to be easy became difficult. The admin area wouldn’t even work in my browser of choice (Opera on Linux) — so I had to go and use a Windows PC every time I wanted to write a post. Templates had become hugely complicated, and the back office used a fancy Ajaxified interface so that you could no longer simply type or paste in the code for your templates. Rebuilding the blog after making changes to the individual entry template became impossible.

I was reluctant to change systems, and thought I might wait for the bug-fix release that was supposed to cure many of the reported problems with templates. But I started to ask around, and WordPress expert Shelly told me “But exporting from MovableType to WordPress is a doddle!”

She was right; it was a 5-minute job to export 200 posts from MovableType and import them into WordPress. I then spent a few hours working through an excellent tutorial in order to convert my MovableType theme to a WordPress one. This article was useful too. It really was that easy.

Although this blog runs on WordPress, I have spent no time customising it; I just installed it, added a ready-made theme, and started posting, without bothering to explore further. Converting my food blog means I’ve had a chance to get much more familiar with the way WordPress works.

I can’t say I like the way it mingles PHP with HTML in the templates; in my own code I have achieved almost complete separation, and it looks much tidier that way.

But on the plus side, once you’ve understood the famous WordPress loop, and the template variables, there are many advantages.

  • Creating and modifying themes is child’s play compared to MovableType.
  • The admin area is simple to use and get around in (just remember to turn off the visual editor!).
  • It’s written in PHP (as opposed to Perl for MovalbeType), which means I should be much more comfortable with it.
  • It’s dynamic — no need to wait for ages for it to rebuild after a simple template change.
  • There is a host of plugins if it doesn’t work the way you want it to out of the box, opening the way to adding all sorts of extra features.

Plugins I have found useful so far:

  • AKismet: for trapping comment spam
  • BadBehavior: also traps spam; most people seem to use it in conjunction with AKismet.
  • Simple-Tags: The one thing the import didn’t do was pick up my MovableType tags. I hadn’t used many (because tags are a relatively recent feature in MovableType), but it would be a pain to have to go into every single post and add tags individually. This plugin lets you bulk-tag posts — an essential feature I would have thought.

And finally, WordPress has become so ubiquitous that I had no excuse not to learn more about it; this was a great opportunity to try it in a risk-free way on my own site before unleashing it on clients.

Meizu miniplayer

I wouldn’t say I was a gadget freak, but some gadgets do appeal to me. Nor am I a fan of listening to music on the move; I originally got an MP3 player to listen to audio books and podcasts while out walking. My first was a cigarette-lighter sized Creative Zen, which worked so well it was pinched by my husband to use as a dictaphone when he was out walking :-)

I replaced it with a pretty red iRiver the same size as the Creative. The sound quality on this one was superb, even better than the Creative (which was pretty good), but it had two flaws which meant I eventually stopped using it:

1) because of the size and shape of the player, the display was tiny. I found that even with my glasses on, I simply couldn’t read it (to be fair, this was a problem with the Zen too, for the same reason). So the only way to find what I wanted to listen to was to scroll through listening to the beginning of each item. Couple that with tiny, invisibly labelled buttons, and it became problematic.

2) It was designed to work with Windows Media Player. Problem: I don’t use Windows. A firmware upgrade meant I could use it like a standard removable drive in Windows, instead of having to go through the painful, clunky WMP to transfer files, but it wouldn’t play with my Linux PC at all.

Of course if you are a Windows user with very good eyesight, these problems won’t apply to you, and the iRiver is a very good player for its size.

Anyway, I allowed myself to be tempted by a special offer from Amazon, and snapped up a 2Gb Meizu. This has a completely different form factor: the size and shape of a credit card, only thicker (just thick enough to fit a headphone jack on one side, along with the mini USB connector). The aesthetics are beautifully thought out: mine is glossy black, with a mirror-finished back that can be used as … a mirror! Of course it picks up fingerprints very easily, but a little cloth is thoughtfully provided for polishing it up to a beautiful lustre and it has a little case to protect it from scratches.

The big plus is the bright, high-resolution 2.4 inch screen, intended for watching videos. I’ve never understood why people want to watch video on a screen that size, but I’m obviously just too old. In any case, for me it means that menus and track information are easy to read, even in sunlight. Alongside the screen is a touchpad which you use for navigation, scrolling, and volume control. It takes a little bit of getting used to, but after a skim of the manual I found it easy and intuitive; for example when listening to something you can increase the volume by simply sliding your finger up the touchpad. The same technique is used for navigating menus; tapping “Enter” at the bottom of the pad selects an option. Again, the sensitive areas are big and well-labelled enough for it not to be fiddly to use.

There are lots of possibilities for customization, including pre-set EQs for jazz, classical, pop etc. — or you can choose your own custom settings. The sound quality seems pretty good to me, from what I’ve listened to so far.

The other excellent feature is that it is OS-agnostic. To transfer files you simply plug it into you computer with the supplied USB cable and drag and drop files (videos have to be converted using Windows-only software, but I haven’t bothered with that). This works just as smoothly in Linux as it does in Windows, and you can organize the files in a way that suits you. It even supports the open-source OGG format, which neither of my other players did. Note that you should make sure MP3s and other audio files are tagged appropriately, then they will automatically be organized by artist, album etc. You can create your own directories in addition to the default ones for videos, music, and pictures — for example I created one called Podcasts — and use the built-in browser to access them. And of course you can create playlists, though I haven’t tried that yet.

Like both the iRiver and the Zen, it has a dictaphone feature, so I will have to keep it hidden from my husband :-) Unlike them, it doesn’t use standard AAA batteries (which didn’t seem to last long and were always running out at inconvenient times). Instead it has a non-user-serviceable internal battery and charges via the USB port. We’ll see whether this proves to be a problem in the long term. Battery life is said to be excellent, but I haven’t used it enough to know yet. Some people complain about lack of an option to charge directly from the mains, but as I am rarely far from a computer, I don’t see that as a problem. If it were, I believe there are USB-to-mains adapters available.

The eee now spends most of its time being used as a convenient way to play music through the stereo. This means it needs to mount the shared directory on the server downstairs that contains all the music. This caused a few problems initially because Amarok doesn’t seem to like Samba shares and it just wouldn’t build the collection even though I could access the tracks by simply browsing the file system. It took me some expert help and a few goes to get the syntax of the mount command right, and what I ended up with was rather a mouthful:

sudo mount -t cifs //silver/music /home/user/silvermusic -o username=samba_username,password=samba_password,iocharset=utf8,
file_mode=0777,dir_mode=0777

Thank goodness you can use the up-arrow to recall terminal commands! But it does work, and Amarok can build the collection correctly. Helpful Mike S explained to me how to set up fstab to load it automatically:

The following line would do it:

//silver/music /home/user/silvermusic cifs username=samba_username,password=samba_password,iocharset=utf8,
file_mode=0777,dir_mode=0777 0 0

But it would be better to not put the login details in fstab, so you should create a credentials file to hold the username and password:
sudo nano /root/.sambacred

Then add the following to it:

username=samba_username
password=samba_password

Then make it read/writeable only by root in order to keep other people out of it:
sudo chmod 600 /root/.sambacred

Then use the following line in fstab:

//silver/music /home/user/silvermusic cifs credentials=root/.sambacred,iocharset=utf8,
file_mode=0777,dir_mode=0777 0 0

Note: I have introduced line breaks for formatting here, but it’s very important to avoid extraneous spaces in these lines :-) After cifs there should be no spaces. Unfortunately in my case it doesn’t work, I think because the wireless interface doesn’t come up until after fstab has been read, in fact it isn’t activated until after the GUI has loaded. So I ended up just putting the original unwieldy line in a shell script called loadmusic.sh so I can easily run it from the shell prompt. I imagine Mike’s way would work if I was using a wired connection.

This is one of those things I can never remember how to do when I need to do it. I don’t know why, it’s really quite simple:

SELECT emailaddress, firstname, lastname,
COUNT(emailaddress)
FROM customers
GROUP BY emailaddress
HAVING COUNT(emailaddress) > 1

Chocs To Go The goal for students on the intermediate PHP and MySQL course that I’m running for IWA/HWG is to create a working shopping cart. The course starts in only three days, and I decided I’d better walk the walk and prove I could do it. So I have quickly mocked up a working version of the cart they are expected to build and put it online here. I think it will be helpful to students to see what they are aiming at, and it will make it easier for them to work out the logic if they can click through a real example. The design may not win any prizes, but the basics are all there.

All course materials now written and double-checked, quiz questions written and checked, SQL scripts generated and tested … just need to put week one’s materials up now!

Why doesn’t SQL Server come with a built-in method for generating SQL dump files so you can easily port your data to another database? Microsoft in its own little walled garden I suppose; while the facilities in Enterprise Manager for exporting to Excel, Access, ODBC, CSV etc. can be very useful, sometimes you just need a bunch of SQL statements <whisper>so you can export your data to Oracle</whisper>.

SQLDumper to the rescue; a handy little free utility that does just that, with a neat user interface that lets you select which database/tables you want to dump. Windows only, but hey, it’s a SQL server tool after all! Downside: you have to download and install the .NET framework if you don’t already have it, but the setup program handles that itself — just something to be aware of if you have a slow connection.

Since 1999 I’ve been teaching online for the Open University. It may not pay brilliantly, but it’s regular income and I really enjoy doing it; OU students often overcome major barriers to achieve a qualification they missed out on earlier in life, for whatever reason, so they can be very rewarding to teach. And the fact that it’s online means I can conveniently fit it around other work. Currently I teach three courses in the Certificate in Web Application Development.

I can now announce that I’m also going to start teaching an online course with eClasses.org, the online learning branch of IWA/HWG. The course uses PHP and MySQL to build a shopping cart, and is aimed at intermediate PHP developers (you don’t have to know anything about MySQL, but it certainly helps if you do). I’m really lookng forward to this; you can see the full course description here, and registration is now open.

On a trip to the UK just after Christmas I succumbed to temptation and paid a visit to Toys R Us. Minutes later I walked out with this:

The eee PC

Then I headed straight for my hotel, and once in my room I could barely wait to unpack it. I’d heard it was small, but I was still staggered at just how small and light it is. I switched it on, and it booted in 15 seconds, as advertised. I ran the “First run wizard” and once that was done I clicked on “Wireless networks” and without further ado it picked up the hotel’s WiFi hotspot. Unbelievably simple; I hot-footed it to reception for a card, and within minutes was checking my email.

This is a tiny, cheap sub-notebook that runs Linux and does everything I’m likely to want to do on the move: web, email, word-processing, seamless networking. The interface is a bit Playschool, but that is clearly a deliberate choice; the machine is aimed at the educational market as a cheap, easy-to-use laptop that children can carry around with them. In any case, a browse around one of the burgeoning eee fansites quickly revealed a simple fix to enable “Advanced desktop” mode, which turns out to be exactly the same as my Xandros desktop, so no complaints there. Having said that, 90% of the time I use it in “Easy” mode.

In practice of course, many buyers seem to be geeks delighted to find a cool device that runs Linux and can be hacked to do all sorts of useful things. The result is an increasing number of sites dedicated to the eee and detailing various hacks and improvements. Always a good sign when a community builds up round something like this.

Edit: interestingly, the Xandros website states:

The Eee PC is an ASUS product and is solely supported by them, including Operating system issues. The Operating System on the Eee PC is not a Xandros Product. While Xandros may have aided in the development of the Eee PC OS, it is owned and supported by ASUS.

… but the Advanced Destop mode looks indistinguishable from Xandros.

This device really suggests that the operating system is becoming an irrelevance as long as you have network connectivity. Many users of the eee PC will not know or care what the operating system is; they’ll just use it to accomplish tasks. Microsoft must be a wee bit worried, because the eee has just launched in Japan with Windows XP pre-installed (the original model comes with instructions for installing XP, but you need a valid installation disk and another PC with a CD drive to do so). I don’t really understand why anyone would want to; as delivered the machine only has 512Mb of RAM, and runs very nicely with Linux, whereas if you want anything like acceptable performance with XP you are going to have to void the warranty by installing more memory.

But some people seem to think they should be able to do everything they could do on a heavy, bulky, 15″ notebook PC on this. It’s only got a 7″ screen for heaven’s sake; what on earth is the point of trying to run Photoshop on it? For me its role is definitely that of a supplementary PC, not a desktop replacement. It’s a huge improvement on the slow, clunky Dell laptop we lug around whenever we travel. The 15-second boot time is particularly appreciated; it means you can quickly switch it on to check something, then switch it off again to conserve the battery (battery life without wifi switched on is about three hours; slightly disappointing but over twice as long as the Dell manages). Resuming from sleep mode is even faster. Plenty of thought has been put into keeping the weight down; it also has a relatively small power adapter, similar to a mobile phone one, not the “brick” you usually get with laptops. And it’s surprisingly robust; you’d expect something as cheap as this to feel flimsy, but it doesn’t.

The one thing I don’t like about it is the small trackpad and very stiff mouse button. I don’t like trackpads much anyway, and even increasing the sensitivity doesn’t seem to help. It feels as if it’s going to be the first thing to break. Using a mouse or trackball that weighs half as much as the PC doesn’t seem to make sense, so I’ve ordered a dinky little Targus mouse for it.

Next Page »