Skip to content

Instantly share code, notes, and snippets.

View weskerfoot's full-sized avatar

Wesley Kerfoot weskerfoot

View GitHub Profile
@weskerfoot
weskerfoot / 11.hs
Created May 5, 2013 00:05
Project Euler #11
import Data.List.Split
import Control.Applicative
import Control.Monad
rows :: String -> [[Double]]
rows xs = (map read) <$> splitOn " " <$> lines xs
columns :: [[Double]] -> [[Double]]
columns rs = map (map head) $
takeWhile (any (/= [])) $
@weskerfoot
weskerfoot / MPDParser.hs
Last active December 17, 2015 05:59
parser for the MPD database
{-# LANGUAGE NoMonomorphismRestriction, TupleSections, MonadComprehensions #-}
module MPDDatabase where
import Data.List
import qualified Database as D
import Control.Monad
import Text.ParserCombinators.Parsec
import Control.Applicative hiding ((<|>), optional)
data Directory = DirTerminal (String, String, [DContents]) deriving (Show)
@weskerfoot
weskerfoot / mpdparse.hs
Created May 15, 2013 22:49
Parses MPD database files
{-# LANGUAGE NoMonomorphismRestriction, TupleSections, MonadComprehensions #-}
module MPDDatabase where
import Data.List
import qualified Database as D
import Control.Monad
import Text.ParserCombinators.Parsec
import Control.Applicative hiding ((<|>), optional)
data Directory = DirTerminal (String, String, [DContents]) deriving (Show)
@weskerfoot
weskerfoot / disprob.rkt
Created June 13, 2013 05:23
Discrete Probability Distributions
#lang racket
(require unstable/list)
;; Helper functions
(define (on f g)
(λ (x y) (f (g x) (g y))))
(define/contract ((<$> f) pair)
(-> (-> any/c any/c) (-> pair? pair?))
<?php
function compose($f, $g) {
return function() use($f, $g) {
$args = func_get_args();
return $f(call_user_func_array($g, $args));
};
}
function add1($a) {
return $a + 1;
from itertools import *
class Cont(object):
def __init__(self, func, *args):
self.args = args
self.func = func
self.done = False
def next(self):
if self.done:
@weskerfoot
weskerfoot / days.hs
Created August 18, 2013 01:52
days of the week
data Day = Mon | Tues | Wed | Thurs | Fri | Sat | Sun deriving (Enum, Ord, Eq, Show)
daysFromNow :: Day -> Int -> Day
daysFromNow day n = toEnum $ (fromEnum day) + n `mod` 6
main = do
print $ daysFromNow Mon 2
print $ daysFromNow Sat 7
print $ daysFromNow Wed 13
#! /usr/bin/python2
import xchat
from time import sleep
from threading import Thread as Thd
import Queue as Q
__module_name__ = "ts"
__module_version__ = "1"
__module_description__ = "ts"
function foo() {
var a = 1;
function bar() {
var a = 2;
console.log(a);
}
bar();
console.log(a);
}
function foo() {
var a = 1;
function bar() {
a = 2;
console.log(a);
}
bar();
console.log(a);
}