Skip to content

Instantly share code, notes, and snippets.

@rhwlo
rhwlo / CISPA-ayes
Created April 18, 2013 22:01
paste into the terminal with your state to find out who voted for CISPA!
(state='CA';curl -s 'http://clerk.house.gov/evs/2012/roll192.xml' | sed -rn '/'$state'"/{/Aye/{s/^.+r">([^<]+).*$/\1/p;};}')
import random
from nltk.corpus import cmudict
d = cmudict.dict()
benedicts = [k for (k,v) in d.iteritems() if len([s for s in v[0] if s[-1].isdigit()]) == 3 and v[0][0] == u'B' and '1' in v[0][1]]
cumberbatches = [k for (k,v) in d.iteritems() if len([s for s in v[0] if s[-1].isdigit()]) == 3 and k[0] == 'c' and v[0][0] == u'K' and '1' in v[0][1]]
for i in xrange(200):

Keybase proof

I hereby claim:

  • I am apollotiger on github.
  • I am joshu (https://keybase.io/joshu) on keybase.
  • I have a public key whose fingerprint is EBC6 6EBE 457B 129A 7851 4173 7A83 B9FF 4A83 2170

To claim this, I am signing this object:

@rhwlo
rhwlo / gameoflife.elm
Last active August 29, 2015 14:09
Conway’s game of life, Elm style.
data Status = Alive | Dead
type Board = [[Status]]
type Coordinate = { row:Int, column:Int }
getNodeAt : Board -> Coordinate -> Status
getNodeAt graph coordinate =
let maxRow = length graph
maxColumn = maximum <| map length graph
row = coordinate.row
column = coordinate.column
@rhwlo
rhwlo / delimTake.hs
Last active August 29, 2015 14:10
break lists of lists on a list of delimiters
import Control.Applicative
-- delimTake takes until it either:
-- 1) reaches the nth item (as "take N")
-- 2) reaches an item containing a delimiter
delimTake :: (Eq a) => [a] -> Int -> [[a]] -> [[a]]
delimTake delimList n seq
| snd brokenTake == [] = naiveTake
| otherwise = (fst brokenTake) ++ [fst breakDelimItem]
where
@rhwlo
rhwlo / dancingPixels.elm
Last active August 29, 2015 14:10
It doesn’t mean anything.
-- just for fun
-- compiled and uploaded to http://rhwlo.com/dancingPixels
import Bitwise as B
type ColorGrid = [[Color]]
actualWidth = 300
drawGrid : ColorGrid -> Element
drawGrid grid = let gridWidth = (length grid)
@rhwlo
rhwlo / JsonToCsv.hs
Created December 22, 2014 02:17
Messing around with converting from JSON (via Data.Aeson) to CSV-y formats.
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson
import Data.List (nub)
import qualified Data.HashMap.Strict as HM
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Vector as V
packShow :: Show a => a -> T.Text

Keybase proof

I hereby claim:

  • I am rhwlo on github.
  • I am joshu (https://keybase.io/joshu) on keybase.
  • I have a public key whose fingerprint is EBC6 6EBE 457B 129A 7851 4173 7A83 B9FF 4A83 2170

To claim this, I am signing this object:

def deriveKey(masterKey: String, allowedOperations: String) = {
def bytesToString(bytes: Array[Byte]) = {
bytes.map({byte => Integer.toString(byte.toInt, 16)}).mkString
}
val masterKeyBytes: Array[Byte] = {
masterKey.map({ char =>
Integer.parseInt(char.toString, 16).toByte
}).toArray
}
@rhwlo
rhwlo / curses_skull.py
Created July 2, 2015 23:10
an animated skull in curses! idea from Achewood
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import curses
import time
SKULLS = ("""
▒▒▒▒▒▒▒
▒▒▓▓▓▓▓▓▓▓▓▓▓▒▒
▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒