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
"""Build the timefunc decorator.""" | |
import time | |
import functools | |
def timefunc(func): | |
"""timefunc's doc""" | |
@functools.wraps(func) |
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
@dataclass | |
class Person: | |
name: str # mandatory | |
def __init__(self, **kwargs): | |
names = set([f.name for f in fields(self)]) | |
for k, v in kwargs.items(): | |
setattr(self, k, v) # dynamically create class fields by passed dict fields |
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
#Merge even and odd numbers | |
even = (i for i in range(1,100) if i % 2 == 0) | |
odd = (i for i in range(1,100) if i % 2 != 0) | |
def imerge(a, b): | |
for i, j in zip(a,b): | |
yield i | |
yield j |
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
import subprocess | |
import shutil | |
packages = [ | |
'chromium', | |
'git', | |
'mc', | |
'ntp', | |
'pacaur', | |
'snapd', |
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
import time | |
from random import random | |
import json | |
from multiprocessing import Pool | |
import redis | |
r = redis.StrictRedis(host='localhost', port=6379, db=0) | |
queue_key = 'queue' |
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
import time | |
from random import random | |
import json | |
import eventlet | |
eventlet.monkey_patch(thread=True) | |
import redis | |
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
#install virtualenv | |
pip install virtualenv | |
cd my_project_folder | |
#create virtualenv | |
virtualenv -p /usr/bin/python3 virtualenv_name | |
#activate virtualenv | |
source my_project/bin/activate |