Keith Gaughan

An attempt at public introspection

Coding

Picking up Lua again

· 3min

I recently resurrected my old original Raspberry Pi B+ and installed NetBSD on it. Currently, it’s acting as a bastion for my local network, but I’ve been thinking of other projects I could do with it. One of those is to build something like Pi-Hole with it, as …

Coding

Creating AWS Lambda functions in Python with dependencies

· 1min

This assumes you have a package called mylambda and a requirements.txt file listing your dependencies.

build.sh:

#!/bin/sh

tmp_dir=$(mktemp -d)
trap "rm -rf '$tmp_dir'" EXIT

pip install -r requirements.txt -t "$tmp_dir"
cp -R mylambda "$tmp_dir/mylambda"

here=$(pwd)
(
    cd $tmp_dir
    zip -r -9 $here/lambda.zip …
Coding

Custom attribute values in Django form field widgets

· 1min

This has frustrated me for so long.

If you want to use checkboxes in a form in Django, the obvious choice is BooleanField. There are times it would be really useful to have the value attribute filled out, but by default, Django just checks for the presence of the field …

Coding

What monads are

· 2min

It’s almost like a rite of passage for a developer to write a monad tutorial.

Well, this isn’t a monad tutorial. This is simply an effort to put an end to some of the nonsense that leads to monad tutorials being written in the first place and all …

Coding

How I use git

· 3min

My git workflow for anything non-trivial is pretty straightforward, but a little different from what I’ve seen others describe. I’m almost certainly not the only person out there who uses this workflow, so I’m certainly not claiming any originality.

There seem to be two camps, both based …

Coding

type() vs. isinstance() in Python

· 1min

One elementary error people make is using the type() function where isinstance() would be more appropriate1.

If you’re checking to see if an object has a certain type, you want isinstance() as it checks to see if the object passed in the first argument is of the type …

Coding

Scoping and use of the ‘global’ keyword in Python

· 3min

[Here’s something I knocked up for one of my co-workers who’s an experienced developer, but a Python neophyte. It may be useful to others.]

As in PHP, the global keyword in Python declares that any reference to a given variable name within the scope of a function or …

Coding

Minesweeper Kata

· 2min

I did the minesweeper kata a few days back. It was a bit too easy, though it’s quite possible that this is more an artifact of how I approached it. Given that it’s a simple one, it might be an idea to see if I can take it …

Coding

Harry Potter Kata

· 4min

I did the Harry Potter Kata earlier because I was feeling a little bored. Here’s the result. I use cents rather than euros as my unit of currency here.

I’d a start when I was thinking about how I’d solve the problem. I thought that being greedy …

Coding

Quick hacks: Python netstring reader

· 2min

I’m writing a proof-of-concept server for a less jokey version of the SRGP. The protocol is more or less SRGP, but it doesn’t use MIME-style headers each request is made up of a series of netstrings. The header and body sections are terminated with empty netstrings, i …

Coding

A reasonable XML RPC envelope protocol, and asynchronous calls

· 11min

Note

This is juvenile, but it’s still better than XML-RPC. Here is the original post.

Sometimes something you do as a joke can yield interesting results.

About a year or so ago, I was feeling bored and decided to see how much of a diet I could put …

Coding

Messing with Standard ML and Moscow ML, part one: The core language

· 8min

Note

A cache of the original post is here.

I was playing with Moscow ML because I’ve wanted to give Standard ML a bash for a while now, but I could never get SML/NJ to play nice for me back when I tried it first on Windows. That …

Coding

Formkeys

· 2min

Formkeys are something I first discovered when snooping around the source for Slashcode many, many moons ago. The idea is to embed a hidden field in a form that can be later used to check if a form has been submitted twice, or if somebody’s attempting to use it …

Coding

How Syncope Works

· 4min

[Note from 2020: Syncope eventually ended up as AFK]

Here’s how Syncope, the kinda-but-not-really-a-framework I mentioned before, works. It’s really just a library with a bunch of canned request lifecycles. Those are the only parts of it that vaguely resemble a framework. It’s made to be as …

Coding

XP and Big Design Upfront

· 1min

Joel Spolsky posted on his site about several instances where where he needed to modify the Project Aardvark (Copilot) Functional Specification.

It was all fine, and stuff I agree with myself, up until close to the end where he wrote:

I can’t tell you how strongly I believe in …

Coding

A Java HTML Scrubber

· 2min

In preparation for possibly adding a WYSIWYG editor to the site—mainly because people don’t seem to read the formatting instructions—I’ve written the best part of a HTML scrubber to ensure that the HTML markup returned from the poster’s browser doesn’t contain anything dodgy and …

Coding

Demystifying the GridBagLayout Layout Manager by Peter Haggar

· 1min

This is an excellent explaination about what must be one of the most puzzling parts of AWT/Swing development: the GridBagLayout layout manager.

The original was an MS Word file. I converted it to LaTeX for my own use, but I think others might find it useful too. I redid …

Coding

Memoization in JavaScript

· 2min

About a fortnight ago, I was poking around the copy of Perl sitting on my laptop. I came across Memoize.pm. Having read the article that inspired it a few years back, I thought I’d take an attempt at implementing something to do the same in JavaScript.

Memoization is …

Coding

The World’s Simplest (decent) PHP Templating Engine…

· 1min

…is PHP, so why not use it?

function include_view($view, $vars=null) {
    # Start buffering the generated text.
    ob_start();

    # Process the view.
    if (!is_null($vars)) {
        extract($vars, EXTR_OVERWRITE | EXTR_REFS);
    }
    include("views/$view.php");

    # Grab the generated content and clean up.
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
Coding

My C++ wrapper for the Expat XML parser

· 1min

Last year when I was writing Orpheus, I knocked out a C++ wrapper around Expat to make using it easier.

It consists of two classes. XMLParser is the Expat wrapper and sets up the event handlers and automates setup and teardown of the parser itself. XMLEvtHandler consists of a set …

continue   →