Author Archives: verens - Page 2

saorfm: first visible results

The first visible project using SaorFM is a jQuery file-selection widget:


Here is the source of that page:

		<p>Select a file</p>
		<input id="file-select" />

		<link rel="stylesheet" href="" type="text/css" />
		<link rel="stylesheet" href="/saorfm/jquery-widgets/jquery.saorfm/jquery.saorfm.css" type="text/css" />

		<script src=""></script>
		<script src=""></script>
		<script src="/saorfm/jquery-widgets/jquery.saorfm/jquery.saorfm.js"></script>

In the above demo, we link in the jQuery and jQuery-UI scripts, and load up the widget’s script.

The only content elements are a <p> telling the user to choose a file, and a normal text <input> box which the user can use as a combobox.

The magic happens with this little bit of JavaScript:


That tells jQuery to convert the #file-select input box into a saorfm widget. The only parameter in this demo is rpc, which tells the widget where the SaorFM server is to be found online.

To install this on your own server, all you need to do is download the SaorFM engine from Google Code, and add a config.php file to the core directory. Here’s mine:


In that, a JSON-encoded hash object contains the configuration. Change the user_files_directory parameter to your own files directory, and you are done with the configuration!

I’ll be adding this to my WebME project next week, after I’ve finished writing the tests (Selenium and PHPUnit).

SaorFM, first few commits

Last Sunday, I announced that Conor and myself were starting a new file manager called SaorFM.

We started out slow, because we want to have absolutely everything in this to be checked by PHPUnit (for console-style testing) or Selenium (for GUI testing).

We’ve got enough written that you can do the following:

  • Write and save a config file.
  • Rename/Move files.
  • Delete files/directories.
  • List the contents of a directory.

All of the above have automated tests, so we’re fairly sure they’re correct. The main class’s source is readable here, and the test’s source is readable here.

Conor is currently adding support for SaorFM into his own CMS, Furasta. I’ll be working on adding it to my own tomorrow (got relatives coming over today – busy busy!).

We need to add some more functionality to make this basically complete:

  • Move directories.
  • Upload files.

After that, things get interesting, as we’ll be adding a plugin architecture.

Tomorrow, I’ll be finishing up the basics, and will write some simple jQuery plugins to select files, select directories, upload files, etc.

Soon, we’ll be catching up on KFM in functionality ;-).

keeping an admin session active

I had a call from a client who asked why, after logging into a CMS admin area and spending an hour or so writing a document, she was unable to submit it because it claimed she was not logged in.

The answer was that the session had expired.

On busy servers, one method of optimisation is to reduce the session-time. This makes it easier for the server to cope with a large number of visitors, but also has the undesired effect of logging people out if they take their time over anything.

One solution to this is to keep the admin session in a database table, tied to a cookie in the browser. Unfortunately, that means that every time the browser sends the cookie, it must be verified, whereas a session is usually trusted.

The workaround is to use some JavaScript to refresh the session every now and then.

I wrote a simple cyclical script which polled the server every minute to refresh the session.

Here it is, using jQuery to handle the AJAX:

function keep_session_alive(){

And the server-side code is this:


Very very simple trick. The polling could be enhanced, if you want, to alert the admin of anything interesting that’s happened on the server.


Last night, I spent four hours chatting with Conor MacAoidh.

We’re both the authors of CMSes, and both need file managers.

I’m the original creator of KFM, but recently, I’ve been getting annoyed at it. The project has grown too large to be easily managed, and it’s slow to start up because of the amount of database configuration involved.

We discussed this, and came up with a plan, which coincides with what I wanted to do for KFM2, but is probably much better.

We are going to reboot the whole thing – write a complete new file manager from scratch. It will only use code from the original KFM2 if the code is demonstrably better than any alternative we come up with.

The project will be properly documented, will have 100% test coverage, and will be completely free.

It will come in a number of separate parts, but only one, the core, will be absolutely needed.

The core of the engine is the bit which handles the actual file management. It will be designed to load in only two or three files for the most part, and as fast as possible.

Communication with the core will be done by either including the core as part of your own CMS, or by interacting with it via RPC.

The RPC will be very important – you send a command such as /rpc.php?action=move&from=/my-files/test1.jpg&to=/images/me.jpg, and results will be returned as JSON.

We decided on the name SaorFM. While this may be slightly confusing for non-Irish-speakers (“Saor”, pronounced half-way between “sair” and “seer”, means “Free”), we feel this is not very important. After all, Ubuntu is a household name, and that’s Bantu.

The main site will be, the blog will be here, and downloads, issue tracker and SVN can be found here.

We’re still deciding on how to go about things, so there are no downloads yet. The decision to do this was made literally last night.

Having a co-developer on board from the absolute start will encourage me to get my arse in gear on this – if Conor does something cool, I have to beat that. And vice-versa, hopefully!

I’m starting the project off at the moment by working on a description of what it’s all about, and then will start writing some starter tests. This will use “test-driven development”, so every single line of code in this project will be repeatedly tested throughout the development.

We’re planning a load of features, such as desktop-/system- integration for Linux, Mac and Windows, and having totally external UI systems. We even considered going mad and creating a bump-top-like UI for it.

It’s taken me almost a year since planning KFM2 and getting to this.

Part of the reason for the delay is that this is so far removed from the current KFM, that I really didn’t know how to bring KFM1 up to the specification I wanted to reach.

Starting from absolute scratch with a brand new name is the right thing to do, I think.

javascript compression tip

I was just reading through the latest article in A List Apart, and there was a little bit of discussion on the following snippet of code:

function getValueFor(data){

  var value;

  if (firstCondition(data)){
      value = 1;
  } else if (secondCondition(data)){
      value = 2;
  } else if (thirdCondition(data)){
      value = 3;
  } else {
      value = 4;

  return value;


When compressed with YUI Compressor, that’s reduced to 140 bytes.

By changing it slightly, you can reduce it further:

function getValueFor(data){

  var value = 4;

  if (firstCondition(data)){
      value = 1;
  } else if (secondCondition(data)){
      value = 2;
  } else if (thirdCondition(data)){
      value = 3;

  return value;


That’s reduced it to 133 bytes.

I think Nicholas missed a trick, though – by removing all the “else if”s and replacing them with ternary operators, he could reduce it even further:

function getValueFor(data){
  return firstCondition(data)

The above will reduce to 95 bytes. That’s 95, where the previous record was 133.

more music scams…

last year, I wrote about some scams where people claimed to be looking for music lessons for their son or daughter.

So far, I have not had one single student for guitar come to me through email or the Internet. Every single request has been a scam.

Here is an example email I received today from (Andrew Barton):


I’m Andrea Barton during my search for a Music Instrument Lessons teacher that would always take my Daughter (Gwyn) and I found your advert.Your advert looks great and it is very okay to me since you specialize in the area I am seeking for her. My daughter will be coming to your Country before the middle of July for 2 Months. She is just 15yrs Old, a beginner, I want you to help me teach her music during her stay in the Country because i will not want her to less busy, i want her to engage in something to keep her busy during her stay.

So, kindly let me know your charges cost per week in order for me to arrange for the payment before she travels down to your country.I would also like to know if there is any Text Book you will recommend for her as a beginner so that she will be reading privately at home after the lesson during her stay.

Please Advise back on;

(1) Your charges per 1 hour twice a week for 2 Months?

(2) The Day and time you will be available to teach her During the week?

(3) Tuition address?

I will be looking forward to read from you soonest.

Best Regards.

There are a few things about this which should immediately strike anyone:

  • People don’t usually mis-spell their own name. Is it Andrea (in the text) or Andrew (in the email address)?
  • There is no mention of what instrument the girl is supposed to be learning. Guitar? Piano? Didgeridoo?
  • The weird capitalisation says to me that translation software has been used, and only for some specific words. I can imagine a template that goes something like this: “I’m ________ during my search for a ________________ teacher that would always take my ________ (____) and I found your advert”. Every one of the blanked out words was inserted with capital letters.
  • There’s a lot of talk about countries – “your Country”, “the Country”, “down to your country”. This person obviously does not know what country I am in, yet knows that his/her daughter will be coming to it?
  • As for that, “My daughter will be coming to your Country before the middle of July for 2 Months.” The email arrived at 2 in the morning today. It’s the 18th of July. A real request for upcoming lessons would surely arrive weeks or months before the trip had already started?

There is a quirky little urge in me to take this as far as I can. However, I’m also not made of time, so I won’t bother.

So here’s the warning: NEVER trust an email from anyone you don’t know.

Here’s how this would pan out if I took it seriously:

  1. We agree price and dates.
  2. They send a cheque and urge me to cash it. I go to the bank and do so.
  3. I suddenly receive an urgent email saying there’s been an error and they sent me too much, and to please send back the extra money.
  4. Of course, that involves me writing and sending a cheque of my own.
  5. They then cash my cheque.
  6. Their cheque then bounces….
  7. The student never turns up.

So don’t be an idiot. Either throw these email in the spam directory (or delete it), or have fun trying to get the guy to do ridiculous things, but never take it seriously.

Btw: here’s an example of this same exact person being a bit over enthusiastic with the attempts – 9 copy/paste messages, with two separate daughters, Rita and Marsha – this guy should probably have got the kids lessons when they were younger…

audio alerts for php errors

I tend to keep a log tailing in one console while working in another.

tail is a Linux program that displays the last few lines of a file. If you run tail -f /var/log/httpd/error_log as root, or as your normal user if you’ve set the right permissions, then you will see any errors as they are added to the log.

However, I also tend to get immersed in my coding and not notice any errors until they cause a visual problem.

What I needed was a program that would watch my log, and beep to get my attention if an error was added.

This article explains how to set that up in Fedora.

First, install the program swatch:

[root@ryuk ~]# yum install swatch

Now create /etc/init.d/swatch, which is the startup/shutdown script for the logger:


case "$1" in
                /usr/bin/swatch --daemon --config-file=/etc/swatch-httpd-errors --tail-file=/var/log/httpd/error_log --pid-file=/var/run/
                PID=`cat /var/run/`
                kill -9 $PID
                echo "Usage: $0 { start | stop }"
exit 0

Notice the two file locations in the /usr/bin/swatch command – the configuration file location, and the log file to be tailed.

Make the file executable:

[root@ryuk ~]# chmod +x /etc/init.d/swatch

Now create the configuration file, /etc/swatch-httpd-errors:

watchfor /PHP Parse error|PHP Fatal error/
        exec mplayer /home/kae/sounds/beep-8.wav > /dev/null 2> /dev/null

You can have swatch do basically anything, from sending an email, to flashing lights in your face if you have them connected to the computer. All I wanted was a little beep.

Change the exec command to whatever your want.

I started experimenting by having Arnold Schwarzenegger yell “What the hell are you doing??” at me, but that could get annoying for other people. In the end, I changed it to a beep – a very /short/ beep. More of a tick than a beep.

Now start up the daemon:

[root@ryuk ~]# /etc/init.d/swatch start

Create a php script with an error in it, and view it in your browser. You should get a satisfying beep.

If you want to have this run automatically when the laptop boots, add the above command to the /etc/rc.local file.

long beep short beep short beep

Bronwyn’s laptop just “died”. She turned it on, there was a beep sequence (“long short short”), then nothing appeared to happen.

All the lights were on, the fan was running and there appeared to be activity, but nothing showed on the monitor.

The problem, it appears, is that the GPU overheats too easily and was soldered incorrectly to the motherboard by HP (it’s a HP Pavilion dv2000). When it overheats, the solder melts. When the computer is turned off, the solder solidifies and shrinks, breaking the connection with the GPU, causing the laptop to fail to turn on the video when next booted up.

The proper solution is to replace the GPU, or at least to re-solder the connection and improve the thermal flow around the chip. Unfortunately, I’m just not technically able to do that.

The temporary solution is:

  • Place the laptop on a cushion so the air intake ports are blocked.
  • Turn on the laptop.
  • Let it overheat for ten minutes or so. This will melt the solder again, re-establishing the connection.
  • Turn off the laptop.
  • Turn on the laptop.

Obviously, this is a temporary solution until I can get the cash to pay for a new laptop for her. After that, the laptop joins my collection of broken laptops and will be used for something or other that doesn’t need a working video card.

piano grade 2 results arrived

I did the grade 2 exam three weeks ago. The results just arrived: “successfully passed in the second grade examination in Pianoforte with first class honours”

Cool, I’ll shove that certificate up on the piano next to last year’s one.

I’m going for grade 3 in September. Was meant to do grade 2 a few months ago, but couldn’t find anywhere close that would do the examination. The nearest was in Louth, but that’s too far to walk.

Here are the examiner’s notes:

Max Marks Requirements Examiner’s Comments Marks Awarded
15 Scales & Arpeggios Very good. Good choice of speed but make sure you keep it nice and steady! Very good tone. 13
10 Sight Readng Very good. Mind the counting 9
10 Ear Tests Very good. 9
5 Theory Excellent. 5
20 First Piece Sonatina in G: You caught the mood well. Nice fluent performance. Good phrasing, tone, dynamics and technique. 18
20 Second Piece Waltz: Another lovely performance. Very good balance in left hand melody. Great attention to detail. Very enjoyable! 19
20 Third Piece Samba: Excellent rhythm throughout. Very good range of dynamics and good use of arm weight. Good control throughout. Well done! 18
Total/Additional Comments: Congratulations! Keep up the excellent work! 91

As you can guess, I’m pretty happy about this!

I’m hoping the keep up the high marks for the next exam. My teacher says my pieces for that exam are already at “pass” level, so three more months of practice can only improve that!

I’m hoping to have enough money next month (royalties from my last book) to afford a new piano and a camera, so may be able to stick some tunes online soon.

review: Expert PHP5 Tools

In short: great overview of the various tools and processes that can be followed to make working in PHP easy and manageable. I have a new employee here in the office who will be getting this book after me, to quickly bring her up to speed on good practices.

The Good

As you might guess from the “new employee” comment, even though the word “Expert” is in the title, you don’t need to be an expert PHP programmer to use this book. It’s an all-round overview of the programs you might use during your day-to-day programming life for the next few years.

As the author (Dirk Merkel) suggested in the book, some people may disagree with some choices in the book. For example, I am a fervent Vim user, but the book chooses Eclipse as its programming environment of choice.

From a broader point of view, the Eclipse IDE may be the correct one for programmers to use, as it offers much more than just a text editor. As for me, it’s hard to change an old dog’s habits!

The book includes some handy reference notes for various tools, such as SVN or phpDocumentor. It’s good for people that are not used to reading online references for everything to have them all in one book.

Each chapter is immensely in-depth. To the point that it’s almost like each chapter is a mini-book on its own subject. In some cases the chapters include everything you might ever use on those subjects.

For myself, I’m interested to try some of the suggestions in the Continuous Integration chapter and throughout the book, as I already run a few projects where updates are more important than releases. I’m especially interested in integrating SVN with automated testing and style-checking. Test-driven Development is described in the book, and it certainly seems more robust than my current “deadline-driven development” style!

The Bad

There were code samples in there that could have been shortened immensely by choosing a different spacing scheme or reducing the comments. For example, in the Debugging chapter, there is a code sample that goes on for 9 pages. That’s a lot of code to read… If the empty lines and comments had been removed or reduced, Dirk could have cut it down to maybe 4 or 3 pages, making it much more readable in print. As it was, I did my best to read through it, flipping back and forth between pages to find where references went or came from.

The Ugly

Actually, there wasn’t really anything in this book that I’d call ugly, apart from the overly long code examples.


Immensely useful for the professional programmer. Especially a programmer who needs to fit into a team.

I’m no beginner myself, and picked up quite a few tips throughout the book.

Buy this book – it’s worth it.