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/python3 | |
""" | |
Solver for the "Frog Puzzle" Android game. | |
Does not implement sinkable platforms. | |
Is not efficient at searching; naively tries all combos of labels. | |
""" | |
from collections import namedtuple, defaultdict | |
import itertools |
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 | |
""" | |
(Stratified) sampling without replacement of lines on stdin. | |
Preserves random N lines of input (without replacement), discards others. | |
Optionally, lines can be grouped into classes based on a value extracted from the line; | |
in this case, N lines per group are preserved. | |
Order is not preserved. | |
Examples: |
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
/** | |
* For books or conference proceedings, SpringerLink makes you download | |
* one chapter/article at a time. Mass downloaders like DownThemAll help, | |
* but need link titles different than just "download" to be able to name | |
* the files sensibly. This small script sets each download link's title | |
* to the title of the article (taken from elswhere in the DOM). | |
*/ | |
function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1;} | |
$('a').filter(function(idx){return endsWith(this.href,'fulltext.pdf');}).each(function(){$(this).attr('title',$(this).parent().parent().parent().find('p.title a').text())}) |
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 base64 | |
import json | |
import matplotlib, matplotlib.pyplot | |
import numpy | |
import types | |
def show_plot(width, height=None): | |
""" | |
A decorator -- show the matplotlib plot after `f` completes. | |
Takes optional parameters (width, height) determining the size of the plot. |
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 restart_on_crash(log_exprs=[]): | |
""" | |
A function decorator that re-runs the wrapped function in case it raises an exception. | |
This is repeated until the function succeeds. | |
`log_exprs` is a list of strings, each string being an expression whose value at the time | |
of exception is displayed. Example: | |
>>> @restart_on_crash(log_exprs=['b', 'a+b']) | |
>>> def divider(a): | |
>>> import random; random.seed(time.time()) |
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
#-*- coding:utf-8 -*- | |
from django.utils.translation import ugettext_lazy as _ | |
from django import forms | |
from django.conf import settings | |
from django.utils.encoding import smart_unicode | |
from django.utils.encoding import force_unicode | |
from django.core.exceptions import ValidationError |