Skip to content

Instantly share code, notes, and snippets.

#/usr/bin/env python
import math
class RunningCorrelation:
def __init__(self):
self.n = 0.0
self.mean_x = 0.0
self.mean_y = 0.0
self.m2_x = 0.0
self.m2_y = 0.0
10406 #fuck
3172 #fuckouttahere
3062 #fuckinfollow
2970 #fuckit
2303 #fuckyou
1573 #fuckgfw
1551 #fuckyeah
1436 #fuckery
1273 #fucking
988 #fuckoff
@pims
pims / Efficient_model_memcaching.py
Created November 3, 2010 15:31
Efficient model memcaching with protobuf
#!/usr/bin/env python
# http://blog.notdot.net/2009/9/Efficient-model-memcaching
from google.appengine.api import memcache
from google.appengine.ext import db
def serialize_entities(models):
if models is None:
return None
"""
from : http://stackoverflow.com/questions/101742/how-do-you-access-an-authenticated-google-app-engine-service-from-a-non-web-pyt
"""
import os
import urllib
import urllib2
import cookielib
users_email_address = "billy.bob@gmail.com"
users_password = "billybobspassword"
"""
from : http://amix.dk/blog/post/19592
"""
from redis_wrap import *
#--- Edges ----------------------------------------------
def add_edge(from_node, to_node, system='default'):
edges = get_set( from_node, system=system )
edges.add( to_node )
/// http://www.fsguy.com/2010-08-24_how-to-download-stock-quotes-from-google-finance-with-fsharp
/// Objectives:
/// - It should work asynchronously
/// - The executing thread shouldn’t be blocked during download so we could run this operation even on a UI thread without locking it
/// - Stock quotes should be downloaded in parallel
/// - But no more than 5 download streams at any particular moment in time
/// - Downloaded quotes should be parsed in parallel
/// - In order to utilize the available hardware resources efficiently
/// - Log actions & exceptions
#!/usr/bin/env python
import random
import re
"""
username,following_count,followers_count,question_answered,questions_asked,registered_days_ago,spam
"""
data = [
('pims',44,61,225,50,200,0),
('joe1234',350,1,0,200,50,1),
@pims
pims / gist:836788
Created February 21, 2011 07:50
Similarity (tanimoto coefficient) between a and all the letters in the alphabet for Arial bold 10px
('a', 'a', 1.0)
('a', 'u', 0.70833333333333337)
('a', 'n', 0.69565217391304346)
('a', 'e', 0.68181818181818177)
('a', 'z', 0.65000000000000002)
('a', 'o', 0.625)
('a', 'x', 0.61904761904761907)
('a', 'p', 0.6071428571428571)
('a', 'q', 0.55172413793103448)
('a', 'c', 0.54166666666666663)
@pims
pims / kmeans.py
Created May 29, 2011 05:19
Naive python translation of https://gist.github.com/995804
#!/usr/bin/env python
import sys
from math import sqrt
from random import random
"""
Naive python translation of https://gist.github.com/995804
Public domain.
"""
# https://github.com/attractivechaos/plb/blob/master/sudoku/incoming/sudoku-bb.py
# Boris Borcic 2006
# Quick and concise Python 2.5 sudoku solver
#
w2q = [[n/9,n/81*9+n%9+81,n%81+162,n%9*9+n/243*3+n/27%3+243] for n in range(729)]
q2w = (z[1] for z in sorted((x,y) for y,s in enumerate(w2q) for x in s))
q2w = map(set,zip(*9*[q2w]))
w2q2w = [set(w for q in qL for w in q2w[q]) for qL in w2q]