Skip to content

Instantly share code, notes, and snippets.

View Ceasar's full-sized avatar

Ceasar Ceasar

View GitHub Profile
@Ceasar
Ceasar / manufactoria.hs
Created June 26, 2013 07:11
Simulation of manufactoria. WIP.
import qualified Data.Map as M
data Direction = N | S | E | W deriving Eq
type Location = (Int, Int)
data Sticker = Red | Blue deriving Eq
data Widget = Widget Location [Sticker]
"""
Convert markdown files containing Python code into working Python files.
Usage: python md2.py [markdownfile]
Example:
Flask is Fun
============
@Ceasar
Ceasar / scrape_tables.py
Created July 26, 2013 22:44
Scrape tables off a web page.
"""
Covert html tables into csvs.
"""
import sys
import urllib
from lxml import etree
@Ceasar
Ceasar / xml2json.py
Created July 26, 2013 22:44
Convert xml to json.
'''A module for converting xml into json.'''
import json
from lxml import etree
def xml_to_json(xml_input, json_output):
'''Converts an xml file to json.'''
dict_to_json(etree_to_dict(xml_to_etree(xml_input), True), json_output)
@Ceasar
Ceasar / Chess.hs
Created July 26, 2013 22:52
WIP Haskell chess.
module Chess where
import Data.Map as M
import Test.HUnit
import Test.QuickCheck
type Pos = (Int, Int)
data Color = White | Black
@Ceasar
Ceasar / speed_primes.py
Created July 26, 2013 23:20
Speed test.
import timeit
setup = """
def primes(n):
'''Get all primes up to n.'''
if n < 2:
return []
nums = range(n)
sieve = set(xrange(2, n))
@Ceasar
Ceasar / Logic.lhs
Created July 26, 2013 23:22
Propositional logic.
> import Data.Set as S
> import Data.Map as M
> import Data.Maybe
> import Control.Monad (liftM, liftM2)
> import Test.QuickCheck
A statement is a sentence that is determinately true of determinately false independently of the circumstances in which it is used.
> data Proposition = Implies Proposition Proposition
@Ceasar
Ceasar / Lisp.hs
Created July 27, 2013 02:37
Lisp in Haskell. WIP.
import Text.ParserCombinators.Parsec
import System.Environment
data LispVal = Atom String
-- | List [LispVal]
-- | DottedList [LispVal] LispVal
| Number Integer
| String String
"""
Palantir interview question.
The goal is to, given an elevation map of some land, print out a
list of basin sizes in descending order, where a basin is a set of
cells of land that all drain to a common point. One cell drains to
another if among the first cell and its neighbors (i.e. cells adjacent,
horizonatlly, vertically or diagonally) the second cell has the lowest
elevation.
import sys
import time
from sh import networksetup
DEVICE = 'en0'
NETWORK = u'AirPennNet'
NETWORK = u'Lovers&Madmen'