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 / jsbin.tenig.css
Last active August 29, 2015 13:56
Ember.js: simple regexp-based validation component
* {
box-sizing: border-box;
}
form {
padding: 10px;
max-width: 400px;
}
.input {
margin: 0 0 10px 0;
position: relative;
// Generates a function which returns a random element of xs, where the same
// input value always returns the same element.
//
// Useful in situations like test data factories, where you want to choose a
// random element from a list of fake test data, but the same input integer
// should return the same value every time.
export default function(xs) {
var memo = {};
return function (i) {
@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)
@alisdair
alisdair / gist:1309200
Created October 24, 2011 14:46
Auto-generated .gitignore
.gitignore: Makefile
echo $(TARGETS) $(OBJS) | xargs -n 1 > .gitignore
@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 / 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 / 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 / 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 / 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 / components.spotify-song.js
Created April 17, 2016 15:44
Test stub for component -> helper -> service
import Ember from 'ember';
export default Ember.Component.extend({
});