Skip to content

Instantly share code, notes, and snippets.

View pscollins's full-sized avatar

Patrick Collins pscollins

View GitHub Profile
@pscollins
pscollins / gist:6d1bb9b7b2145e43aa25
Created April 2, 2015 05:13
Python prime factorization
def factors(n):
app = [n] if n != 1 else []
ans = set(chain(app, *((i, n//i) for i in range(2, int(sqrt(n) + 1))
if not n % i)))
return ans
vows = require 'vows'
assert = require 'assert'
phantom = require '../phantom'
describe = (name, bat) -> vows.describe(name).addBatch(bat).export(module)
# Make coffeescript not return anything
# This is needed because vows topics do different things if you have a return value
t = (fn) ->
->
@pscollins
pscollins / gist:e236222ac83ac06129f1
Last active August 29, 2015 14:13
This is wrong(?)
class Vertex:
def __init__(self, idx, parent, children):
self.idx = idx
self.parent = parent
self.children = children
def rb_dist(source, graph):
def init_list():
return [float('inf') for _ in graph]
@pscollins
pscollins / scrape.sh
Created January 13, 2015 04:02
Scrape chalk
BASE_URL="https://chalk.uchicago.edu/webapps"
AUTH_URL="$BASE_URL/login/?action=relogin"
SCRAPE_URL="$BASE_URL/blackboard/content/launchLink.jsp?course_id=_137801_1&tool_id=_139_1&tool_type=TOOL&mode=view&mode=reset"
# Log in to the server. This can be done only once.
wget --keep-session-cookies --save-cookies cookies.txt --post-data 'user_id=$1&password=$2' $AUTH_URL
# Now grab the page or pages we care about.
wget --load-cookies cookies.txt -m $SCRAPE_URL
import logging
LOG = logging.getLogger(__name__)
LOG.setLevel("DEBUG")
LOG.warning("foo")
LOG.debug("bar")
datatype type_node
= Param of TyParam.t
| LongId of LongTyId.t * tyargs_t option
| Record of field_t list
| Tuple of type_t list
| Fun of type_t list * type_t list option * type_t list
| Any
| VProc
| Cont of tyargs_t option
| Addr of type_t
@pscollins
pscollins / ParseRun.java
Created August 6, 2014 09:59
regex strangeness
public static Calendar startCalendarFromFilename(String bookPath) {
// format is YYYYMMDD
String datePattern = "\\D+(\\d{4})(\\d{2})(\\d{2})\\.csv\\.gz";
Pattern dateRe = Pattern.compile(datePattern);
Matcher matcher = dateRe.matcher(bookPath);
Calendar startDate;
if (matcher.groupCount() == 3) {
System.out.println("Got match on:" + matcher.toString());
System.out.println("Group 0:" + matcher.group(0));
(23): {
[ 81400000, 400,
80620000, 25,
80500000, 50,
79800000, 200,
76510000, 100,
75000000, 100,
72600000, 100,
72520000, 5,
72000000, 25,
(23): {
[ 83500000, 100,
85000000, 10,
90000000, 100,
115200000, 5,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
@pscollins
pscollins / HDF5CompoundVerifier.java
Last active August 29, 2015 14:04
getting at T.class?
public class HDF5CompoundVerifier<T> {
private final IHDF5Reader expectedReader;
private final IHDF5Reader actualReader;
private final boolean READ_LINK_TARGETS = false;
private final HDF5CompoundDSBridgeBuilder<T> expectedBridgeBuilder;
private final HDF5CompoundDSBridgeBuilder<T> actualBridgeBuilder;
private final String ROOT;
public HDF5CompoundVerifier(IHDF5Writer expectedWriter, IHDF5Writer actualWriter, Class<T> typeForBridge, String root) {
actualBridgeBuilder = new HDF5CompoundDSBridgeBuilder<>(actualWriter);