Skip to content

Instantly share code, notes, and snippets.

View aparrish's full-sized avatar

Allison Parrish aparrish

View GitHub Profile
isobel:~ adam$ perl -le 'print join "", reverse sort split //, "everything"' | perl -le 'print $_ x (ord($_) - ord('a')+1) for split //, <>'
yyyyyyyyyyyyyyyyyyyyyyyyy
vvvvvvvvvvvvvvvvvvvvvv
tttttttttttttttttttt
rrrrrrrrrrrrrrrrrr
nnnnnnnnnnnnnn
iiiiiiiii
hhhhhhhh
ggggggg
eeeee
isobel:~ adam$ perl -le '$x=shift@ARGV;{print substr($x,$i%length $x).substr($x,0,$i%length $x);$i++;redo}' everything |head -25
everything
verythinge
erythingev
rythingeve
ythingever
thingevery
hingeveryt
ingeveryth
ngeverythi
isobel:~ adam$ perl -le 'for(split//,shift@ARGV){$r++;read(STDIN,$c,1);if($c=~/$_/i){print "$c (read $r bytes)";$r=0;next}redo}' everything </dev/urandom
E (read 70 bytes)
v (read 388 bytes)
E (read 15 bytes)
r (read 166 bytes)
y (read 186 bytes)
T (read 180 bytes)
H (read 130 bytes)
I (read 21 bytes)
n (read 56 bytes)
@aparrish
aparrish / page_graph.py
Created April 21, 2011 22:37
page through any facebook graph request
# usage:
# python page_graph.py https://graph.facebook.com/some/path?access_token=x
# ... where some/path is the thing you want to get from the graph api, and 'x' is a
# valid access token (such as can be obtained from http://developers.facebook.com/docs/reference/api/)
# redefine the 'tester' function to change what happens with each data item in the
# response
import json
import urllib
import time
@aparrish
aparrish / gaussian_sonnet.py
Created April 22, 2011 15:22
gaussian sonnet
import random
import sys
def somewhere_around_n(lines, n, stddev):
idx = int(random.gauss(n, stddev))
if idx < 0: idx = 0
if idx > len(lines) - 1: idx = len(lines) - 1
return lines[idx]
stddev = int(sys.argv[1])
@aparrish
aparrish / wordturn.py
Created April 23, 2011 17:32
processing.py sketch for making rotating poem things
import random
class Sketch(object):
def __init__(self):
self.words = [
['then', 'later', 'and'],
['my', 'the', 'a', 'that'],
['minister', 'survey', 'drunk', 'lather', 'liver', 'doctor', 'grue', 'vice', 'devilry', 'shortcake'],
['confessed', 'drained', 'maintained', 'checked out', 'focused'],
['your', 'those', 'all', 'his', 'her', 'lifelessly.', 'as well.', 'here.', 'first.'],
@aparrish
aparrish / replacer.py
Created April 25, 2011 12:20
replace strings in file with other random strings having the same number of letters
# usage:
# python replacer.py wordlist input_file output_file
import sys
import re
import random
words = dict()
allwords = set()
for line in open(sys.argv[1]):
line = line.strip()
@aparrish
aparrish / stories.grammar
Created April 28, 2011 03:25
grammar for gossipy stories - for use with the CFG generator discussed here: http://wp.me/PfzbG-a4
Para -> It all started when S . ManyContinueS . ConclusionS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS . ManyContinueS
ManyContinueS -> ContinueS
S -> PersonPsg VPsg
@aparrish
aparrish / poem.py
Created April 29, 2011 02:48
dramatically enjambed poems (using nltk POS-tagging)
import nltk
import sys
from nltk.corpus import brown
import random
import re
def only_tokens(paired_list):
return [x[0] for x in paired_list]
def clean(s):
@aparrish
aparrish / simplethread.py
Created May 1, 2011 14:45
simple threading example with processing.py
from threading import Thread
import random
import time
def random_wait(max_seconds, callback):
seconds = random.randrange(max_seconds)
time.sleep(seconds)
callback(seconds)
class Sketch(object):