Tags

Posts tagged with: code

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

JavaScript function to help with Accesskeys

Posted on Wed 21 Dec, 2005

There’s a few little touches I like on sites I frequent: sensible tabindexes for forms, accesskeys and so on. Once I learn the accesskeys, I can fly around the main sections of a site. I apply these things to the sites I build, and the other day I realised adding accesskeys and supporting markup was no fun at all.

I wrote this JavaScript function to search for all your accesskeys and add some friendly markup. It even detects if the user is running Windows or Mac OS, to tell them to use ‘alt’ or ‘ctrl’:

function underline_accesskeys()
{
var links = document.getElementsByTagNam…

Continue reading → | Tagsjavascript, code, snippets, 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

Single-table inheritance and validates_as_unique

Posted on Tue 29 Nov, 2005

I had a User class, which then had a Moderator class. I was using the “type” field in my database to denote whether a user was a User or a Moderator. However, my validations weren’t working as I expected:

validates_as_unique :name, :email

Users could have the same email address as Moderators. Obviously sometimes this kind of scoping makes sense for STI classes, but it doesn’t here. I ended up writing this:

module ActiveRecord
module Validations
module ClassMethods
# Intended for use with STI tables, helps ignore the type field
def validates_overall_u…

Continue reading → | Tagssnippets, code, programming, rails

Javascript Mini Bibliography

Posted on Fri 18 Nov, 2005

I often annoys me when people don’t make it clear what they’re referencing in an article. Sometimes people don’t give any references at all, and when they do they use links on words that shouldn’t be links (the click here syndrome).

So I wrote this Javascript to help out. It adds a section at the bottom of each of your Wordpress posts containing all the links you referred to in a post:

/* From Prototype /
document.getElementsByClassName = function(className) {
var children = document.getElementsByTagName(‘
‘) || document.all;
var elements = new Array();

for (var i =...
Continue reading → | Tagsjavascript, snippets, code, programming