This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> import Data.Char | |
> instance Functor Parser where | |
> -- map f p = MkP g | |
> fmap f p = MkP g | |
> where g s = [(f x, s') | (x,s') <- papply p s] | |
> alphanum :: Parser Char | |
> -- alphanum = sat isAlphaum | |
> alphanum = sat isAlphaNum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> module MyParseLib | |
> (Parser, mplus, orelse, item, many, some, manywith, somewith, | |
> sat, char, string, digit, lower, upper, letter, alphanum, | |
> ident, space, token, symbol, applyParser) where | |
> import Data.Char | |
> import Control.Monad | |
> newtype Parser a = MkP (String -> [(a,String)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> import System.Console.ANSI | |
> | |
> cls :: IO () | |
> -- cls = putStr "\ESC[2J" | |
> cls = clearScreen | |
> | |
> type Pos = (Int,Int) | |
> | |
> goto :: Pos -> IO () | |
> --goto (x,y) = putStr ("\ESC[" ++ show y ++ ";" ++ show x ++ "H") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval :: String -> Int | |
eval xs = case (parse expr xs) of | |
Just (n, "") -> n | |
Just (_, out) -> error ("unused input " ++ out) | |
failure -> error "invalid input" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/fixtures/bodies.yml | |
one: | |
id: 1 | |
file_entry_id: 1 | |
description: desc1 | |
two: | |
id: 2 | |
file_entry_id: 3 | |
description: description2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Field; | |
public class MemoryCheck { | |
private static int OVERHEAD = 16; | |
public static int calcUsage(Class testClass) throws Exception { | |
int usage = OVERHEAD; | |
Object obj = testClass.newInstance(); | |
for (Field field : testClass.getDeclaredFields()) { | |
String fieldName = field.getName(); | |
String fieldType = field.getType().getSimpleName(); | |
if (fieldType.equals("boolean")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shell_sort(a): | |
size = len(a) | |
h = 1 | |
while True: | |
h = 3 * h + 1 | |
if h > size: break | |
while True: | |
h /= 3 | |
#print "h=%d" % h | |
for i in range(h, size): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter: | |
fmt = "%d, %d" | |
def __init__(self): | |
self.db = {} | |
def count(self, w, h): | |
n = 0 | |
assert(w < h) | |
n = self.db.get(Counter.fmt % (w, h), None) | |
if n: return n | |
if h % w == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
import unittest | |
from test import test_support | |
class TestClass(unittest.TestCase): | |
def test_answer_conserves_names(self): | |
self.assertEqual(len(getNames("nick.txt", True)), | |
len(getNames("answer.txt"))) | |
def test_answer_nameList_is_uniq(self): | |
self.assertTrue(isUniq(getNames("answer.txt"))) | |
def isUniq(l1): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#path: project_name//app/controllers/home_controllers.rb | |
class HomeController < ActionController::Base | |
def index | |
end | |
def update | |
@params = params | |
render '/home/params' | |
end | |
end |