Skip to content

Instantly share code, notes, and snippets.

@tomwolber
tomwolber / collections
Created September 30, 2011 15:47
collections.Counter example
>>> from collections import Counter
>>> c = Counter()
>>> c['t'] = 3
>>> c
Counter({'t': 3})
>>> c['r'] = 2
>>> c
Counter({'t': 3, 'r': 2})
>>> c['r'] += 1
>>> c
@tomwolber
tomwolber / gist:1334814
Created November 2, 2011 20:30
Fraction Shit
from fractions import Fraction
def fraz(r1,t1,r2,t2):
z = Fraction(r1,t1) + Fraction(r2,t2)
n = z.numerator/z.denominator
return n
if __name__ == "__main__":
print fraz(10,5,6,2)
@tomwolber
tomwolber / euc.py
Created November 11, 2011 19:26
euc.py
a = input("enter first number: ")
b = input("enter second number: ")
while b != 0:
if a > b:
a -= b
else:
b -= a
print a
@tomwolber
tomwolber / sleep.py
Created November 11, 2011 21:38
python sleeeeeeep
import time
import sys
// This sleeps for 10 secs, then prints a bunch of stars
for i in range(10):
time.sleep(1)
print '*',
// Same here
In [16]: for i in range(10):
@tomwolber
tomwolber / equi.py
Last active December 12, 2015 07:09
A = [-7, 1, 5, 2, -4, 3, 0]
def equi(A):
s = [] # array of equilibrium indices
for a in range(len(A)-1): # loop with '0 index' hack
x = A[:a+1] # split 'left' of the current index
y = A[a+2:] # split 'right' of the current index
n1 = 0 # this will be the total of the 'left' numbers
import math
# quick test cases
A = [-7, 1, 5, 2, -4, 3, 0]
B = [1, 2, 3, 4, 3, 2, 1]
C = [99, 0, 66, 32, 1]
D = [1, -1, 1, -1, 1, -1, 1]
E = [0,0,0]
F = [0,53,9]
G = [0,1,-1]
@tomwolber
tomwolber / god.snippet
Created June 7, 2013 05:16
my new favorite @TextExpander snippet for reaching out to coworkers on Skype
Are You There %filltext:name=field 1:default=God%? It's Me, Tommy
import os
import gspread
import json
gpass = os.environ['GPASS']
gc = gspread.login('[email protected]', gpass)
sh = gc.open('irobot_FE_Translation_Final')
worksheet = sh.get_worksheet(0)
thekeys = worksheet.col_values(1)
request.get({url : 'https://lasamobi.com.br/LatLong/json/lojas.json', rejectUnauthorized: false }, function (error, response, body) {
console.log('request');
storeData = JSON.parse(body);
});
if (/categories/.test($('body').data('path')) && $('nav.link-bar h3').length === 1) {
$(window).on('SSReady', function(){
//soysauce.widgets[0].button.click();
//$('nav.link-bar').data('ss-state', 'open');
//$('nav.link-bar .subcategories').data('ss-state', 'open');
//$('nav.link-bar h3').data('ss-state', 'open');
});
}