Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""pyCookieCheat.py
2014-10-28 Modified to FUCK ALL COOKIES (quit Google Chrome first) --Jeigh
20140701 v 2.1: Modularized the code, made it compatible with Python 2, and added an encryption function
Use your browser's cookies to make grabbing data from login-protected sites easier.
Intended for use with Python Requests http://python-requests.org
Accepts a URL from which it tries to extract a domain. If you want to force the domain,
@mehitabel
mehitabel / ca_assembly.json
Last active December 31, 2015 22:19
A quick scrape of the CA assembly site that makes it easier to answer a question that I always have.
{
"9-1-1 Service and Public Safety Communications": [
{
"dist": 5,
"name": "Frank Bigelow",
"url": "http://assembly.ca.gov/a5"
},
{
"dist": 64,
"name": "Isadore Hall, III",
@mehitabel
mehitabel / ca_senate.json
Created December 14, 2013 09:23
I found this information quite annoying to scrape from the legislature website and it's something I'm often curious about. Have fun!
{
"Agriculture": [
{
"dist": 5,
"name": "Senator Cathleen Galgiani (Chair)",
"url": "http://senate.ca.gov/sd05"
},
{
"dist": 12,
"name": "Senator Anthony Cannella (Vice Chair)",
@mehitabel
mehitabel / montgomery_ladder.py
Created December 13, 2013 04:59
The Montgomery ladder is a minor variation on the usual recursive squaring method for computing powers, which also uses O(log n) multiplications where n is the exponent. The difference here is that in either branch you always compute one square and one multiplication, so don't leak information through branch timing. I see this discussed for elli…
def bits(n):
b = []
while n > 0:
b.append(n % 2)
n >>= 1
return reversed(b)
def montgomery_pow(x, n):
a, b = 1, x
for x in bits(n):
@mehitabel
mehitabel / screwing around with gphoto2
Created November 9, 2013 22:05
Just having some fun here, maybe will be useful for people on macs or for a local webapp
This file has been truncated, but you can view the full file.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@mehitabel
mehitabel / Weighted Reservoir Sampling
Created October 24, 2013 20:15
A quick run through weighted reservoir sampling.
{
"metadata": {
"name": "Weighted Reservoir Sampling"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
from math import sqrt
def std_dev_over_mean(n, p):
""" increment a counter by 1/p with probability p, n times. (independently) """
q = 1 - p
var = n * q / p
return sqrt(var) / n
@mehitabel
mehitabel / CountMinSketch.ipynb
Created August 16, 2013 23:39
very quick sketch of count-min-sketch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def harmonic_mean(xs):
return 1.0 / sum(1.0 / x for x in xs)
def harmonic_sum(xs):
return len(xs) * harmonic_mean(xs)
def hll_style_composite(xs, alpha):
return alpha * harmonic_sum(2.0**x for x in xs)
# computed the integral suggested in the original hyper log log paper
@mehitabel
mehitabel / probcount
Last active December 20, 2015 14:09
probabilistic counting basics
{
"metadata": {
"name": "Intro to Probabilistic Counting"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{