Skip to content

Instantly share code, notes, and snippets.

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 Aug 29, 2015
Ember.js: simple regexp-based validation component
View jsbin.tenig.css
* {
box-sizing: border-box;
}
form {
padding: 10px;
max-width: 400px;
}
.input {
margin: 0 0 10px 0;
position: relative;
View gist:164884992979c8ac8361
// 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 Jun 7, 2011
String#unpack format string width
View format-width.rb
# 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 Oct 24, 2011
Auto-generated .gitignore
View gist:1309200
.gitignore: Makefile
echo $(TARGETS) $(OBJS) | xargs -n 1 > .gitignore
@alisdair
alisdair / serial.c
Created Nov 4, 2011
RCB128RFA1 & RCB_BB UART serial echo client
View serial.c
#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
View roku.html
<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 Nov 25, 2011
logger_assert: macro to die when an expression is false, printing the function name, expression, file, and line
View logger.h
#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 Dec 14, 2015
Tom Moertel's tree traversal ported from Haskell to Coffeescript.
View traversal.coffee
# 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 Dec 14, 2015
hubot script to tell people to make coffee for me
View rota.coffee
# 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 Apr 17, 2016
Test stub for component -> helper -> service
View components.spotify-song.js
import Ember from 'ember';
export default Ember.Component.extend({
});