Tags

Posts tagged with: tips

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

Session encapsulation

Posted on Fri 18 May, 2007

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…

Continue reading → | Tagsrails, programming, tips

Tools for tests

Posted on Mon 9 Apr, 2007

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

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:

Continue reading → | Tagsprogramming, tips, ruby, testing

Rails quality control tip: use verify in controllers

Posted on Wed 7 Mar, 2007

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 => ...

Continue reading → | Tagsruby, rails, tips, programming

Rails speed tip: link_tag caching

Posted on Tue 6 Mar, 2007

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 => ...

Continue reading → | Tagsrails, programming, tips

Rails time-saving tips

Posted on Mon 16 Oct, 2006

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…

Continue reading → | Tagstips, rails, programming

script.aculo.us: When to use Ajax and effects

Posted on Sat 10 Dec, 2005

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:

  1. I’d use Ajax to allow users to post comments on things, to cut down on page loads. The site features screenshots from videogames as the main content, so I didn’t…
Continue reading → | Tagstips, programming, code, javascript

Processing Textile text with XSLT

Posted on Thu 7 Oct, 2004

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:

...
Continue reading → | Tagsxslt, programming, snippets, tips, textile

Processessing multiple XML files with XSLT in PHP

Posted on Fri 16 Jul, 2004

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...
Continue reading → | Tagsphp, xslt, programming, snippets, tips