Setup
- Step 1 - The Project
- Step 2 - Fork the Project
- Step 3 - Get the Clone URL
- Step 4 - Create the Cloud9 Workspace
Virtualenvs
| import functools | |
| from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor | |
| def check_only_integers(fn): | |
| """Very simple decorator that prevents other than integers to be passed | |
| to the decorated function. Just for demonstration purposes. | |
| """ | |
| @functools.wraps(fn) | |
| def wrapped(*args): |
| def get_repo_stars(org, repo): | |
| url = 'https://api.github.com/repos/{org}/{repo}'.format( | |
| org=org, repo=repo) | |
| print("GET ", url) | |
| resp = requests.get(url) | |
| return resp.json()['stargazers_count'] | |
| params = [ | |
| ('requests', 'requests'), | |
| ('requests', 'httpbin'), |
| """ | |
| This one "Doesn't" work. Seems like `map` doesn't play well with | |
| `as_completed`. | |
| """ | |
| import time | |
| import random | |
| from concurrent.futures import ThreadPoolExecutor, as_completed | |
| def my_sleep(n=1000): |
| from django.http import HttpResponseForbidden | |
| from django.http import JsonResponse | |
| from pusher import Pusher | |
| class PusherAuthStrategy: | |
| def __init__(self, namespace): | |
| self.namespace = namespace |
| import re | |
| TIMEDELTA_REGEX = (r'((?P<days>-?\d+)d)?' | |
| r'((?P<hours>-?\d+)h)?' | |
| r'((?P<minutes>-?\d+)m)?') | |
| TIMEDELTA_PATTERN = re.compile(TIMEDELTA_REGEX, re.IGNORECASE) | |
| def parse_delta(delta): |
| from datetime import datetime, date, time, timedelta | |
| from pytz import timezone | |
| START_DATE = date(2017, 10, 9) | |
| START_TIME = time(8, 0) | |
| START_DATETIME = datetime.combine(START_DATE, START_TIME) | |
| INTERVAL_IN_HOURS = 2 | |
| OPTION_TEMPLATE = "{start} - {end} ({tz})" |
| class Tuple(tuple): | |
| def __getattr__(self, name): | |
| def _int(val): | |
| try: | |
| return int(val) | |
| except ValueError: | |
| return False | |
| if not name.startswith('_') or not _int(name[1:]): | |
| raise AttributeError("'tuple' object has no attribute '%s'" % name) |
| def range(x, y=None): | |
| if y is None: | |
| y = x | |
| x = 0 | |
| while x < y: | |
| yield x # This is the generator | |
| x += 1 | |
| def range(x, y=None): | |
| results = [] | |
| if y is None: | |
| y = x | |
| x = 0 | |
| while x < y: | |
| results.append(x) | |
| x += 1 | |
| return results |