Skip to content

Instantly share code, notes, and snippets.

Avatar

Brendan Berg brendanberg

View GitHub Profile
@brendanberg
brendanberg / vowlies.py
Created Aug 6, 2010
Counts vowels and consonants from stdin
View vowlies.py
import sys, string
def vowels(str):
count = 0
for let in str:
if let in list("AEIOUaeiou"):
count += 1
return count
def vowelies(str):
@brendanberg
brendanberg / lisp.coffee
Created Aug 24, 2011
Lisp list functions in CoffeeScript
View lisp.coffee
cons = (h, t) -> (m) -> m(h, t)
car = (x) -> x((h, t) -> h)
cdr = (x) -> if x then x((h, t) -> t) else null
map = (ls, f) ->
cons (f car ls), if cdr ls then map cdr(ls), f else null
foldl = (ls, f, n) ->
f (car ls), if cdr ls then foldl (cdr ls), f, n else n
@brendanberg
brendanberg / coffee.html
Created Aug 24, 2011
CoffeeScript in Your Browser
View coffee.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Caffeinate Me!</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Brendan Berg">
<!-- Date: 2011-08-24 -->
<style>
@brendanberg
brendanberg / point.coffee
Created Aug 29, 2011
Making objects using closures in CoffeeScript
View point.coffee
point = (x, y) ->
setX = (nx) -> x = nx
setY = (ny) -> y = ny
(n) -> n(x, y, setX, setY)
pointGetX = ->
(x, y) -> x
pointGetY = ->
(x, y) -> y
@brendanberg
brendanberg / random
Created Oct 27, 2011
Can you guess the output?
View random
public static void main(String ... args) {
System.out.println(randomString(-229985452)+' '+randomString(-147909649));
}
public static String randomString(int seed) {
Random rand = new Random(seed);
StringBuilder sb = new StringBuilder();
for(int i=0;;i++) {
int n = rand.nextInt(27);
if (n == 0) break;
@brendanberg
brendanberg / best-of.txt
Created Nov 12, 2011
egrep [aeiou]{4} sowpods.txt
View best-of.txt
aqueous
banlieue
bioaeration
bioaeronautics
euouae
gooier
guaiac
guaiacol
guaiacum
homoiousian
@brendanberg
brendanberg / gist:1556862
Created Jan 3, 2012
Evil dictionary insertions in Python
View gist:1556862
from time import time
def elapsed(fn):
t = time()
fn()
return time() - t
def insert_good(n):
for i in range(2 ** n):
d[i] = 0
@brendanberg
brendanberg / detector.py
Created Mar 10, 2012
Connect4 winner detection
View detector.py
import sys
import json
def search_line(row):
string = ''.join(row)
if string.find('OOOO') != -1:
return 'O'
if string.find('XXXX') != -1:
return 'X'
else:
@brendanberg
brendanberg / password.py
Created Jun 20, 2012
Generates every valid password for an incredibly stupid authentication system
View password.py
import itertools
# Finding every single terrible password
#
# (Password requirements from http://kottke.org/12/06/the-worlds-worst-password-requirements-list)
#
# Must be exactly 8 characters long
# Must contain at least one character from each of these sets:
# ['@', '#', '$'],
# ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
@brendanberg
brendanberg / gist:4080423
Created Nov 15, 2012
A Parsing Expression Grammar to Turn Buffalo into Fish
View gist:4080423
/*
* Use this at http://pegjs.majda.cz/online
*
* Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo
* - becomes -
* Fishy fish fishy fish fish fish fishy fish
*
* Also, the grammar is recursive, so it could also generate ALL THE FISH.
*/
You can’t perform that action at this time.