Goin' Full Require: Turtles All The Way Down

2012 Nov14
N

ow that we are comfortable the syntax for creating and loading modules we need to set up configure **RequireJS** to load anything and everything we want for our applications. Luckily the configuration API for RequireJS is rather straight forward and allows for a lot of flexibility. Configuring RequireJS is a simple as passing it an Object literal.

var SiteName = require({ });

Pretty simple! The require function returns a configured instance of RequireJS so you can stash it in a variable and use it as the loader for a specific set of modules, or as it if were your applications primary name space. Now, there are 3 options in particular we are going to want to pay special attention to -

Read More
filed under:  javascript amd requirejs

Goin' Full Require: Moving To AMD

2012 Nov02
A

MD ( [Asyncronous Module Definition](http://wiki.commonjs.org/wiki/CommonJS) ) is a apart of the [CommonJS](http://www.commonjs.org/) movement. It aims to bring something to javasscript is very much needed in todays world of browser based applications. And that is the idea of modules. A logical way of breaking your apps into smaller, more logical peices and import dependencies only in the situations that you actually need them. [RequireJS](http://www.requirejs.org) is at the fore front of JavaScript Module loaders, and for good reason. When you start to dig into RequireJS, you'll find that it isn't just a fancy script loader, but more of a micro-framework for managing large JavaSscript Apps.

Make The Move

Its

Read More
filed under:  javascript amd requirejs modules

Keep NodeJS Alive With Uncaught Exception

2012 Jul25
N

odeJS is still a pretty young project, and as you might expect, things can sometimes go wrong with out any obvious reason as to why. The [http module](http://nodejs.org/api/http.html) for example, especially in some earlier versions of node, will just throw an error and die - bringing your application down with out batting an eye! While not the most desireable method, you can pretty much catch any error comming from a NodeJS process and react accordingly:

process.on( "uncaughtException", function( err ){
    //do something usefull
	console.log( err )
});

NodeJS exposes a global object called process that you can listen for the uncaughtException event oddly enough, which you can listen to. As long as

Read More

Fun With Mootools Part 2: Protected Methods

2012 Jul17
P

rivate and protected class methods can come in handy when creating complex applications. While JavaScript doesn't provide these features natively, [Mootools](http://mootools.net) provides a mechanism to define protected methods on a class. Protected means that the function can only be called by the originating class or a sub-class of the originating class. An attempt to call a protected function by a different class or from an instance of the class would result in error. Here is how you do that with a mootools classs:

var SecretClass = new Class({
	Implements:[Options]
	, initialize: function( options ){
		this.setOptions( options );
		var s = this.protectedMethod();
	}

	/**
	 * A regular class method 
	 */
	,publicMethod: function( name ){
		alert("Hello" + ( name || "world") + "!"
Read More
filed under:  mootools class javascript oop

Running Django On wsgid with Mongrel2 & ZeroMQ

2012 Jun27
I

love Django and I love Python. However, I also love javascript, Node.js, and I even like playing with Ruby and Ruby on Rails. I love playing around with cool web technology in general. But the the one thing I've always hated was building apache correctly to handle all of these different apps and languages only to have to sit Nginx In front of it. What I really want is a single light weight server that can deal with any application written in any language with out having to build modules, plugins or even recompile the server to get everything to work right. What would be even better is if all of these apps running on a single server

Read More

Pythonic Iterators With Mootools

2012 Jun12
P

ython comes standard with an interesting module called, itertools, which provides a set of functions that make performing complex computations that revolve around iteration much easier. It is actually a invaluable set of tools to have at your disposal when you get comfortable with them. The module itself can work with anything that implements the iterator interface. An iterator is an object wrapper around some sequence that exposes a method called next. When the next method is called, the iterator should return the next item in the sequence and throws a StopIteration exception when there is nothing left in the sequence. While JavaScript doesn't offer anything that would resemble an iterator, that are actually very simple to implement when

Read More

Dynamic Django ModelForms

2012 May05
T

he forms module in Django is pretty amazing and it allows you to do some rather complex things with not a lot of code. Django forms ships with a class called, ModelForm. ModelForm, if you are not familiar, when given a model class, on an instance of a model, will generate a form instance for you complete with validation. You can, of course, specify which fields to exclude from the form and which widgets to use for each field.

Django forms ships with a class called, ModelForm. ModelForms, if you are not familiar, when given a model class, or an instance of a model, will generate a form instance for you complete with validation. You can, of course, specify

Read More
filed under:  python django closure modelform

Case Study: Cross Browser Logging AMD Module

2012 Apr24
T

he console object, which allows developers to echo arbitrary pieces of data out to a console in the browser, is becoming a standard piece of equipment in most browsers. However, there are some browsers that do not have a console implemented, and leaving code that references the console object in browsers that do not have one will cause your javascript programs to die.

To normalize and remedy this pain point in development We will define a Log module to encapsulate the desired functionality. Or example will aim to mimic the api of the popular firebug development tool as well as provide a fallback for browsers that do not implement a logging console as well as for browsers that do

Read More
filed under:  log amd commonjs console requirejs

Create A File Watcher With NodeJS and Child Process

2012 Apr15
I

t is not uncommon in the life of a software developer to want to execute a series of tasks every time a file changes. It tends to come up more frequently in development, for example, you might want to concatenate a series of files, or send and email to an administrator, etc. It becomes even more beneficial to be able to watch all of the files in a given directory. Surprisingly, for as much as it seems to creep up, it tends not to be standard machinery it a large number of programming languages and their standard libraries. Luckily, [Node.js](http://www.nodejs.org) gives you all of the [tools](http://http://nodejs.org/api/fs.html#fs_

Read More

Fun With Mootools Part 1: The Class toElement method

2012 Apr14
T

he [MooTools](http://www.mootools.net) ( My Object Orientated Tools ) JavaScript framework is a pretty sweet piece of software. It's goal is to make developing with JavaScript easier. It provides large set of tools for building complex JavaScript applications. There are a lot of hidden [goodies](http://www.youtube.com/watch?v=6nOVQDMOvvE) tucked away in the framework that kick off one of those ["AHa!" moments](http://en.wikipedia.org/wiki/Eureka_effect). One of those goodies is the toElement method on classes. One of those goodies is the **toElement** method on classes.

The Class' method, toElement, works in tandem with the MooTools document.id ( $ ) method. In most cases, Classes center around a DOM element for some reason

Read More
filed under:  dom mootools class javascript oop