Skip to content

Instantly share code, notes, and snippets.

View apg's full-sized avatar
🐢
Turtle

Andrew Gwozdziewycz apg

🐢
Turtle
View GitHub Profile
@apg
apg / haiku.el
Created June 3, 2011 14:33
Test if something is a haiku in elisp -- did I post this before?
(require 'cl)
(defconst count-syllables-negative
'("cial" "tia" "cius" "cious" "giu" "ion" "iou" "sia$" ".ely$"))
(defconst count-syllables-positive
'("ia" "riet" "dien" "iu" "io" "li"
"[aeiouym]bl$"
"[aeiou]\\{3\\}"
"^mc"
@mattpodwysocki
mattpodwysocki / jsconf-eu-2011.md
Created October 1, 2011 13:40
JSConf.EU Slides
@fogus
fogus / gist:1377358
Created November 18, 2011 18:45 — forked from hugoduncan/gist:1377108
Alternate cache protocol
(ns pallet.cache.impl
"An implementation namespace for pallet.cache")
(defprotocol CacheProtocolImpl
"Cache implementation interface."
(lookup [cache e] [cache e default]
"Retrieve the value associated with `e` if it exists")
(has? [cache e]
"Checks if the cache contains a value associtaed with `e`"))
@evilpie
evilpie / disassembler.js
Created April 4, 2012 11:51
Disassembler for Notch's 'DCPU-16'
/* See: http://0x10c.com/doc/dcpu-16.txt */
function hex(n) {
return '0x' + n.toString(16);
}
function disassemble (code) {
var PC = 0;
var operand = function (bits) {
@jordanorelli
jordanorelli / request.go
Created May 7, 2012 19:34
regex router in go.
package core
import (
"net/http"
)
// the Request struct wraps the http.Request struct, providing a slice of
// strings representing the positional arguments found in a url pattern, and a
// map[string]string called kwargs representing the named parameters captured
// in url parsing.
;; (mcase subject-expr (pattern action) ...)
(defmacro mcase (subject &rest clauses)
`(funcall (mlambda ,@clauses) ,subject))
;; (mlambda (pattern action) ...)
(defmacro mlambda (&rest clauses)
(if (null clauses)
'(lambda (x) (match-error x))
(let ((subject (gensym)) (fail (gensym)))
`(lambda (,subject)
@idris
idris / github.sh
Created January 20, 2011 22:23
command-line utility that opens a browser to the given file/directory in GitHub.
#!/bin/bash
FILE=$1
if [ -d $FILE ]; then
DIR=$FILE
else
DIR=`dirname $FILE`
fi
function parse_git_branch {
@manuel
manuel / dyn-wind-commentary.scm
Created August 11, 2012 12:45
Commenting on Oleg's dyn-wind.scm
;; See http://okmij.org/ftp/continuations/implementations.html#dynamic-wind
;; and http://axisofeval.blogspot.com/2012/08/delimited-continuations-do-dynamic-wind.html
;; Slight trick here: use identity of yield-record-tag function as the actual tag
(define (yield-record-tag) yield-record-tag)
(define (make-yield-record v k)
(list yield-record-tag v k))
;; Yield simply aborts up to the generator's caller, delivering to it
;; the yielded value and the continuation for resuming after the call
@pachacamac
pachacamac / mrisc.rb
Created July 7, 2011 10:20
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1