Skip to content

Instantly share code, notes, and snippets.

View Ceasar's full-sized avatar

Ceasar Ceasar

View GitHub Profile
@Ceasar
Ceasar / lex.py
Last active August 29, 2015 14:01
problem with python scope.
"""
there is no way good way to make this append() function, which is unfortuante because we want the two lines in it to be atomic.
"""
def _lex(line):
tokens = []
token = ""
whitespace = {' '}
escape_chars = {'\\'}
escape = False
_ = require "lodash"
memoize = (f) ->
cache = {}
memoizer = ->
args = Array.prototype.slice.call(arguments)
if _.has(cache, args) then cache[args] else cache[args] = f.apply this, args
return memoizer
fib = (n) ->
"""
fab -H [hostname] [command]
"""
from fabric.api import run
HOME = '/Users/ceasarbautista'
def authorize():
import sys
import time
from sh import networksetup
DEVICE = 'en0'
NETWORK = u'AirPennNet'
NETWORK = u'Lovers&Madmen'
"""
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.
@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
@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 / 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 / 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 / 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)