Skip to content

Instantly share code, notes, and snippets.

var titan = titan || {}
//===----------------------------------------------------------------------===//
// Data
//===----------------------------------------------------------------------===//
titan.tiles = [
{ name: 'grass' },
];
import Control.Arrow
import Control.Monad
import Control.Monad.Random
import Data.List
import Data.Map
import Data.Maybe
-- A monad which represents a random integer from 1-6
die :: (RandomGen g) => Rand g Int
die = getRandomR (1,6)
DEPS=$(cat urls.txt | grep -o "\w\+\.\w\+$")
redo-ifchange $DEPS
@jb55
jb55 / parseCsv.fs
Created April 1, 2011 01:38
Rock solid csv parser
open FParsec.Primitives
open FParsec.CharParsers
type CsvResult = { IsSuccess : bool; ErrorMsg : string; Result : string list list }
// Some simple helpers
let isWs s = Seq.map (isAnyOf "\t ") s
|> Seq.reduce (&&)
let ws = spaces
@jb55
jb55 / gist:945731
Created April 28, 2011 03:13
replace nginx with connect
var connect = require('connect')
, proxy = require('http-proxy')
function redirect(loc) {
return connect.createServer(function(req, res){
res.writeHead(301, { "Location": loc });
res.end();
});
}
@jb55
jb55 / gist:960155
Created May 7, 2011 02:56
minecraft stuff
{EventEmitter} = require 'events'
mmap = require 'mmap'
path = require 'path'
fs = require 'fs'
# Used for accessing blocks
class Blocks
@chunks = {}
# Blocks takes a path to a world directory.
@jb55
jb55 / test.coffee
Created May 8, 2011 16:02
vows coffee
vows.describe('binary-simple').addBatch
'a number':
topic: new Buffer [0x74, 0x01, 0x00, 0x01]
'with a big endian byte order':
'parses correctly': (buf) ->
res = binary.be buf, 3
assert.equal res, 7602432
'parses correctly with offset': (buf) ->
res = binary.be buf, 2, 1
assert.equal res, 256
derp = do
x <- [1,2,3]
y <- [x, x + 1, x + 2]
return y
derp2 :: [Int]
derp2 = concatMap (\x -> [x, x + 1, x + 2]) [1,2,3]
-- derp == derp2
import Control.Monad
import Test.QuickCheck
import Test.QuickCheck.Gen
import System.Random
import System
data Serial = Serial String Int
instance Show Serial where
show (Serial prefix number) = prefix ++ show number
@jb55
jb55 / Error.hs
Created July 26, 2011 13:58
Handy error handling combinators
data Error = Timeout
| Exception SomeException