Skip to content

Instantly share code, notes, and snippets.

View wolever's full-sized avatar

David Wolever wolever

View GitHub Profile
#!/bin/bash
set -e
function must_have_var() {
eval VAL=\$$1
if [[ "$VAL" == "" ]]
then
echo "$1 must be set."
exit 1;
-module(trie).
-export([new/0, add/2, step/2, from_dict/0, at_word/1]).
setdefault(Key, Default, Dict) ->
case dict:find(Key, Dict) of
{ ok, Value } ->
{ Dict, Value };
error ->
{ dict:store(Key, Default, Dict), Default }
end.
# ====
# NOTE
# ====
# This may be out of date; see the comments below.
# Arduino 0017 Makefile
# Arduino adaptation by mellis, eighthave, oli.keller,
# alex norman [with help from http://code.google.com/p/arduino/issues/detail?id=65#c5]
# Version 0017/Mac modifications made by
# David Wolever
function rmext () {
find . -name "*.$1" | head
echo "Remove all .$1 files?"
read RESP
[[ "$RESP" =~ [nN] ]] && { echo "Abort."; return 1; }
find . -name "*.$1" -delete
}
// Accepts a bunch of lines then strips, from every line, the shortest prefix
// that is entirely whitespace and creates a 2D array.
// Find the smallest amount of whitespace before any line...
var minWhitespace:int = min(map(function(line:String):int {
return line.replace(/^([ \t]*).*/, "$1").length;
}, str.split("\n")));
// ... then strip it off and return an array of single characters.
var grid:Array = map(function(line:String):Array {
/**
* Return the cartesian product of ...iterables.
* cartesian_product([1, 2]) => [ [1], [2] ]
* cartesian_product([1, 2], ["a", "b"]) => [ [1, "a"], [1, "b"], ... ]
*/
public function cartesian_product(...iterables):Array {
if (iterables.length == 1) {
return map(function (item:*):Array {
return [item];
}, iterables[0]);
# Based on http://www.djangosnippets.org/snippets/85/
from django.conf import settings
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, get_host
def is_insecure(request):
return not request.is_secure()
class UseHttpsMiddleware:
def process_request(self, request):
// ActionScript is stupid. It's no secret. But, to maintain my own sanity, I need to rant about it… So I'll
// do that here.
// First, interfaces.
// I know, I know… It's not vert sporting to point out flaws in AS interfaces… But they consistently
// make me mad, so I'm going to do it anyway.
// First, type checking of the implementation.
// I think it's done by string comparison instead of, you know, the right way.
// Take this interface, for example: