Skip to content

Instantly share code, notes, and snippets.

View johnfn's full-sized avatar

Grant Mathews johnfn

View GitHub Profile
(defmacro simple [x] (eval x))
(let [y 5] (simple y))
>> can't eval locals
@johnfn
johnfn / gist:1177226
Created August 28, 2011 21:02
Ludum dare stat cruncher
# Copy (yes, literally copy as in copy and paste) all the data from the LD big stats page (http://www.ludumdare.com/compo/ludum-dare-20/?more=1)
# and put it into a file called "data" (quotes for clarity). Then run this file with python.
data = [l[:-1] for l in file("data")]
scores = {}
score_category = ""
categories = []
for line in data:
{- Say my html template looks something like this:
head
title Whats up?
body
div Yo.
-}
@johnfn
johnfn / gist:1285437
Created October 13, 2011 20:32
CS106a Style
import acm.program.*;
import stanford.karel.*;
public class BlankKarel extends SuperKarel {
/**
* Karel will move three spaces forward.
*
* Precondition: There are no walls 3 or less spaces away from Karel.
*/
@johnfn
johnfn / gist:1290540
Created October 16, 2011 05:28
Style guide

Style guide

One of the things I had problems with in the 106s is style. "What is this thing called style?!" I cried. "I came into CS because I liked how I could be sure I was absolutely right about something, and now you're telling me that I'll never know if I'm absolutely right?"

What is style?

Good style means: Your code is easy to read, and it's easy to modify.

That's it! Everything else stems from these two things in some way.

tester = do
let x = 5
let y = 6
return (x + y)
pure =
tester + 1
data Ptr = [Lens Tree Tree]
adjustTree :: Ptr Tree -> Maybe [Ptr Tree] -> Maybe Ptr Tree -> Tree
adjustTree updatedNode siblings createdNode root =
let np = parent updatedNode in
if isJust createdNode then
let newNode = fromJust createdNode in
if isFull newNode
class A:
def __init__(self, x):
self.x = x
def foo(self):
self = A(6)
a = A(5)
print a.x
a.foo()
@johnfn
johnfn / gist:1543294
Created December 31, 2011 07:52
flixel!
var hpSprite:FlxSprite = new FlxSprite(i * 16, HP_Y);
hpSprite.loadGraphic(ImgHP, true, false, 48, 16);
hpSprite.width = hpSprite.height = 16;
hpSprite.frame = 1;
add(hpSprite);
@johnfn
johnfn / gist:1613858
Created January 15, 2012 01:53
scala fun times
def revNoPatterns[A](list: List[A]): List[A] = list.foldLeft(List[A]())((result: List[A], elem: A) => elem :: result);