Skip to content

Instantly share code, notes, and snippets.

@t33chong
t33chong / dependency-upgrades
Last active September 13, 2015 20:59
lita-github rspec failures
tristan@15th:~/Code/lita-dev/workspace/lita-github$ bi
Resolving dependencies...
Using rake 10.4.2
Using addressable 2.3.8
Using ast 2.1.0
Using parser 2.2.2.6
Using astrolabe 1.3.1
Using bundler 1.10.6
Using docile 1.1.5
Using json 1.8.3
@t33chong
t33chong / temp.rb
Created August 31, 2015 23:44
lita http.post debugging
module Lita
module Handlers
class Temp < Handler
http.post '/foo/:bar', :foo
def foo(request, response)
bar = request.env['router.params'][:bar]
baz = request.params['baz']
response.write("#{bar}\n#{baz}")
end
@t33chong
t33chong / get_location_uid.py
Created July 15, 2014 01:48
Is there a way to avoid having to select in order to get the UID after inserting a new row?
def get_location_uid(name, country_code):
# TODO: DRY, figure out a better way to do this
cursor.execute("SELECT uid FROM location WHERE name = '%s' AND country_code = '%s'" % (name, country_code))
result = cursor.fetchone()
if result is not None:
return result[0]
cursor.execute("INSERT INTO location (name, country_code) VALUES ('%s', '%s')" % (name, country_code))
db.commit()
cursor.execute("SELECT uid FROM location WHERE name = '%s' AND country_code = '%s'" % (name, country_code))
result = cursor.fetchone()
@t33chong
t33chong / funnyfinder.py
Created June 2, 2014 03:36
Heuristic to parse IRC logs for humorous content
import os
import re
DIR = '' # Directory containing chat logs
FILENAMES = ('#python',) # Substring that chat logs to searched should contain
NICKS = ('tristaneuan',) # Nicknames expected to be upvoted
LAUGHS = ('[ha]{6,}', '[lo]{6,}', 'lmao', 'lmfao', 'rofl')
fileregex = re.compile('|'.join(FILENAMES))
laughregex = re.compile('|'.join(LAUGHS), flags=re.I)
@t33chong
t33chong / disjoint.py
Created November 27, 2013 05:39
My textbook claims the worst case runtime of this function is O(n^2). I don't understand why - there are 3 nested loops, shouldn't it be O(n^3)?
def disjoint2(A, B, C):
"""Return True if there is no element common to all three lists."""
for a in A:
for b in B:
if a == b: # only check C if we found match from A and B
for c in C:
if a == c # (and thus a == b == c)
return False # we found a common value
return True # if we reach this, sets are disjoint