Skip to content

Instantly share code, notes, and snippets.

@Newky
Newky / lines.py
Created May 22, 2012 15:13
Little script to tell you where you are going over the 80 char limit. omits docstrings
#!/usr/bin/env python
#usage: lines.py filenames seperated by space
#my personal way of using it: lines.py `git diff --no-ext-diff --name-only HEAD~1 HEAD | grep .py`
import sys
TAB_WIDTH = 8
LINE_LENGTH = 79
def count(line):
@Newky
Newky / state.hs
Created January 7, 2012 19:18
State Haskell
data State s a = State (s -> (a, s))
test :: Int -> State Int () -> State Int () -> State Int Bool
test n f g = (f `bindState` (\_ -> g) `bindState` (\_ -> State $ (\s -> ((s > n), s))))
runState (State t) s = t s
returnState :: a -> State s a
returnState a = State $ (\s -> (a, s))
@Newky
Newky / HaskellRandom.hs
Created January 3, 2012 10:59
Haskell random generator demonstrating state monad.
import System.Random
newtype State s a = State {
runState :: s -> (a, s)
}
returnState :: a -> State s a
returnState a = State (\s-> (a, s))
bindState :: State s a -> (a -> State s b) -> State s b
@Newky
Newky / xando.hs
Created December 22, 2011 23:10
Sample Paper Haskell Q4.
import Data.List
data Piece = X | O deriving (Ord, Eq, Show)
data Board = Board [(Int, Int, Piece)] deriving(Ord, Eq,Show)
winning_combinations = [[(a,0), (a,1), (a,2)] | a <- [0..2] ] ++ [[(0,a), (1,a), (2,a)] | a <- [0..2] ] ++ [[(0,0), (1,1), (2,2)], [(0,2), (1,1), (2,0)]]
over2 :: Board -> Bool
over2 (Board []) = False
over2 (Board x) = is_winner newx winning_combinations
@Newky
Newky / prolog.js
Created September 19, 2011 16:56
Bit of prolog like magic with JavaScript
/*Prolog Num succ and prev defined in some wierd ass JS */
var num= (function(num) {
num = num || 0;
var x = num;
return {
s: function() {
x+=1;
return x;
},