here it is (code) – what I do is to have that page open, and the Scramble game open, in two windows side-by side. Then start a new game, type the letters into the top input box. That’ll fill in the grid. For “qu”, type “q” in the input box and correct it in the grid. Then click “do it” and cheat your way to a high score.
Also discovered a small bug in my binary search algorithm 😉 I’ve fixed it in this new script but couldn’t be bothered with the last one – I’m done with that.
Yesterday, I cheated at WordDrop, which is a Facebook game. I already had the highest score of my own network of friends, so I feel okay about this. But now that I’ve cheated, the game’s no fun any more!
WordDrop is a game where an 11×8 grid of letters is shown, and you build up words from that grid, where each letter should be linked to the one before it, with longer words getting higher scores.
I wrote a little script which basically plays the game itself, and comes up with the longest words possible.
My current score on the game is more than 500,000, and that was for a single 10-letter word. The second word the program came up with was “reselected”, which was not in the WordDrop dictionary. I just stuck with the first word and submitted that. With one word, I got a score that was about 8 times higher than my previous high score.
It’s been almost a full year since the last release, 1.3.1, and I haven’t done much on KFM in that time.
Benjamin ter Kuile, though, has! Today, we release KFM 1.4
In the time that I’ve been busy with other stuff, and procrastinating on KFM, Benjamin has been working diligently, adding features and making the core files more stable.
Here is a short list of improvements, gleaned from the SVN logs over the last year. I’m sure I’m missing a lot.
jQuery upgraded to 1.3.2 (faster, better, stronger)
you can edit multiple text files simultaneously
context menu code improved to help it work in Chrome, Opera and Safari
file icons are now created as a montage, improving display speed
a lot of functions converted to “lazyload” – improves startup speed
images are also lazyloaded – if an icon is not visible on the screen, its thumbnail is not loaded
lots of bug-fixes
Not many new features, as KFM was basically complete.
1.4 is the last 1.x version which will be released. We’re done with the code-base, and ready to start on a much more ambitious project.
We’re going to rebuilt the entire system from scratch in a modular way, adding functionality that would be very difficult to shoehorn into the present system. The new version will be called KFM 2, and I’m really excited about it. I will be starting the coding for it very soon, as soon as I’ve finished with the release of my book, jQuery 1.3 with PHP.
For those of you that are already using 1.3; 1.4 is /faster/, but 1.3 already completes the initial spec, so only upgrade if you find that 1.3 is slow. New users should install 1.4.
I’ve been sent a mockup for the book’s cover. The suggested title of the book is “jQuery 1.3 with PHP”. The working title was “PHP and jQuery”. Which do you prefer?
The book has been completed, in that all the chapters are written, and it’s in the final edit phase at the moment. This involves Packt having a technical editor try everything in the book just to iron out any kinks. It’s already been gone over by three other reviewers, and the only problem appears to have been with the File Management chapter, where the web-server was IIS on Windows. That should be solved by the time the book comes out.
I’ve learned a lot while writing this book. A major point that keeps raising its head is that I keep using colloquialisms and aphorisms (ha! “raising its head”), and those are not globally understood. Another is that I keep using British spelling, but it’s expected that most readers will be American.
From a coding point of view, I tend to write compact code with comments only appearing where something is obviously confusing, but I’ve tried to put proper comments in the book whenever any reviewer asked a question about the code.
Anyway – I expect it will be in PDF form in only a few weeks! I’m looking forward to hearing what people think of it.
On a funny note, I was working on something in work recently, and was trying to figure the best way to do it, when I suddenly remembered I’d written a whole chapter on it, so went and read what I’d written! I’ll be keeping a copy of the book on my own shelf 😉
This kind of thing is always happening to me – I would need to solve some problem (hooking an OKI B2200 printer to Linux over Samba, for example), go searching for the answer, and find that I’d written the solution for it a year or two previously…
By the way, KFM 1.4 will be released next week. It will be the last 1.x version. We (Benjamin and myself) are starting a total rewrite after that, which will become KFM 2. It’s going to be massive!
I was just looking at scales and trying to memorise how many sharps and flats each key has.
In short: count the sharps. multiply by 7. divide by 12. add the remainder in semi-tones to C. that’s the key. For flats, subtract the remainder from C.
The usual way to do this is to use the “circle of fifths” diagram:
In that, you count clockwise from C to find keys with sharps in them, and anti-clockwise for flats.
This key has 3 sharps, so you count three keys to the right of C, and that makes it A major.
If you want the minor key, then do the same, but then subtract 3 semi-tones from it, and you get F#m.
Now, what if you’ve a crap memory like me? There’s no bloody way I could remember a complex diagram like that.
Simple – let’s look at another variant of the diagram:
In this diagram, in order to figure out the key, you follow the lines; anti-clockwise for sharps, and clockwise for flats. For a key with 3 sharps, you start on C, then follow the lines 3 times, through G and D to A.
Yes, it’s another diagram, but look at the lines – they’re perfectly regular, which means that a formula can be built from it.
The formula is simply this: sharps * 7 % 12. Then add the result in semi-tones to C and you get the answer.
1 sharp: 1*7=7. 7%12=7. 7 is G
2 sharps: 2*7=14. 14%12=2. 2 is D
3 sharps: 3*7=21. 21%12=9. 9 is A
For flats, subtract the result from 12 to get the answer:
Based on some work I did for chapter 3 of jQuery 1.3 with PHP, I’ve created a plugin to encapsulate the remote selectbox trick.
The idea of this is that in a lot of cases, there may be huge select boxes in your forms, but the selected value might not ever need to change. For example, if you have a country list, and you’re pretty sure that the user is in Ireland, then it might be pointless to have a full list of countries in there if it’s unlikely to be changed.
Notice that when you click the select box, it’s populated with countries. However, the source of the page does not include those countries in the HTML. So how does it do it?
How it does it is to add a focus event to the selectbox, which populates it only when it’s actually about to be changed. In this case, the missing options are in a file named countries.html which is 9k in size. So, by using this trick, we’ve saved 9k in bandwidth. Multiply that by the amount of large selectboxes in your forms, and it could be considerable.
All that’s needed is to include a single option in there to indicate the default, then run .remoteselectoptions() on the selectbox, telling it what url it should grab the options from.
In case you need to do some checking on the server-side based on the current selected item, the script calls the option source with a selected GET parameter set to the current selected option’s value. You might set the url to a PHP script for example, which would build up the option list based on that selected item.
If you want to patch your own copy of Sortable, here’s my patch file.
I think there’s actually a moral here – if you want to make sure that something is fixed, then you should knuckle down and do it yourself, as the jQuery developers really do have better things to be doing.
For chapter 8 of jQuery 1.3 with PHP, I wrote about drag and drop. jQuery has a few different ways to do drag and drop. The most fundamental way is to use the Draggable and Droppable interfaces, but as it happens, most of the things you might want to do with a CMS can be done just with the Sortable interface.
Sorting a tree-based list (navigation menu, for example) and saving the result. demo, download
Dragging items from a list of contacts into a list of people to send emails to. demo, download
The second one worried me for a while, as it kept behaving erratically on me – I would sometimes drag an item and it would simply vanish. It turns out that it’s a bug in jQuery UI’s Sortable that should be fixed by the time the book is out, so it will work better then. I’m not worried about its behaviour right now as I’m certain this will be fixed.