Skip to content

Instantly share code, notes, and snippets.

# different functions that can be passed in
# (num_divisors is used by default)
uniq_factors = lambda x: len([p for p,n in factor(x)])
count_factors = lambda x: sum(n for p,n in factor(x))
num_divisors = lambda x: len(divisors(x))
def plot_divisors(height=100, fun=num_divisors):
width = 2*height
m = matrix(height, width)
l = width / 2
httpProxy = require 'http-proxy' # npm install http-proxy
server = httpProxy.createServer (req, res, proxy) ->
if req.headers['host'] == PUBLIC_IP
# react to a request sent from the malicious beacon giving
# the user's current location
{query} = url.parse(req.url)
{location} = querystring.parse(query)
if location
console.log "Tracked location: #{location}"
@paulgb
paulgb / index.html
Created February 10, 2013 20:56 — forked from wrr/index.html
<!DOCTYPE html>
<!-- By Jan Wrobel (http://mixedbit.org) -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Random walk</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
from sklearn import preprocessing, pipeline
label_enc = preprocessing.LabelEncoder()
pipe = pipeline.Pipeline([('enc', label_enc)])
X = ['foo', 'bar', 'baz']
label_enc.fit(X) # works
pipe.fit(X) # fails w/ output below
@paulgb
paulgb / convert.py
Last active January 31, 2020 22:40
Convert the Yelp Academic dataset from JSON to CSV files with Pandas.
'''
Convert Yelp Academic Dataset from JSON to CSV
Requires Pandas (https://pypi.python.org/pypi/pandas)
By Paul Butler, No Rights Reserved
'''
import json
import pandas as pd
@paulgb
paulgb / Great Circle Flight Maps.ipynb
Last active February 7, 2021 18:47
Visualization of OpenFlight data with gcmap python package
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paulgb
paulgb / racecondition.py
Created September 15, 2013 16:18
A race condition in IPython under Mac OS Darwin. iopub.get_msg fails unless sleep(1) is uncommented.
from IPython.kernel import KernelManager
from time import sleep
def racecondition():
km = KernelManager()
km.start_kernel()
kc = km.client()
kc.start_channels()
@paulgb
paulgb / binom_interval.py
Created September 19, 2013 17:58
Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
from scipy.stats import beta
def binom_interval(success, total, confint=0.95):
quantile = (1 - confint) / 2.
lower = beta.ppf(quantile, success, total - success + 1)
upper = beta.ppf(1 - quantile, success + 1, total - success)
return (lower, upper)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from os.path import getsize
from progressbar import ProgressBar
class ProgOpen(object):
def __init__(self, filename):
self.filename = filename
def __iter__(self):
return self