Skip to content

Instantly share code, notes, and snippets.

View goutomroy's full-sized avatar

Goutom Roy goutomroy

View GitHub Profile
def check_balance(expression):
open_list = ['(', '[', '{']
close_list = [')', ']', '}']
stack = []
for c in expression:
if c in open_list:
stack.append(c)
elif c in close_list:
pos = close_list.index(c)
if len(stack) > 0 and stack[-1] == open_list[pos]:
import time
import random
from threading import Thread
class Worker(Thread):
def __init__(self, number):
Thread.__init__(self)
self._number = number
def run(self):
import time
import random
from multiprocessing import Process
class Processor(Process):
def __init__(self, number):
Process.__init__(self)
self._number = number
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
p = Pool(5)
print(p.map(f, [1, 2, 3]))
import concurrent.futures
import urllib.request
from time import sleep
URLS = ['http://www.foxnews.com/',
'http://www.cnn.com/',
'http://europe.wsj.com/',
'http://www.bbc.co.uk/',
'http://some-made-up-domain.com/']
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
def __str__(self):
return self.name
@property
def url(self):
return 'author/' + str(self.id)
class Meta(type):
"""
when
class MyClass(metaclass=Meta):
pass
is encountered type's __call__ method is called and from that Meta's __prepare__, __new__, __init__
is called one by one.
"""