Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
shaunlebron / hourglass.py
Last active September 29, 2015 03:37
Measuring arbitrary times using arbitrary hourglasses
def print_target_moves(aTimeCapacity, bTimeCapacity, targetTime):
'''
Given two hourglasses with respective time capacities,
print out a process for measuring the given target time
without going over that time.
An hour glass can only be flipped when any of them have run out.
TODO: generalize to multiple hour-glasses
'''
moves = []
@shaunlebron
shaunlebron / river.lp
Created March 27, 2012 23:31
Carcassonne Contiguous River Generator
% the tile width of the rectangular map
#const width=4.
positions(0..11).
rotations(0..3).
% piece(number, side, side type [g=grass, w=water, c=city, r=road]).
piece( 1,0,g ;; 1,1,g ;; 1,2,g ;; 1,3,w).
piece( 2,0,g ;; 2,1,g ;; 2,2,g ;; 2,3,w).
piece( 3,0,g ;; 3,1,w ;; 3,2,g ;; 3,3,w).
@shaunlebron
shaunlebron / ConvertTableToTree.py
Created October 31, 2012 17:07
How readable is this?
entries = getListOfTableEntriesSomeWhere()
entryTree = MyTree(entries)
################################
def group_entries(groupclass, entries, keyfunc):
return [groupclass(k,g) for k,g in itertools.groupby(entries,keyfunc)]
key_sys = lambda x: x.sys
key_subsys = lambda x: x.subsys
@shaunlebron
shaunlebron / test.clj
Created November 12, 2015 06:21
paren mode shift case
(def foo| (bar
baz))
(define (make-link x)
  `(a [[href "#top"] [class "internal"]]
      ,(splice x)))
@shaunlebron
shaunlebron / parinfer-benchmarks
Created December 24, 2015 22:43
current parinfer benchmarks
$ node test/perf.js
Testing file with 2865 lines
indent: 62.065ms
paren: 52.131ms
$ /usr/sbin/system_profiler SPHardwareDataType
Hardware Overview:
Model Name: MacBook Pro
@shaunlebron
shaunlebron / gfm-bug-example.md
Last active December 24, 2015 23:49
A GFM bug - displaying code after a list
  • item 1

  • item 2

  • item 3

    // code here

should be equivalent to...

  • item 1
if [ ! -f .classpath ]; then
classpath=`boot show -c | tee .classpath`
else
classpath=`cat .classpath`
fi
planck -c $classpath ...
(ns sitegen.markdown
(:require
[clojure.string :as string]
[planck.core :refer [file-seq slurp]]
[clojure.walk :refer [keywordize-keys]]))
(def ^:dynamic *filename*)
(defn error [msg]
(throw (str "markdown metadata error: " msg " - " *filename*)))
(ns sitegen.markdown
(:require
[clojure.string :as string]
[planck.core :refer [file-seq slurp]]
[clojure.walk :refer [keywordize-keys]]
[cljs.pprint :refer [pprint]]))
(def ^:dynamic *filename*)
(defn error [msg]
(throw (str "markdown metadata error: " msg " - " *filename*)))