Skip to content

Instantly share code, notes, and snippets.

View lambda-fairy's full-sized avatar

Chris Wong lambda-fairy

View GitHub Profile
@lambda-fairy
lambda-fairy / Names.hs
Created July 25, 2013 01:55
Python identifier generator
module Names (renderName) where
import Data.List (genericIndex)
-- | Map a non-negative integer to a valid Python identifier.
renderName :: Integer -> String
renderName
= ('_':) -- Prevent conflict with Python keywords
. map (genericIndex chars)
. digitify (fromIntegral $ length chars)
@lambda-fairy
lambda-fairy / .bashrc
Last active December 20, 2015 14:09
My .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# Include the default .bashrc
. /etc/skel/.bashrc
# Don't save command history on the VM
if [ "$(hostname)" == 'bonbon' ]; then
unset HISTFILE
@lambda-fairy
lambda-fairy / api.txt
Last active December 20, 2015 22:18
Sparkle API
GET /project
200 OK
{
"revision": revision,
"tasks": [
{
"title": string,
"completed": boolean,
"children": [ .. ]
@lambda-fairy
lambda-fairy / Comb.hs
Created August 12, 2013 06:19
Simple parser combinator library
-- | A simple parser combinator library.
module Text.Comb
( Parser(runParser)
, parse
, next
, satisfy
, match
, matches
) where
@lambda-fairy
lambda-fairy / boygirl.py
Created August 14, 2013 03:38
Monte Carlo simulation of "Boy or Girl" paradox
#!/usr/bin/env python3
"""
I go around, knocking on people's doors, until I find someone with two
children, at least one of which is a boy.
What is the probability that they are both boys?
(The answer should approximate 1/3.)
@lambda-fairy
lambda-fairy / counter.py
Last active December 21, 2015 10:18
Count the number of comparisons performed by a program
"""
A simple mixin that counts the number of comparisons performed. Each
class it is mixed into keeps its own counter, which can be retrieved and
reset at whim. The code is written generically, and will work with any
orderable type.
In the COSC122 (first year computer science) course at the University of
Canterbury, one of the assignments is to implement a binary search. To
verify the algorithm, students have to manually increment a counter
every time they compare two values. This is annoying and error-prone,
@lambda-fairy
lambda-fairy / fix.py
Created September 21, 2013 05:54
Fun with fix-point combinators
#!/usr/bin/env python3
from functools import wraps
def fix(f):
@wraps(f)
def inner(*args, **kwds):
return f(fix(f), *args, **kwds)
return inner
@lambda-fairy
lambda-fairy / fuzzy-checkboxes.js
Created September 24, 2013 07:30
Fuzzy checkboxes
jQuery.fn.extend({
fuzzyCheckboxes: function (selector) {
this.on('click', selector, function () {
$(this).find(':checkbox').click()
})
this.on('click', selector + ' :checkbox', function (e) {
e.stopPropagation()
})
}
})
@lambda-fairy
lambda-fairy / Sleepsort.hs
Created October 23, 2013 03:20
Sleep sort, in Haskell
module Sleepsort (sleepsort) where
import Control.Applicative
import Control.Concurrent
import Control.Monad
import System.IO.Unsafe (unsafeInterleaveIO)
sleepsort :: [Int] -> IO [Int]
sleepsort xs = do
ronald <- newChan
@lambda-fairy
lambda-fairy / isms.markdown
Last active December 26, 2015 09:39
Epic one-liners

That's hotter than an iron refinery.

Your reasoning is tighter than a whore on her first night.

Sexy, sexy non sequitur.

If a crystal grows to exactly 1609.344 meters in length... is it a milestone?

You shoot yourself in the foot, but the compiler notices you're already dead inside and optimizes it away.