Welcome to Barricane.

We hope you will find what you are looking for.

A MySQL query to find the last matching row(s).

After having to reinvent this query three times, I'm actually blogging it this time. It always seems obvious afterwards, but takes me about half and hour to write fron scratch.

Here's a table:

CREATE TABLE foo (
    id INT(10) NOT NULL AUTO_INCREMENT,
    uid INT(10) NOT NULL,
    value VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `uid` (`uid`)
)

containing:

id, uid, value
 1,   1, hello
 2,   2, cheese
 3,   2, pickle
 4,   1, world

The data represents two objects (uids 1 and 2) which go through a couple of values. (Google 'event sourcing' and 'CQRS' for more info.)

I want to make a view of the 'latest' values of each uid, to simplify querying.

It can be done with:

select id, uid, value 
from foo as a
where a.id = (select max(id) from foo where uid = a.uid group by uid)
;

The above query produces:

id, uid, value
 3,   2, pickle
 4,   1, world

There is bound to be a more efficient way to do this, so I'll ask on StackOverflow...

Posted on 08 February 2012.

how to generate an openssl certificate for https

I always forget how to create an openssl certificate, so here it is:

openssl genrsa -out privatekey.pem 1024 
openssl req -new -key privatekey.pem -out certrequest.csr 
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
Posted on 24 November 2011.

Google V8 to annotate source with Closure JSDoc Type Expressions

I would a like a new tool to help with Javascript development, both in NodeJS and (possibly) on the browser.

What I want is to be able to run (and/or unit test) a NodeJS app (on the built-in V8). As an extra output I would like a transformed version of the source, annotated with Google Closure JSDoc Type Expressions.

I can't see any technical reason why this would not be possible.

Who will write this? It's probably a few weeks of fulltime work, or more if you don't already know the innards of V8.

Why would it be useful?

  1. It allows the flexibility of untyped development, without the maintenance burden.
  2. A developer will quickly spot any unexpected types, leading to bug fixes.

Please Google, Joyent, or Anyone Else, can you write this for us?

Thanks,

Chris.

Posted on 06 October 2011.

Ludum Dare entry, but I'll take a year to write it.

I'm going to participate the the Ludum Dare October Challenge. Unfortunately I have just 3 hours per week for game development. I don't think there's any chance of meeting the end of the month (12 hours dev), so I'm giving myself a year (150 hours).

The game will be called Anastom, pronounced anAStom, as I have the domain and am not currently using it for anything.

It has the following design constraints:

  • It must be fun.
  • It must be playable within two seconds of typing www.anastom.com
  • It must work in 80% of browsers (no WebGL, but 2D Canvas OK).
  • It must be massively multiplayer.

I have the following ideas:

  • Visibility like Roguelikes.
  • 2D side scrolling platformer, but not 'twitchy'.
  • Puzzles, like Castle Quest (BBC Micro).
  • Solo Instances for some areas, and Group Instances for others.
  • Mixture of Randomly Generated Maps and Set Pieces.
  • Old-school pixellated graphics, maybe 3x or 4x upscaled. (Quicker to design.)

Platform:

  • Client: JavaScript, with Canvas and Socket.IO.
  • Server: NodeJS (JavaScript) with Socket.IO and MySQL.

I'll blog on progress each and every Friday, to keep my motivation up.

Lets see how I do...

Posted on 30 September 2011.

The D Language is Really Practical.

I'd like to take a minute to thank Walter Bright for creating the D programming language.

I had a project, which I had previously written in Python, but which I now needed to port to a more runtime-efficient langauge (a single static executable and obfuscated source are also a bonus for a commercial product).

The standard library (for D 2.0) had all the file a directory manipulation functions I needed, easily as rich as Python and an awful lot easier to use than APR or POSIX.

I had initally attempted the port using C and the Apache Portable Runtime, but I found it hard work after years of Python and Javascript. I quickly got bogged down in memory pools, string handling and shared state.

I decided to give D a try:

  • Running D programs as scripts is as easy as adding '#!/usr/bin/dmd -run' to the top of the source file. This alson must have saved me a few hours.
  • String handling is sane, as is just about everything else in the langauge.
  • Concurrency is well thought out.
  • They've produced a 64 bit compiler, since I last looked a year ago.

There are a couple of issues:

  • I'm still trying to find a Debian Packaging or Autotools Howto for D.
  • You may start to dislike writing C/C++.

Basically, if your now mostly a script programmer and think you need to do go back to C for some lower level work, give D a try.

Posted on 06 September 2011.