Skip to content

Instantly share code, notes, and snippets.

@travisby
travisby / basicLexerFlow.js
Last active August 29, 2015 13:56
Basic idea for a Lexer flow.. not taking into account quotes or comments
// the first few dozen lines are more boilerplate that we will probably already have built-in with OCaml
// In addition, the Token prototype is really a do-nothing. A real token prototype/datatype will be much, much cooler
Object.prototype.keys = function () {
var keys = [];
for (var key in this) {
keys.push(key);
}
@travisby
travisby / switchVif
Created April 17, 2014 22:24
switch vs. if statement
[~]$ pr -m -t test1.c test2.c
int main() { int main() {
int x; int x;
if (x == 0) { switch (x) {
// case 0:
} else if (x == 1) { break;
// case 1:
} break;
return 0; }
} }

Keybase proof

I hereby claim:

  • I am travisby on github.
  • I am travisby (https://keybase.io/travisby) on keybase.
  • I have a public key whose fingerprint is CF83 0F41 2F3C FD90 7365 F15A 0EF3 6F58 BC1A 6525

To claim this, I am signing this object:

module Main where
import Data.Maybe
import Data.List
main = do
content <- getContents
-- get rid of \n
let c = init content
putStr "Single Santa traveled: "
@travisby
travisby / advent_day_04.hs
Created December 5, 2015 16:25
advent_day_04.hs
module Main where
import Data.Hash.MD5
main = do
input <- getContents
let key = init input
let firstResult = head . filter (isAdventCoin key 5) $ [1..]
putStr "00000...: "
print firstResult
module Main where
import Data.List
import Debug.Trace
main = do
input <- getContents
let xs = lines input
putStr "Old rules: "
print (length (filter (allPredicates [atLeastNVowels 3, repeats, not . containsBlacklistedPhrase]) xs))
module Main where
import Data.Maybe
import Data.List
main = do
content <- getContents
let boxes = map (fromJust . strToBox) $ lines content
putStr "Paper: "
print . sum . map boxToPaper $ boxes
putStr "Ribbon: "
data Action = On | Off | Toggle deriving (Show, Eq)
data Rectangle = Rectangle Point Point deriving Show
data Point = Point Int Int deriving Show
-- strToInstruction :: String -> Maybe Instruction
-- strToInstruction ('t':'u':'r':'n':' ':'o':'n':xs) = Just (Instruction On (strToRectangle xs))
-- strToInstruction ('t':'u':'r':'n':' ':'o':'f':'f':' ':xs) = Just (Instruction Off (strToRectangle xs))
-- strToInstruction ('t':'o':'g':'g':'l':'e':' ': xs) = Just (Instruction Toggle (strToRectangle xs))
-- strToInstruction x = trace x Nothing
@travisby
travisby / fib.py
Created February 7, 2013 03:05
Memoized fibonacci sequence in python
"""
Each new term in the Fibonacci sequence is generated by adding the previous two
terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not
exceed four million, find the sum of the even-valued term
"""
@travisby
travisby / nest.hs
Created March 6, 2013 04:25
Non-working Haskell :(
travis@localhost ~/Documents/dev/school/language_study/chapter5 $ cat Prettify.hs
data Doc = Empty
| Char Char
| Text String
| Line
| Concat Doc Doc
| Union Doc Doc
deriving (Show,Eq)
empty :: Doc
empty = Empty