Skip to content

Instantly share code, notes, and snippets.

# handy aliases
[alias]
co = checkout
stat = status
prune-all = !git remote | xargs -n 1 git remote prune
fetch-all = !git remote | xargs -n 1 git fetch
# do the right thing for gh:user/repo.git urls
[url "[email protected]:"]
Python 2.7.2 (default, Apr 1 2012, 14:18:41)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # load up a test file
>>> import OIL
>>> i = OIL.Image.load("input.png")
>>> i.get_size()
(800, 600)
>>> # save it to a stringio object
>>> import StringIO
# a silly long computation
def long_computation(a, b):
print("doing long computation", a, b)
# sleep for 2 seconds, asynchronously
yield until_elapsed(2)
print("computation successfull", a, b)
return a + b
# normal use of return
def func1():
return(1)
print func1() # prints '1'
# freaky use of return
stored_return = None
def func2():
global stored_return
import phosphorus
from phosphorus.irc import IRC
import sys
_, host, port, nick = sys.argv
def main():
irc = IRC(host, port, nick)
yield phosphorus.fork(irc.run())
yield phosphorus.until_elapsed(2)
@agrif
agrif / gist:3879048
Created October 12, 2012 12:45
metric seconds!
Normal to Prefixed Seconds
--------------------------
1 hour ~= 4 ks
1 day ~= 90 ks
1 week ~= 600 ks
1 month ~= 3 Ms
1 year ~= 30 Ms
1 decade ~= 300 Ms
average human life ~= 2 Gs
achin: any weider than gravity?
[4:56pm] agrif: less weird
[4:56pm] agrif: gravity is insane
[4:57pm] agrif: so did you know that electromagnetism is what pushes back on you when you push on a wall?
[4:57pm] agrif: it's the same force
[4:57pm] achin: yes, i think i did
[4:58pm] agrif: it's just that in a magnet, everything is aligned just so, so that all atoms are working together
[4:58pm] achin: well, i could have said that, but don't really *know* what it means
[4:58pm] agrif: so you feel it farther away than you do normally
[4:58pm] agrif: constructive interference
@agrif
agrif / sexp.py
Created October 28, 2012 21:27
S-expression parser in python (minus value classes)
from string import whitespace, digits
from values import Cell, Symbol, Integer
token_boundaries = '(.)' + whitespace
# parser functions return (result, leftover) tuples
# parse a token single token, respecting token boundaries
def parse_token(s):
# find the first token boundary character
rm: cannot remove 'confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdir3/confdi
$ 1 5.0E-6 10.20027730826997 43 5.0 43
r 352 224 352 144 0 40.0
r 400 224 400 144 0 40.0
w 400 224 352 224 0
w 352 224 352 256 0
w 400 144 352 144 0
w 288 176 288 144 0
w 288 144 352 144 0
R 352 144 352 96 0 0 40.0 12.0 0.0 0.0 0.5
g 352 288 352 336 0