Skip to content

Instantly share code, notes, and snippets.

View alisdair's full-sized avatar
🏋️‍♂️
I'm probably snatching right now

Alisdair McDiarmid alisdair

🏋️‍♂️
I'm probably snatching right now
View GitHub Profile
@alisdair
alisdair / rota.coffee
Last active December 14, 2015 16:39
hubot script to tell people to make coffee for me
# Description:
# Assigning jobs randomly to people with a role
#
# Commands:
# hubot request <role> - choose a random user with a role
# hubot rota <role> - show previous assignment counts
#
# Examples:
# hubot alisdair is a support technician
# hubot matthew is a support technician
@alisdair
alisdair / traversal.coffee
Last active December 14, 2015 13:18
Tom Moertel's tree traversal ported from Haskell to Coffeescript.
# Translation of Tom Moertel's tree traversal:
#
# http://blog.moertel.com/posts/2012-01-26-the-inner-beauty-of-tree-traversals.html
t0 = []
t1 = [1]
t3 = [2, [1], [3]]
preorder_traversal = (f, z, tree) ->
do go = (tree, z) ->
@alisdair
alisdair / invisible_proxy.rb
Created August 31, 2012 08:29
Invisible proxy example for Ruby
class FlatArray
instance_methods.each do |m|
undef_method(m) unless m =~ /(^__|^nil\?|^send$|^object_id$)/
end
def initialize(array)
@target = array
end
def respond_to?(symbol, include_priv=false)
@alisdair
alisdair / logger.h
Created November 25, 2011 11:29
logger_assert: macro to die when an expression is false, printing the function name, expression, file, and line
#define STR(x) #x
#define STRINGIFY(x) STR(x)
#define LINESTR STRINGIFY(__LINE__)
#define logger_assert(x) if (!(x)) logger_die("%s: assertion failed: " #x \
" (" __FILE__ ", line " LINESTR \
")", __func__)
@alisdair
alisdair / roku.html
Created November 21, 2011 17:19
Roku
<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="white" />
<meta name="apple-touch-fullscreen" content="yes" />
<title>roku</title>
<script src="roku.js" type="text/javascript"></script>
<style type="text/css">
html {
@alisdair
alisdair / tty.c
Created November 15, 2011 15:42
Code to open a TTY with POSIX API, raw mode
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@alisdair
alisdair / serial.c
Created November 4, 2011 14:57
RCB128RFA1 & RCB_BB UART serial echo client
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#define BAUD 9600
// doc8266: ATmega128RFA1 data sheet. Available at:
//
// http://www.atmel.com/dyn/resources/prod_documents/doc8266.pdf
@alisdair
alisdair / gist:1309200
Created October 24, 2011 14:46
Auto-generated .gitignore
.gitignore: Makefile
echo $(TARGETS) $(OBJS) | xargs -n 1 > .gitignore
@alisdair
alisdair / format-width.rb
Created June 7, 2011 10:45
String#unpack format string width
# http://www.ruby-doc.org/core/classes/String.html#M001112
#
# Calculate how many bytes String#unpack will read for a format string.
#
# Only guaranteed to work with the characters defined in classes, which are
# the sensible ones you should be using anyway. So there.
#
# Notably will not work with x, X, @, and so on.
def width(format)