Archive for the 'Programming' Category

How to do an AJAX search with jQTouch, Part 2

In the last installment of How to do an AJAX search with jQTouch we looked at how to setup a jQTouch interface with the goal of performing an AJAX search. In this article, we will write the necessary JavaScript to perform that AJAX search, as well as a PHP script to respond to those calls.

This article assumes you have read the first part of this series.

Read more »

How to use custom jQuery animation queues

You may not know this, but whenever you use jQuery commands like fadeIn, slideDown, and delay, you are implicitly making use of a jQuery queue behind the scenes. That queue is named fx, and it is the default queue that all animations use unless otherwise specified.

In this article, we will look at how jQuery animation queues work, how to create and manipulate them, and how to use them in a meaningful way.

Read more »

Biomorph.js: Natural Selection in JavaScript

For his 1986 book The Blind Watchmaker, Richard Dawkins developed a program that created “biomorphs”: virtual creatures created by a computer simulation. The simulation, called Biomorph, was developed in order to demonstrate the power of natural selection.

Recently, in an effort to better understand how the Biomorph program worked, I decided to implement it myself in JavaScript using the HTML5 canvas element. The result of this endeavour can be found here. Read more to learn how to use the Biomorph program.

Read more »

A little bit about Webble and JavaScript games

Webble is a pure HTML/CSS/JavaScript implementation of some of the core features Wezzle game engine. By “pure” I mean that there are no external plugins like Flash used. Furthermore, Webble does not make use of the HTML5 canvas element: all the animation is done purely by moving around HTML elements using JavaScript.

Writing a simple game engine using the DOM and JavaScript poses some interesting problems that are atypical to regular website development. In this article I will discuss a few of the problems that I encountered while writing Webble and how I solved them.

Read more »

How to query posts by template in WordPress

Ever wanted to filter a query_posts call by template? If you’re reading this post, you probably have or need to right now. You probably went to the query_posts documentation and scanned for something like “template=foo” and were deeply disappointed. Then maybe, in an act of desperation, you started to trudge around the plugin library. Stop! Stop right there! You don’t need a plugin to do this. Everything you need is already in WordPress.

Read more »

Adding Extension Methods to PHP

If you’ve ever used the .NET Framework version 3.5 of later, you’ll probably have encountered extension methods. Microsoft describes extension methods as:

Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

In this article, I will show you how to write a base class that will allow you to add methods to any PHP class that inherits from it at runtime. You will be able to call these methods transparently, without any special syntax.

Read more »

How to do an AJAX search with jQTouch, Part 1

jQTouch is a pretty nifty little jQuery plugin for making websites look like native iPhone apps. Unfortunately, beyond a bunch of examples included with the distribution, there’s not a whole lot of online documentation written for jQTouch. Having started to use jQTouch for a professional project, I thought I’d help remedy this deficiency by posting what I learned along the way.

We’ll start with something fairly straightforward by making a jQTouch app that makes an AJAX call to a PHP script to search a database. It then displays the results of that search in the jQTouch app. This article is split up into two parts. The first part deals with the jQTouch UI and the second part deals with the PHP script and the supporting JavaScript.

This is part 1 of a two part series.

Read more »

Anders Hejlsberg talks about C# 4.0

Channel 9 has posted a great talk by Anders Hejlsberg, the original author of Turbo Pascal, the chief architect of Delphi, and the lead architect of C#.

History lesson: Anders was lured away from Borland by Microsoft with a hefty offer of a $1.5 million signing bonus, a base salary of up to $200,000, and options to buy 75,000 shares of Microsoft stock.

Looks like it was worth it, as each C# release has added many interesting and powerful features, while maintaining a fine balance between complexity and simplicity.

Trimming in ActionScript jQuery-style

Sometimes we want to remove whitespace from the ends of our strings. In fact, this task is so common on the web that the ubiquitous jQuery library includes a utility method for that purpose.

What about in ActionScript 3? Well, not so much. The String class in AS3 is, in my opinion, a bit lacking compared to languages like C# and Scala. What’s worse, you can’t augment prototypes easily like you can in JavaScript to add missing methods (see update at the end for more information on this).

Read more »

SpriteFactory — an AS3 library for creating multiple sprites using the same bitmap

While working on Flash sidescroller stuff I noticed that there was no easy way (that I could find) to create multiple sprites from a single bitmap (something you’d do when doing a tile-based graphics layout).

Sooo… I made my own simple library called SpriteFactory.

Here’s some example usage:

var factory:SpriteFactory = new SpriteFactory("assets/sprites");
factory.loadBitmap("grass", "block-grass.png");
var grass1:Sprite = factory.newSprite("grass");
var grass2:Sprite = factory.newSprite("grass");

Check out the project page for more information.

Next Page »