Archive for the ‘Python’ Category

FormLess - style agnostic and auto-validating forms

Thursday, January 1st, 2009

Creating HTML forms can be a drag. Validating the form input is even worse. I wrote up a javascript utility to demonstrate how easy and enjoyable it could (should) be to create forms. Check out the demo. You create a form with:

new FormLess('form-container-element-id', items);

where items is an array of objects. Each item requires at least a name and a type, but could also take an array of options or a validation function that gets called to validate the value of that item.

items = [{
  name : 'Gender',
  type : 'select',
  options : ['None of your business', 'Male', 'Female'],
  validate : function(data) {
    return data && data != 'None of your business'
  }
}]

Each time an item’s value changes, the validation function gets called for that item. If a validation function returns false, the item gets marked as invalid. Valid and invalid items can be styled however you please:

.valid {
  background-color : green;
}

.invalid {
  background-color : red;
}

When the form is submitted, each item gets has its validation function called. If all validation functions pass, the submit function gets called along with a key-value object containing the items names and values. This tool has not been tested across browsers - it’s mostly a demonstration of how easy it should be to gather and handle user-entered data. Check out the demo Screenshot of FormLess demo application

I’ve Got Code Running on Google

Monday, May 12th, 2008

Google App Engine is awesome.

Repeat. Google App Engine is awesome.

A quick tutorial video, 30 minutes of tinkering and playing around, and I’ve got database code running on Google’s BigTable(!). Go check it out - leave a shout.

Oh, and it turns out - Ruby to Python isn’t that bad after all.

Google I/O Registration - Comes with App Engine Invitation

Monday, May 12th, 2008

I finally registered for Google I/O, and was happy to see that it comes with an invitation to App Engine. Tonight I’m meeting up with a Python friend to show me the ropes.

I’m now intending to port ShareWithMe from rails to python and BigTable for its first, long overdue release.

Pretty Code on your (wp) Blog

Tuesday, May 6th, 2008

What? How to make your code look pretty on your blog with minimal effort. Meaning language appropriate highlighting without even specifying which programming language the code is in. Why? Because

/**
* A miss manners guest
* @constructor
* @param {Object} params The parameters object. All other parameters are named properties of this object
* @param {String} name The guest name
* @param {String} gender The guest gender. 'male' or 'female'
* @param {String} interest The guest interest. A single string. You should give guests interests so that some match up - this is what the rule engine bases their placemenet on.
* @param {String} color Hexadecimal value of the color to represent the guest with.
*/
MissManners.Guest = function(params) {
  this.name = params.name || this.Default.name;
  this.gender = params.gender ? params.gender.toLowerCase() : this.Default.gender;
  this.interest = params.interest ? params.interest.toLowerCase() : this.Default.interest;
  this.color = params.color || this.Default.color;
  this.id = 'MMGuest-' + MissManners.nextUniqueId++;
}

Looks infinitely better and is much more readable than

/**
* A miss manners guest
* @constructor
* @param {Object} params The parameters object. All other parameters are named properties of this object
* @param {String} name The guest name
* @param {String} gender The guest gender. 'male' or 'female'
* @param {String} interest The guest interest. A single string. You should give guests interests so that some match up - this is what the rule engine bases their placemenet on.
* @param {String} color Hexadecimal value of the color to represent the guest with.
*/
MissManners.Guest = function(params) {
this.name = params.name || this.Default.name;
this.gender = params.gender ? params.gender.toLowerCase() : this.Default.gender;
this.interest = params.interest ? params.interest.toLowerCase() : this.Default.interest;
this.color = params.color || this.Default.color;
this.id = 'MMGuest-' + MissManners.nextUniqueId++;
}

But this can be a pain to get right (you know if you’ve tried). There is an easy way, especially for all us WP bloggers. How? With wordpress, the easiest thing in the world. Just download Google Code Prettify for wordpress v1.1 to your wordpress wp-content/plugins directory with


curl -O http://www.deanlee.cn/downloads/google_code_prettify_v1.1.zip
unzip google_code_prettify_v1.1.zip

Then go to your wordpress plugins admin area at /wp-admin/plugins.php, and activate Google Code Prettify. The next time you write code, just wrap it in <pre class=”prettyprint”> /* your code here */ </pre> and the plugin takes care of the rest. Seriously - you don’t even have to specify the programming language your code is in. *Thank you!*