This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def from_number(r) | |
third = 1.0 / 3 | |
if r>= 0 and r<= third then choice = "r" end | |
if r >=third and r<= 2*third then choice = 'p' end | |
if r>= 2*third and r<= 1 then choice ='s' end | |
return choice | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# avahi-alias.py | |
import avahi, dbus | |
from encodings.idna import ToASCII | |
import logging | |
# Got these from /usr/include/avahi-common/defs.h | |
CLASS_IN = 0x01 | |
TYPE_CNAME = 0x05 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script to download a show from http://prairiehome.publicradio.org/ | |
Depends on rtmpdump (apt-get install rtmpdump) | |
Usage: | |
# List shows in January | |
python prar.py 2012 1 | |
# Download show with index 0 | |
python prar.py 2012 1 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import Data.Array.Repa as R | |
import Data.Array.Repa.Algorithms.Randomish as RR | |
import Criterion.Main | |
import Criterion.Config | |
ra = RR.randomishDoubleArray (ix2 1000 3) 0 1 1 | |
main = defaultMainWith defaultConfig {cfgSamples = ljust 10} (return ()) [ | |
bgroup "pairwise-random" [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
MODEL = """\ | |
53..7.... | |
6..195... | |
.98....6. | |
8...6...3 | |
4..8.3..1 | |
7...2...6 | |
.6....28. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dbus | |
bus = dbus.SystemBus() | |
NM = 'org.freedesktop.NetworkManager' | |
def get_manager(): | |
proxy = bus.get_object(NM, '/org/freedesktop/NetworkManager') | |
return dbus.Interface( | |
proxy, NM) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, turtle | |
def maze(w=10, h=10): | |
# This is the random spanning tree implementation | |
seen = set() | |
# Add some walls to confine the maze | |
for i in xrange(-1, w+1): | |
seen.add((i, -1)) | |
seen.add((i, h+1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import numpy | |
from skimage.filter import sobel | |
from skimage.morphology import watershed | |
from scipy import ndimage as nd | |
grind = numpy.asarray(Image.open('grind.png')).mean(axis=2) | |
edges = sobel(grind) | |
markers = numpy.zeros_like(grind) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solve n-queens problem with picosat | |
import pycosat | |
import numpy | |
import itertools | |
def get_cnf(N): | |
cnf = [] | |
# * convert to object because pycosat expects 'int's | |
# * add 1 because 0 is reserved in pycosat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycosat | |
import numpy | |
import itertools | |
WORLDS_HARDEST_RIDDLE_ACCORDING_TO_TELEGRAPH = """\ | |
8........ | |
..36..... | |
.7..9.2.. | |
.5...7... | |
....457.. |