Archive for January, 2009
jQuery SuperSelect
A little while back I was working on a project and wanted a selectbox to look a bit more pretty, but with complete backwards compatibility with regular select boxs.
I.E. If I already had a select box on the page, and it had various JavaScript events hanging off it already, I wanted that to function still but I wanted the box to be prettier.
The first idea was to use CSS to just style the box. But then I realised that each browser and OS has it’s own different way of rendering the controls. So I turned to JavaScript, and the always useful jQuery library. I wrote a plugin that will immediately transform any selectboxes into prettier ones, allows icons for the options, all with valid xhtml and works completely fine with JavaScript (or the plugin) disabled. Pretty cool, eh?
Well, I put the original demo page I designed for it back online, so check out the plugin!.
CakePHP Evangelism and T-Cake
So I’ve had this blog for 3 posts now and none of them has a “cakephp” tag yet. Shocking. So here we go…
If you don’t know what CakePHP is and you’ve ever created a web application, or even a website that did more than show a static page, then you should check it out. CakePHP is a web application framework designed for rapid application development using the MVC Design Pattern and with a focus on Convention over Configuration.
What this means in practical terms is that you can built an access controlled, database driven, dynamic web sites/applications in a fraction of the time that it would to start from scratch. A simple blog could be built in a matter of minutes. I could go on for hours. So I won’t, I’ll talk about my latest project, which is – you guessed it! – built with CakePHP.
T-Cake
T-Cake is going to be a Torrent Controller. It’s not a Bittorrent Client, it can’t download using the bittorrent protocol or act as a tracker. It can provide an abstraction layer to a torrent client of you choice. Basically the application will allow remote access to control torrents which will then be activated using a torrent client.
The idea came from TorrentFlux which I used for a long while on my home server. However the time came when I wanted to do more, and was frustrated by the restrictions imposed by TorrentFlux being tied to BitTornado. The key idea in this whole project was choice of client.
To achieve this aim, I built a CakePHP datasource for interacting with a bittorrent client through an interface class. Then I designed an interface class for the Transmission Bittorrent Client which has a fairly simple JSON RPC for communication. I also intend to write an interface for rTorrent which has an XML RPC (slighty more complex, but potentially more functional).
The project is still in early stages, but going strong. The fact that I have abstracted the client, means I can add any features I want whether or not the client natively would support it, for example:
- Seeding to a pre-determined limit
- RSS torrent automation
- configurable queuing system
- Multi User option - with torrents only visible to their owner / admins
- Direct Torrent search and acquire via “engine” plugins
- Alerts for preconfigured events, e.g. torrent completion, new torrent added by RSS, new queue item starting, etc…
- Alerts could be theorectically pushed to any medium, email, SMS, an RSS feed, etc…
However the proviso on the client is that it has an API or RPC that I can hook into with PHP.
Well, sounds exciting doesn’t it? I think so, I’ll post some screenshots in a bit, so you can see the start of the interface, and maybe some of the techniques I’ve used in CakePHP to make it work.
Notes on the Culture
It recently found an essay written by Iain M. Banks regarding the society he so often writes about in his Science Fiction novels - the Culture. I found it interesting, as a fan of his books, because the Culture is so appealing.
Anyway to cut a long story short, I liked the essay but the presentation of it was upsettingly difficult to read. So I have produced a version of it myself, with improved markup.
Check it out for yourself: Iain M Banks: Notes on the Culture
Regular Expressions in MySQL
I like regular expressions. Anyone who has tried to understand them will understand the learning curve involved and in no way do I claim to be an expert. However, I use them all the time. They are possibly the most useful thing I have ever learnt to do with programming and are more powerful I imagined at first.
So what does this have to do with MySQL?
Well, I was recently dealing wit a table in which there is some inline JSON serialised data. This makes sense for the situation but of course if you want to query on something within the data you have to be a bit more careful. You have two options as I saw it yesterday:
- Pull all the data and parse it out outside of the database - which seems weak and inefficient.
- Use some LIKE query to pull likely candidates and then parse out of the data base - again not so good, but a bit better.
The solution!
You can use Regular Expressions in a MySQL query! To simplify the problem I faced, suppose you have a field in the database which contains JSON data like this:
And I want to find all records which contain a specific value in the “content” array (and suppose I know which records will have the “content” array by another field/method). LIKE would not be enough as it leaves to much room for error, but Regular Expressions - easy! If I want to find the value 578 then:
Would find all records with 578 as an element in an array containing only numbers. Combine this with the method for restricting the SELECT to only filed you know will contain data in the right format and you have done it!
This is but one example, and the technique seems most useful when you have a serialised data format in your database field, but could be useful for advanced searching in table that do not support “fulltext” searches.
The First Post
So, I started using WordPress.
I have tried before, but never felt quite right. This time I braved the learning curve and dived right in.
The problem is that I want to control everything. I don’t know how WordPress was built because I didn’t write it. I don’t know how it’s templating works, because I didn’t write it. So I was wary…
This time I have taken a good look at the templating system, and manage to recreate the simplistic look that I had on my site beforehand. I am confident that I could also put more into as time goes on, but for now I am happy that it works.
So a blog eh? Well, I expect this one will be about code and what I’m currently writing, and my thoughts about it. I tend to write in PHP although innovation’s in other languages also pique my interest. On the last incarnation of this website, I had a link to some useful pieces of code that I had written, so I will create some static pages for those. Not very much, a couple of jQuery plugins, and some older Javascript Utilities that I used to use before jQuery but are pretty good all the same.