MyOath – MySQL Promises for Node

I have mixed feelings about ORMs, and prefer to err on the side of the more lightweight solution when I’m not sure which tool will be most appropriate to the problem I’m trying to solve. I recently found myself re-inventing the CRUD wheel once again for a node app I’m writing, and tried to find a library with a little more abstraction than the basic MySQL library without going full ORM – but turned up nothing that was appealing.

Over the last few months I’ve really embraced the promises pattern in my JavaScript, and I wanted something that would let me execute SQL queries asynchronously with promises. I also wanted something that would be DRY for the REST API’s I’m often writing.

I have to say that I’m pretty happy with the result. I’ve been using the Q Promise Library, but I’ve heard good things about some other libraries so I wrote this to support a range of promise libraries so that you can use your preferred library natively with this library. Its methods return promises so they can be easily chained with other promises. The library exposes methods which correspond to HTTP methods for GET, POST, PUT and DELETE so that you can spend more time on your app instead of writing yet another set of CRUD methods.

You can find the docs on the project’s github page. I’d appreciate all constructive feedback whether it is positive or negative.


Slim RedBeanPHP and Knockout

Last night I gave a talk about building websites with Knockout.JS, which I’ve been happily using for a long time.  I demonstrated using Slim as an application framework, and RedBeanPHP as an ORM on the back-end. I’ve used Slim on a few projects in the past, but this was my first time playing with RedBeanPHP. I’m looking forward to learning more about this cool little ORM.

The main message of the talk was that choosing simple frameworks can mean writing and maintaining less code, and can help to overcome obstacles to adopting TDD.

At the same time, I’m a big fan of Angular, Symfony and Doctrine.  For projects that can benefit from those more elaborate architectures they should be used. For smaller projects, or to make getting traction with TDD easier you should consider smaller frameworks like those touched on here.

If I were doing this talk again I would break it into three parts to that I could spend more time on each library, and on the unit testing. I was barely able to finish in an hour and a half, and I feel terrible for putting the group through such a long and code-heavy talk (again).

The slides are posted on slideshare, and the code is posted on github.

The Intense Role Playing Game

Today I released a very simple role-playing game which I developed for use at Scout camps. It is ideal for playing around a camp fire, but works just fine around a table too. The rule book is only 12 pages long, and only 2 of them are really about the rules. Most of it is help for the person who’s running the game such as story ideas.

I hope that it will be approachable by non-nerds since the rules are so simple. I’ve only played it with youth aged about 10 – 14 but I expect adults would have fun with it too.

Check it out at

MeteorJS: First Impressions

I saw some buzz today about Meteor, a new set of technologies for building JavaScript applications which blurs the lines between server code and client code.  I’ve had a notion like this bouncing around in my head for the last year or so, and so I was keen to jump in and try it.  I watched the screencast, installed the app, and installed the leaderboard example.  The installation went flawlessly, and I was able to start the example app and bring it up in my browser without any trouble.  I was off to a great start!

Read more…

SOLID PHP & Code Smell Wrap-Up

Here are the slides from the SOLID wrap-up I presented at GTA-PHP last night (Google DocsPPTX, PDF).  I’ve also made a gist for the LSP example referenced on slide 8 that I couldn’t find at the time.  I covered the Liskov Substitution Principal (LSP), the Dependency Inversion Principal (DIP) and the Interface Segregation Principal (ISP) in PHP.  I’ve covered SRP and OCP in earlier posts.  I mentioned that I wasn’t particularly fond of applying the ISP in PHP, and Ilia Alshanetsky pointed out that PHP’s performance can suffer if you use too many small interfaces in your PHP.  We discussed the notion of putting constructors in interfaces, and Guilherme Blanco pointed out that since you can’t instantiate an interface an abstract class would be a more appropriate way to require a specific constructor.  Peter Meth and Dan (sorry Dan, I don’t know your last name!) asked where to find a good summary of the SOLID principals, and I suggested the Wikipedia entry, which has a nice table for jogging your memory on the acronym’s meaning.  Thanks to everyone who showed up!

JS301 Week 4: Knockout and Objects

This week we will look at how to use knockout.js to keep our in-memory models and user interface in sync, and we’ll look at how objects are used in JavaScript.  We’ll finish up with some suggestions on how you might continue to expand your JavaScript horizons.  The slides are available online and for download (pptpdf).  Update: I’ve had stability problems with today, so just in case here’s the source for the OO examples.  The knockout examples are from their web site, so we’re safe there.

JS301 Week 3: Practical JavaScript

This week we’ll look at some real world examples of how you can use JavaScript to enhance your web pages.  There aren’t a whole lot of slides, but I think it’ll take a while to get through the examples and understand them.  If we have extra time we can play with Knockout.js too.  You can view the slides online or download the PDF or PPT.