Skip to content

Instantly share code, notes, and snippets.

View evansb's full-sized avatar

Evan Sebastian evansb

  • Singapore
View GitHub Profile
@evansb
evansb / memoize.hs
Last active August 29, 2015 14:12
Memoization hack in Haskell, using unsafe IO operation.
module Memoize (memoize) where
import Debug.Trace
import Data.Hashable
import System.IO.Unsafe
import qualified Data.HashTable.IO as H
type HashTable k v = H.CuckooHashTable k v
@evansb
evansb / bundles.vim
Last active August 29, 2015 14:10
bundles
" Here come the bundles
Bundle 'gmarik/vundle'
Bundle 'Valloric/YouCompleteMe'
Bundle 'Lokaltog/powerline-fonts'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'MarcWeber/vim-addon-mw-utils'
Bundle 'Raimondi/delimitMate'
Bundle 'bling/vim-airline'
Bundle 'bling/vim-bufferline'
@evansb
evansb / .vimrc
Last active August 29, 2015 14:10
set encoding=utf-8
scriptencoding utf-8
set nocompatible
filetype off
"let $PATH='/Users/evan/.opam/system/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/evan/School/Haskell/.cabal-sandbox/bin:/Users/evan/.cabal/bin'
if has("gui_running")
set guifont=Source\ Code\ Pro\ Medium:h14
@evansb
evansb / thread_guard.cpp
Created December 3, 2014 15:28
C++ multi threaded programming notes
#include <iostream>
#include <stdexcept>
#include <thread>
/* Thread guard is an RAII for thread that ensures
* join is called when the function that creates
* the thread goes out of scope.
*/
class ThreadGuard {
@evansb
evansb / tut2.ml
Created September 1, 2014 07:11
Tutorial 2 CS2104
(* Tutorial 2 : Recursion & Higher-Order Functions *)
(*
OCaml Reading Resources
tutorial:
http://ocaml.org/learn/tutorials/
introduction:
http://www.cs.jhu.edu/~scott/pl/lectures/caml-intro.html
@evansb
evansb / Parser.hs
Created August 11, 2014 11:28
3 lines Parser in Haskell (Line 9,11,12)
import Control.Monad.State.Lazy
import Control.Monad.Error
import Control.Monad.Identity
import Control.Applicative
import Data.Char
-- Begin parser
type Parser a = StateT String (ErrorT String Identity) a
@evansb
evansb / dp.py
Created July 26, 2014 05:44
Some DP problems in Python
def ugly_pascal_triangle(level):
table = []
for row in range(level):
for col in range(level):
if row == 0:
table.append([])
if col == 0 or row == col:
table[row].append(1)
@evansb
evansb / erdos.py
Created July 4, 2014 16:21
Erdos Number (UVA 10044).
import sys
DEBUG = True
INFINITY = 99999
def debug(var):
if DEBUG:
sys.stderr.write(repr(var) + "\n")
def make_adjacent(graph, people, paper):
@evansb
evansb / fold.hs
Created June 21, 2014 14:16
Some interesting fold example
-- Try to guess what divide does!
divide:: (Integral a) => [a] -> [[a]]
divide = f1 . f2 where
f1 = foldr f3 []
f2 = map (:[])
f3 x acc
| null acc = x : acc
| (head x * head (head acc)) > 0 = (x ++ head acc) : tail acc
| otherwise = x : acc
@evansb
evansb / binarytree.hs
Created June 7, 2014 11:13
Balanced Binary Tree from List in Haskell.... Literally just copying the definition.
data Tree a = Leaf
| Node Integer (Tree a) a (Tree a)
deriving (Show, Eq)
foldTree :: [a] -> Tree a
foldTree [] = Leaf
foldTree xs = Node height
(foldTree $ take half xs)
(xs !! half)
(foldTree $ drop (half + 1) xs)