Skip to content

Instantly share code, notes, and snippets.

View bshillingford's full-sized avatar

Brendan Shillingford bshillingford

View GitHub Profile
@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):
"""
@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 / 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 / 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 / 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):