Coding Samples

Selected code samples. Clicking on any of the sub-headings ("Working with Email", for example) will show you the relevant samples. [check my css to see how I do it]. PHP Source code examples are highlighted for easier viewing.

PHP & MySQL

Here are some samples of PHP code I've written. Most of them will not function on their own, because they are part of an application or project -- but the source has been included so you can get an idea about how I write. (Click on one of the subheadings to the left to see the samples)

Working with Email

Upload Class

This is a class that I wrote when we were asked to create a form so students could register for a writing contest. It needed to be able to submit attachments (.docs and .pdfs). I wrote this general class first, and then extended it into the Attachment class below.

Attachment Class

The attachment class is for Email attachments from Form submissions. It snags the file, encodes it, and spits it back out on command.

Mailer Script

This script is a general mail processor that uses the Attachment class above to email attachments. It conforms to MIME standards. There are some additional measures taken to circumvent potential SPAM relay wannabes.

Working with MySQL

MySQL DBO Class

This class is the standard DBO I've been using for connecting to MySQL (and with some slight modifications, T-SQL) databases. It's easy, clean, and functional. I can't claim complete authorship of it, unfortunately, since it is largely derived from a book example (I think it was one of those Quickstart Guides...).

I've done some additions and hacking to it, most notably the "Safe_query" function for parametrized querying / SQL Injection protection. I have included it here for that as well as reference, since I think I use it in one or more of the other examples.

Queries used in the "Testing Service" Application

This file contains some query definitions I used in an application for the Teaching & Learning Center (TLC) Center for Teaching & Learning. The application [screenshot] is for students to remotely sign up for test sessions proctored by the CTL (primarily for distance education students). It is behind an authentication page, so I can't provide a direct link, but the screenshot might give you an idea of what it looks like. (it's not very pretty, but it works.)

As the comments say in this file, I realize that this would be better suited to Stored Procedures -- but SP's aren't something I have fully learned yet, so I stuck with more familiar methods. I'm very comfortable with normalizing databases, JOINing, sub-queries, etc. and have recently taught myself how to use FK constraints / cascades.

Structure of the "Testing Service" database (T-SQL)

For reference, the structure of that database, in ASCII tree format. It's very simple (3 tables) but is more or less normalized and uses Foreign Key constraints to manage cascading deletions.

Working with the Filesystem

Directory Object Class

This was a class I wrote a year ago to supplement the Gallery builder script (below). It creates object representations of folder hierarchy, recursively.

Gallery Builder Script

This gallery builder can be seen in action on a client's website. It was written so that my client could maintain her various galleries through FTP. The script renders all the HTML, and creates thumbnails where necessary, so all she has to do is upload, name, delete, etc.

Working with XML

Events RSS Reader

The IU East website once pulled down an RSS feed from the centralized events database (no, they don't have web services yet. :( ). This script uses cURL to pull down the feed, store it in a cache file, and then use the XMLParser class to transform it into something useful.

Working with Sessions

Rock Paper Scissors Application [Source]

This was an application I wrote for a course awhile back. We were required to use sessions. This particular application tracks the progress of your choices and maintains a running total of scores & choices. It utilizes AJAX (see below) for asynchronous processing. (FWIW, I did the cheesy graphics as well)

Working with Images

getText (used on this page)

I didn't have anything handy, so I just threw this together real quick for this page. I began with the sample script on the php.net writeup for imagettftext function, but hacked it to allow parametrical data. It even dynamically creates drop shadows based on background-color!

Here, you can even play with it:

Templating

Athletics Template Source [Screen Caps]

This is a hacked wordpress theme I did for the IU East Athletics department. It does the standard Wordpress Loop, but also some side-queries for additional information. The obvious important feature here is the universal HTML markup for varying database-content. I'm very familiar with the concept behind templating, even if we don't use DB-driven templates at my current job. NOTE: The template code shown in the source example is NO LONGER CURRENT. I did, however, do the site design for the Athletics website (as of 2009, inclusive)

JavaScript / AJAX

Back in 2008, I started using Prototype & Scriptaculous. I'd been doing AJAX for a little over a year prior to that. If I need high functionality, I use Prototype, if I just need simple Asynchronous connections, I use the AJAX-Lite script I wrote, below. I'm very comfortable with the technology, and use it wherever it's needed.

AJAX

AJAX Lite: Scriptlet

This is a script I based off of a textbook example by Lee Babin. It's been significantly hacked though, and now allows flexible responses based on output, as well as Response-chaining (to prevent a racing condition).

In Action: Mad-Libs

This was probably the first AJAX application I wrote. It was before I knew about XML, or JSON, or any effective method of serialization, so I ended up hacking my own serializer (comma and colon separated). It was also before I figured out AJAX chaining, so I was sending a bit more data than necessary. You can view the JS source here and the PHP source here. It is database driven (MySQL), although I don't have the database structure handy. You can kind of get an idea from looking at the PHP source though. There's only four or five "madlibs" loaded (three of them are Shakespeare ;) ) and a few dozen words -- it's pretty funny though. Try it out. ["Add New Words" and "Create a Madlib" were never added].

In Action: Rock Paper Scissors

The Rock, Paper, Scissors mentioned above application uses my AJAX-Lite functions with the function-chaining (to prevent racing conditions).

Sample function interfaces

"Testing Service" actions

The "Testing Service" for CTL, mentioned above, uses some functions that incorporate AJAX-Lite. They aren't particularly meaningful, but show it in action.

Image Test from above

The javascript written for the image toy above. Uses some basic regex, DOM, and string functions. Nothing terribly fancy.

Python

I'm was once a total n00b with Python. I admit it. But I do have a success story for it. I knew absolutely NOTHING about it before I took a Distributed Computing class (which assumed you were already proficient in it) -- I was able to learn Python well enough after only a few weeks to write a number of scripts, including this application: a text-based Tic-Tac-Toe game using socket connections.

Since then, I have played with the PyGame library and done some hobbyist coding. I am a bit more comfortable in it now, but it's still not a strong language just yet.

I had a similar experience with .NET at my current job. Never touched it before, but learned it to a proficient level in 2 weeks. I pick stuff up pretty quickly when I'm immersed in it. :)

Socket Connections / Interfacing

Tic-Tac-Toe App

Here it is! You can actually run it, if you have python loaded. Dont' expect anything fancy though -- unless you're a big fan of "Wargames".

XML-RPC Server

Q/A XML-RPC Server

This app is half of the Question / Answer server. It was another class project. The purpose was to design a server that would ask questions from a survey, prompt for answers, and record the results for analysis later. It uses the Pickle library.

Q/A XML-RPC Client

This is the client portion. If you're curious, the Survey itself is here, which derives from some code written by my instructor.