Skip to content

Instantly share code, notes, and snippets.

View bshillingford's full-sized avatar

Brendan Shillingford bshillingford

View GitHub Profile
@bshillingford
bshillingford / scraper.py
Last active December 15, 2015 22:29
Simple Python scraper library
import lxml.html
import urllib2
import urllib
import cookielib
import re
class ScraperException(Exception):
pass
class Page(object):
@bshillingford
bshillingford / CookieWebClient.cs
Created April 8, 2013 02:33
cookie-enabled (stateful) web scraping helper C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace UbcAutoRegister
{
class CookieWebClient : WebClient
{
@bshillingford
bshillingford / scrape_all.py
Last active December 16, 2015 05:39
SSC course scrape Python module
#!/usr/bin/python2.7
import lxml, lxml.etree, urllib2, re
SESSYR=2012
SESSCD='W'
debug_last_url = None
def read_endpoint(dept=None, course=None, section=None):
global SESSYR, SESSCD
@bshillingford
bshillingford / gist:5565243
Last active December 17, 2015 06:28
Duplicate finder
#!/usr/bin/python2.7
import subprocess
from collections import defaultdict
from glob import glob
import sys
pattern = sys.argv[1]
d = defaultdict(lambda: [])
@bshillingford
bshillingford / logtype.py
Last active December 18, 2015 07:39
A numeric type for Python that performs nonnegative float computations in log-space.
__author__ = 'brendan'
__all__ = ['logfloat', 'LogFloat']
import numpy as np # numpy's logaddexp correctly handles LOGZERO
from math import log as _log, exp as _exp
@np.vectorize
def logfloat(x):
"""
# -*- coding: utf-8 -*-
__author__ = 'brendan'
import collections
class property_dict(collections.Mapping):
"""
Dictionary wrapper that adapts a dict with a wrapper allowing property-style reads. Intended
for ease of JSON accessing.
"""
Google Directions API
"""
import urllib2
import urllib
import json
class Modes:
DRIVING="driving"
#!/bin/bash
##############################
# install Torch
# export PREFIX=/home/scratch/$USER/torch
export PREFIX="/home/scratch/torchshared/torch"
mkdir -p $PREFIX
rm -rf /tmp/luajit-rocks
@bshillingford
bshillingford / lbfgs_new.lua
Last active September 8, 2015 04:15
See test.lua for verification the new code works
--[[ An implementation of L-BFGS, heavily inspired by minFunc (Mark Schmidt)
This implementation of L-BFGS relies on a user-provided line
search function (state.lineSearch). If this function is not
provided, then a simple learningRate is used to produce fixed
size steps. Fixed size steps are much less costly than line
searches, and can be useful for stochastic problems.
The learning rate is used even when a line search is provided.
This is also useful for large-scale stochastic problems, where
@bshillingford
bshillingford / arxiv_bash_aliases.sh
Last active July 9, 2020 10:09
useful arxiv tools for bash
function arxiv-authors() {
if [ $# -ne 1 ]; then
echo "Usage: arxiv-authors arxiv_url_or_id"
echo "Prints authors' names, one per line."
else
if [[ $1 == http* ]]; then
url=$1
else
url=http://arxiv.org/abs/$1
fi