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 | |
| def timeit(method): | |
| def timed(*args, **kw): | |
| ts = time.time() | |
| result = method(*args, **kw) | |
| te = time.time() | |
| print '%r (%r, %r) %2.2f sec' % \ |
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
| def formater(simbol, text): | |
| doc.delete_selected_lines() | |
| doc.insert_text("{n}{t}".format(n=simbol,t=text)) | |
| TEXT = doc.get_line_text() | |
| if TEXT[0] == "[": | |
| if TEXT[0:3] == "[ ]": | |
| formater("[+]",TEXT[3:]) | |
| elif TEXT[0:3] == "[+]": | |
| formater("[-]",TEXT[3:]) |
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
| def multiple_replace(dict, text): | |
| # Create a regular expression from the dictionary keys | |
| regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys()))) | |
| # For each match, look-up corresponding value in dictionary | |
| return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text) |
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
| def singleton(cls): | |
| obj = cls() | |
| # Always return the same object | |
| cls.__new__ = staticmethod(lambda cls: obj) | |
| # Disable __init__ | |
| try: | |
| del cls.__init__ | |
| except AttributeError: | |
| pass | |
| return cls |
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
| """ | |
| =========== | |
| Description | |
| =========== | |
| Simple script to copy and gzip static web files to an AWS S3 bucket. S3 is great for cheap hosting of static web content, but by default it does not gzip CSS and JavaScript, which results in much larger data transfer and longer load times for many applications | |
| When using this script CSS and JavaScript files are gzipped in transition, and appropriate headers set as per the technique described here: http://www.jamiebegin.com/serving-compressed-gzipped-static-files-from-amazon-s3-or-cloudfront/ | |
| * Files overwrite old versions |
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
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| from psycopg2 import connect | |
| from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT | |
| class PostgresDbHelper(object): | |
| def __init__(self, host, user, password, dbname): | |
| self.host = host |
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 asyncio | |
| from contextlib import closing | |
| import aiohttp | |
| async def download_file(session: aiohttp.ClientSession, url: str): | |
| async with session.get(url) as response: | |
| assert response.status == 200 | |
| # For large files use response.content.read(chunk_size) instead. |
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 asyncio | |
| import aiofiles | |
| import aiohttp | |
| import logging | |
| import re | |
| import sys | |
| import os | |
| import lxml.html |
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 shutil | |
| import mimetypes | |
| from os import listdir | |
| from os.path import isfile, join | |
| ORIGIN = r"C:\Users\Konstantin\Downloads\\" # Change these. Unless your system | |
| # happens to have the same configuration. | |
| MUSIC_DESTINATION = r"C:\Users\Konstantin\Music\\" | |
| PICTURE_DESTINATION = r"C:\Users\Konstantin\Pictures\\" | |
| PDF_DESTINATION = r"C:\Users\Konstantin\Documents\\" |
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 os | |
| from log_exceptions import log_exceptions | |
| def throw_something(a1, a2): | |
| raise Exception('Whoops!') | |
| @log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None) | |
| def my_function(arg1, arg2): | |
| throw_something(arg1 + 24, arg2 - 24) |