This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://algorithmia.com/algorithms/diego/AnalyzeTwitterUser | |
{ | |
"followers": 340, | |
"following": 415, | |
"is negative about": [ | |
{ | |
"country": 1, | |
"evil": 1, | |
"kumailn": 2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
denominations = [25, 10, 1, 100] | |
change = 66 | |
for d in sorted(denominations, reverse=True): | |
q, r = divmod(change, d) | |
print d, '*', q | |
change = r | |
# 100 * 0 | |
# 25 * 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A -> B | |
# A -> C | |
# B -> C | |
# B -> D | |
# C -> D | |
# D -> C | |
# E -> F | |
# F -> C | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TwoSum(object): | |
""" | |
find if the sum of any two numbers in a list equates | |
to a given number | |
""" | |
def __init__(self): | |
self.nums = [] | |
self.sum = 0 | |
def add_num(self, num): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
import functools | |
def _myfunc_with_one_arg(n): | |
return n ** 2 | |
def _myfunc_with_two_args(arg1, arg2, s): | |
return arg1 + arg2 + s | |
def ramifier(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'svalleru' | |
"""If 'YOU' can't solve it, you can't ask the interviewee to solve it ;)""" | |
class Dictionary(object): | |
"""Pure python implementation of a dictionary of fixed length""" | |
def __init__(self, size): | |
self.size = size | |
self.data = [[] for _ in xrange(size)] | |
#hash method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'svalleru' | |
class Observable(object): | |
def __init__(self, name): | |
self._name = name | |
self._observers = [] | |
def register_observer(self, observer): | |
self._observers.append(observer) | |
def notify_observers(self, msg): | |
for observer in self._observers: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'svalleru' | |
# simple script for network latency debugging | |
import time | |
from optparse import OptionParser | |
from urllib2 import Request, urlopen | |
def url_fetcher(url, count): | |
print "trying url:", url, "with retry count:", count | |
for attempt in range(1, count): | |
if attempt > 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'svalleru' | |
# Monkey patching | |
class Spam(object): | |
def __init__(self, name): | |
self._name = name | |
def beans(self): | |
print "Good morning, %s. Here are your delicious fried beans." % (self._name,) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sorts a dictionary based on value | |
from collections import OrderedDict | |
from random import choice, randint | |
import string | |
# generate random upper case string of given length | |
def generateRandomString(len): | |
return ''.join(choice(string.ascii_uppercase + string.digits) for _ in range(len)) | |
#create a dict with arbitrary K-Vs |
NewerOlder