Tag Archives: programming

Wanted: Simple 2D Game Framework

ab_dI want to write a simple kid’s game. It would show something like “A B _ D”, then speak “What letter is missing?”. If you hit the “c” key, it would say “Congratulations!”. If you hit any other key, “Try again!”.

Anyone have pointers on game-creation frameworks? I’m looking for something cross-platform and very high-level. I want to be able to write and play the game in a few hours max.

These look hopeful: ScratchLÖVE, RacketAlice, Pygame.

I want this crawl version to be as simple as possible. Eventually I might want to add score tracking and animations.

I could also create a web-based game that would work, say, in a web browser on an iPad, but this smells a bit more complex than I’m hoping for right now.

Here are a couple other related links I came across while poking around:

List largest MongoDB collections

I wanted to know the top five largest collections in my MongoDB database in terms of document count. This JavaScript gets the job done.

// config
var dbname = 'dev_bv';
var measure = 'count'; // or 'size'
var numTopCollections = 5;
function updateTopCollections(collection, stats, topCollections) {
    var thisCollectionObj = {
        'name' : collection,
        'count' : stats.count,
        'size' : stats.size
    for(var i = 0; i < topCollections.length; i++){
        if (stats[measure] > topCollections[i][measure]) {
            topCollections.splice(i, 0, thisCollectionObj);
    if (topCollections.length < numTopCollections) {
    if (topCollections.length > numTopCollections) {
db = db.getSiblingDB(dbname);
var collections = db.getCollectionNames();
var topCollections = [];
for(var i = 0; i < collections.length; i++){
    if (collections[i].match(/^system/)) {
    var stats = eval('db.' + collections[i] + '.stats()');
    updateTopCollections(collections[i], stats, topCollections);
printjson (topCollections);

Save it to a file, edit variables in the config section, and execute like so:

mongo --quiet topCollections.js

Here’s a gist of same: https://gist.github.com/4150940

Wanted: fair curated tweet list

I think I like Twitter. I’m getting to like it, anyway. One problem I have with it is what appears to be an overwhelming emphasis on timely and copious posting.

I often miss tweets from my VIPs (friends, family), especially those who post infrequently. I want something that shows me the last few tweets for a list of people I specify.

Twitter’s “lists” feature comes close to this goal, but (like every other Twitter client I’ve seen) it shows every tweet and the most recent first, so infrequent tweeters are still penalized.

What would really unlock this problem for me is if there existed a REST API to pull a few tweets from several users at once. Anyone know if such a thing exists?

I’m also interested to know if there’s an extant client that does what I’m describing. I wouldn’t mind not coding this.

UPDATE (30 minutes later):

I cobbled something together that basically does what I want. I only slightly modified Kevin Liew’s dead-simple jQuery-based example to make my app. I just factored out the user parameter to JQTWEET.loadTweets() and now call it multiple times, once per VIP. Even with a list of 50 VIPs I can run this less than once per hour and still avoid rate limits.

UPDATE (2012-09-27):

Another idea, no coding required: subscribe to the RSS feeds for each VIP in your favorite feed reader.

Link Checker Wishlist

Link checkers spider through your website and make sure that links work. I want an awesome link checker. Ideally, it would espouse as many of these attributes as possible:

  • easy to learn
  • easy to configure/customize
    • example config: don’t hit URLs on other servers
  • sensible default behaviors
    • example: respects robots.txt and ‘nofollow’ link attributes
  • scriptable / embeddable
    • useful from command line
    • useful from within CI servers like Jenkins
  • recurses (parses HTML, follows links)
    • and smartly avoids checking the same pages twice
  • fast
  • thrifty with memory
  • pluggable
    • example plugin: run jslint on all JavaScript
    • example plugin: validate HTML 5
    • example plugin: validate CSS
    • example plugin: compute accessibility score
    • example plugin: JUnit XML output
    • example plugin: OpenDocument spreadsheet output
    • example plugin: Excel output
    • example plugin: CSV output
    • example plugin: JavaScript engine
    • example plugin: follow hashbang URLs
  • beautiful source code

offline HTML 5 validation

HTML 5 logo

I’m liking Henri Sivonen’s Validator.nu service. I’ve got it running locally, and it works well. I can use it as a web service and validate HTML from within Vim, using quickfix to rapidly resolve errors. My Jenkins CI server uses the same validator via phpunit tests.

Warning: it took me a very long time to get it running locally. Technically easy (just run a build script), but it downloads tons of libraries and files before it can do its job.

Debugging web tests on remote servers

I run “web tests” on a remote server. I use Selenium to act like a person interacting with a website, viewing and entering data. Selenium is pretty awesome, it can drive a real web browser like Firefox.

Even better is to have these web tests run automatically every time I commit code. I use Jenkins for this. Jenkins even fires up a headless desktop so Selenium can run Firefox.

When a web test breaks (especially in some way I can’t reproduce on my local desktop), sometimes it helps to actually see what Jenkins sees as it runs the test. Here’s a quick guide for doing so on an Ubuntu GNU/Linux server.

  1. Connect to the remote server using SSH. Install VNC server:
    sudo apt-get install vnc4-server
  2. On the remote server, become the user tests run as. For example:
    sudo su - ci
  3. Set a password for the VNC server using the vncpasswd command.
  4. Start headless X server by running vncserver. Note the given display. If example.com:1 is included in the output of vncserver, the display is :1.
  5. Figure out which port the VNC server is using. I usually do something like

    sudo netstat -nape | grep '^tcp.*LISTEN.*vnc.*'

    Here’s some example output:

    tcp        0      0  *               LISTEN      107        3099855     13233/Xvnc4     
    tcp6       0      0 :::5901                 :::*                    LISTEN      107        3099858     13233/Xvnc4

    By trial and error, I figured out that 5901 was the port I should use.

  6. Port-forward VNC to your local machine.

    1. Disconnect from the server.
    2. Reconnect, including -L10000:localhost:5901 on your SSH command line.
    3. Leave this connection open.
  7. On your local machine, connect a VNC client to localhost:10000. An X terminal should be displayed.

  8. In the X terminal, run your web tests.

  9. When finished debugging, kill the X server using the display noted earlier.
    vncserver -kill :1

simple AJAX/JSP example: sum of two numbers

It’s been a while since I’ve done any front-end Web programming, so when Eva proposed a friendly challenge to quickly create a simple AJAX calculator, I gladly accepted. It took her about 20 minutes on an ASP.NET stack, and took me… *cough* …a couple of hours using JSP.

The challenge was fun because I played with and gained respect for JQuery and the Eclipse WTP. I think it took me longer than Eva because I first looked for tiny AJAX examples in Ruby on Rails and Django. After a couple of aborted attempts, I decided to use JSP after finding this nice example.

I’m sharing my result since I wasn’t able to find one quite as succinct. You can throw the war file in a Tomcat “webapps” directory or import it into Eclipse (ideally the Java EE version with WTP) to hack it. The WTP even has a nifty HTML WYSIWYG design view.