Home » Topics » 

Javascript

apache_prettify

Nick Nettleton | 24 April 2009

apache_prettify adds code colouring and line numbers to Apache configuration code - the stuff you write in httpd.conf and .htaccess. Most useful if you are publishing this sort of code in your blog.

  • Written in JavaScript - works in the browser
  • Dead easy to use
  • Compatible with all JS libraries - jQuery, prototype, etc
  • Quick - just a couple of regexs
  • Lightweight - 1.35K minified
  • To change the appearance, just edit apache_prettify.css

Read more Comment


Validate a credit card number in JavaScript

Nick Nettleton | 12 August 2007

When you're writing web apps, it's good to do validation both in the browser and on the server side. Do it in the browser to provide your user with instant feedback, and on the server for real security, as all client-side validation can be tricked or circumvented by those who know how.

Validating credit card numbers is a little tricky. They all follow a special algorithm, whose name I forget. But here are the mechanics of it...

Read more 1 comment


JSON - better than XML?

Nick Nettleton | 02 July 2006

JavaScript coders have been doing it for ages. Now it's got a name: JSON, or JavaScript Object Notation.

One of the sexier features of JavaScript is a shorthand notations for defining and populating a data structure containing objects and arrays. So, instead of:

me          = new Object() ;
me.name = 'Nick' ;
me.age = 30 ;
me.hobby = new Array()
me.hobby[0] = 'Reading' ;
me.hobby[1] = 'Writing' ;
me.smelly = false ;

You can do this...

Read more 4 comments


Trim a string in JavaScript

Nick Nettleton | 01 July 2006

I've seen all kinds of techniques used to trim a string in JavaScript, some of them a bit bonkers. Here's the 'right' way:

var trimmed = str.replace(/^\s+|\s+$/g, '') ;

So there.

Permalink 47 comments