Archive for the ‘Code’ Category

Chapter 2, Pong

It’s not perfect, but here is pong on the canvas! Your browser does not support HTML5 Canvas.

Share
Read the rest of this entry »

Speed of Singletons

One of the most popular Javascript patterns is the Singleton. It’s extremely useful way to create namespaces and organize your code. The thing I’ve been wondering, what is the performance cost when using namespaces? I created a loop that sets a variable 1,000,000 times and records the result. Let’s test it! Results: In this chart, [...]

Share
Read the rest of this entry »

Node.js

Recently I’ve fallen in love with node.js a web server written in JavaScript. Ok it’s not really a web server, it makes IO functions available to JavaScript code in a completely non-blocking way! What does that mean? It means it’s incredibly fast. Yeah ok, how fast is incredibly fast I hear you saying. Right now [...]

Share
Read the rest of this entry »

Star Rating Plugin for jQuery

What An easy to use rating control. It takes a normal select box, and turns it into a rating that your users can click on. The select box is preserved so you can still bind on change, get, and set the value in the rating control. The image is controlled with CSS and a simple [...]

Share
Read the rest of this entry »

Javascript, jQuery, Scope, and this

I want to talk a little bit about scope. Normally, scope is an easy concept, but there are a few little twists and turns in Javascript that make scope more complicated than it would seam. First, some basics.

Share
Read the rest of this entry »

jQuery serializeForm

What: A plugin for jQuery that makes serializing input elements easy. Once serialized you can send the elements back to the server with AJAX. Why: There is a big problem with jQuery’s built in $.serialize() method. It only uses the input elements name attribute. In practice I found that the name attribute is rarely used, [...]

Share
Read the rest of this entry »

Canvas 7, Saving and Loading

The last version of my Canvas app let you pick different brushes and draw on the grid. If you played around with the line brush you might have noticed a small bug. The line erases everything it passes over.  This is because the line has no idea what the image was supposed to look like [...]

Share
Read the rest of this entry »

Canvas Part 5

This time I’ve taking the actual drawing out of the canvas object so we can have different brushes. I’ve also included a bit of code to get the color from the current cell and compare it with a hex color.

Share
Read the rest of this entry »

Python, Evolving, Learning

I’ve always been interested in the idea of software that evolves on it’s own; software that can write itself. I’ve come up with all sorts of ways this can happen, from neurons to dynamic methods, to my latest effort, a sudo assembly language. Note: I’m not trying to replicate or create an actually assembly language. [...]

Share
Read the rest of this entry »

Canvas Part 4

If you’ve played around with the demos, then you might have noticed a little bug. If you click down in one square and let the mouse up in another square, the square you clicked down in will stay green. I haven’t addressed this issue in earlier examples because it’s not actually a bug. What I [...]

Share
Read the rest of this entry »