Skip to content

Instantly share code, notes, and snippets.

View lukego's full-sized avatar

Luke Gorrie lukego

View GitHub Profile
@lukego
lukego / luke-basic.el
Created July 4, 2012 11:16
The minimal Emacs configuration that I carry around with me
;;; luke-basic.el -- my most basic Emacs configuration
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(setq sentence-end-double-space nil)
(setq diff-switches "-u")
(global-set-key [(control g)] (lambda () (interactive))) ; NOP
@lukego
lukego / gist:3799305
Created September 28, 2012 11:33
vmbuilder python error backtrace
root@arbon ~/vm # vmbuilder kvm ubuntu
Traceback (most recent call last):
File "/usr/bin/vmbuilder", line 24, in <module>
cli.main()
File "/usr/lib/python2.7/dist-packages/VMBuilder/contrib/cli.py", line 142, in main
hypervisor, distro = self.handle_args(optparser, args)
File "/usr/lib/python2.7/dist-packages/VMBuilder/contrib/cli.py", line 292, in handle_args
distro = VMBuilder.get_distro(args[1])()
File "/usr/lib/python2.7/dist-packages/VMBuilder/distro.py", line 75, in __init__
super(Distro, self).__init__()
@lukego
lukego / pbook in sed
Created October 24, 2012 13:10
Format program listings for Markdown
sed -E -e 's/^/ /g' -e 's/^ --- ?//g' | pandoc -o listing.pdf -
That expression is a cheap literate programming system for Markdown.
Start commentary lines with '--- ' and they will be
markdown-formatted, the rest will be code. (Uses Lua comment syntax.)
Finally the right implementation of this idea:
http://fresh.homeunix.net/~luke/misc/emacs/pbook.pdf (program)
http://fresh.homeunix.net/~luke/misc/erlang/regtest.pdf (better example)
@lukego
lukego / gist:3952159
Created October 25, 2012 11:46
Erlang literate programming
Simple literate programming.
Add comments to your Erlang file with a special %%% syntax, like this:
%%% This is a comment that will be formatted in a variable width font with Markdown.
%%% You can use *emphasis* and
%%% # Headings
%%% and even
%%%
%%% - Lists
@lukego
lukego / gist:4065602
Created November 13, 2012 12:49
Object oriented programming in Lua

Simple example of object-oriented programming in Lua. Objects are represented as tables so they are easy to invoke methods on, but their state is kept in a closure where it's convenient for methods to access.

Example of a simple stateful "counter" object with two methods:

module("counter", package.seeall)

function new (count)

@lukego
lukego / gist:4706097
Last active December 12, 2015 03:19
Table data structure that "garbage collects" not-recently-used items in O(1) time

I use this data structure all the time. Can someone leave a comment and tell me what it's called?

  1. insert(k,v): add a new value
  2. lookup(k): lookup an existing value
  3. age(): delete old entries (that have not been used since previous call to age())
# Initialize 'old' and 'new' to empty tables
local old, new = {}, {}
@lukego
lukego / gist:4706885
Last active December 12, 2015 03:28
Cute code (written in Forth)

Below is some cute code that I wrote for the OLPC Openfirmware HD Audio driver.

The firmware is allowed to hard-code knowledge of the physical design of the laptop and motherboard. This firmware code tells the audio chip explicit details such as the size and colour of each physical audio jack in the laptop. The operating system can later query the chip for this information and present it to a user, for example in an audio mixer application.

porta  config(  1/8" green left hp-out jack     )config
porta  config(  1/8" green left hp-out jack     )config
portb  config(  1/8" pink left mic-in jack      )config
portc  config(  builtin internal top mic-in no-detect other-analog )config
portd  config(  unused line-out no-detect       )config
@lukego
lukego / bug.sh
Created September 19, 2013 09:54
LuaJIT 2.1 object linking bug
#!/bin/bash
cat > main.c <<EOF
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int
@lukego
lukego / gist:6634948
Created September 20, 2013 08:59
LuaJIT bytecode module name (luajit -b -n newname ...) bug report.
#!/bin/bash
cat > main.c <<EOF
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int
@lukego
lukego / gist:8503881
Last active January 3, 2016 18:39
Setting up a roughdraft.io blog with my own URLs

roughdraft.io for blogging

I like the look of roughdraft.io for automatically rendering my Github Gists as a blog at http://lukego.roughdraft.io/.

I'd prefer to use my own name in the URLs though, so that links aren't permanently dependent on roughdraft.io. (There's a lot of churn in my blog infrastructure life, it seems.) I tried a little Apache config to make http://blog.lukego.com/6634948 display the content of http://lukego.roughdraft.io/6634948:

ProxyPassMatch ^(/[0-9]*)$ http://lukego.roughdraft.io$1