
ajax analysis api apple atom automator backpack browsers camping cheatsheets code console editors ergonomics gems google helipad hpricot internationalisation javascript lies mac optimisation patterns performance personal php plugins productivity programming prototype rails rapidrails rsi rss ruby server snippets standards sysadmin terminal testing textile textmate theory tips tools vim workshops writing xslt

Have you ever been working on a project that has session variables controlling important aspects of functionality? When they start falling out of controllers and views into a big pile of soup on the floor it’s probably time to encapsulate them.
Although relying on the session object in controllers and views is relatively easy to understand, you should be very wary when you’re tempted to use them this way. Thinking, “I’ll just add a session variable for this” will probably lead to misunderstandings or bugs later on. And on…
Writing test code isn’t easy at first, and writing good test code is even harder. I’ve reviewed several tools to help write better tests here, focussing on ruby.
Code coverage tools attempt to analyse how much of your code has been tested. Reports are generated based on your test code, with columns expressing how much code has been tested.
Incentives for using code coverage tools are:
Have you found that any of your Rails projects get hits to controller methods that expect parameters? A neat way of handling this is the ActionController::Verification module.
By adding calls to verify in your controller, you can elegantly catch all kinds of unexpected but reasonable uses of your system: from mistyped URLs and browser history auto-complete to web crawlers blindly following links. This way, you can redirect people somewhere logical instead of flashing them with an error message.
You can even insert a message into the flash:
verify :params => “user”,
:only => ...
Have you ever tried concatenating your JavaScript and CSS files for performance improvements? The idea is that latency is a bigger issue than file size when loading web pages, so stuffing all your JavaScript into a monolithic file for deployment should improve performance.
I wrote a rake task to do this for some of my applications (such as tiktrac). This is slightly more cumbersome than a feature I spied in the ActionPack changelog:
Added caching option to AssetTagHelper#stylesheet_link_tag and
AssetTagHelper#javascript_include_tag [DHH]. Examples:
stylesheet_link_tag :all, :cache => ...
I’ve created quite a few Rails projects over the last year, some commercial projects, and others are applications released under Helicoid. Here’s a few things I’ve found save time and help make projects as maintainable as possible.
Named routes
You can refer to routes in your forms and links like this: document_edit_url(:id => document.id). Isn’t that much nicer than other means? It can often make code easier to understand quickly, thus helping maintainability.
To use named routes, instead of the usual map.connect directive, use map.my_name.
Migrations
I use migrations for…
A few applications I’ve been developing recently have either had things from script.aculo.us applied for fun, to add effects our client would like, or they’ve been designed with Ajax and visual effects from the start.
A very beta application I’m working on is Multitap.net. Since it’s my project, and I don’t have clients to answer to, I’ve done whatever the hell I want with it. I had these things in mind when creating it:
Textile provides a simple way of writing human-friendly text that can easily be translated to XHTML. HTML tags are simplified into a set of phrase and block modifiers; even tables and attributes can be created.
I was looking at the PHP code for this and wondering if I could create an XSL file that could translate similar text into XHTML. I created some XML to contain my text:
And then used the following recursive algorithm to process it in XSLT:
...
I often use a message class for a lot of things with PHP. This allows me to build messages to display to the user for errors, successes and general feedback.
Classes for each of these three things are created in CSS to display the information, and then I use a simple PHP class for appending messages to a arrays.
I wanted to include this in some XML data I was processing with XSLT, but I found it difficult to combine multiple XML files with PHP’s XSLT processor. However, in PHP4, you can do it like this:
// this is a code fragment
//
$XML = implode('', file($XML_Fi...