Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonid Shvechikov shvechikov

View GitHub Profile
@shvechikov
shvechikov / timed_code.py
Created Jul 9, 2018 — forked from lericson/timed_code.py
Python Timer Class - Context Manager for Timing Code Blocks
View timed_code.py
import logging
from contextlib import contextmanager
from timeit import default_timer
time_logger = logging.getLogger(__package__ + ".timer")
@contextmanager
def timed_code(name=None):
next_unit = iter(("s", "ms", "ns", "us")).next
msg = "section %s took" % (name,) if name else "section took"
@shvechikov
shvechikov / README.md
Last active Jul 20, 2018 — forked from snehesht/Concurrent HTTP Requests with Python3 and asyncio
Concurrent HTTP Requests with Python3 and asyncio
View README.md

Concurrent HTTP Requests with Python3 and asyncio

http://geekgirl.io/concurrent-http-requests-with-python3-and-asyncio/

My friend who is a data scientist had wipped up a script that made lots (over 27K) of queries to the Google Places API. The problem was that it was synchronous and thus took over 2.5 hours to complete.

Given that I'm currently attending Hacker School and get to spend all day working on any coding problems that interests me, I decided to go about trying to optimise it.

I'm new to Python so had to do a bit of groundwork first to determine which course of action was best.

View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View gist:6c339ddaf143ed5ac468
__author__ = 'archeg'
import httplib
import urllib
import urllib2
import re
def URLRequest(url, params, headers, method="GET"):
if method == "POST":
View gist:c28a08db6aac6f65a72e
from inspect import getattr_static
class dep:
name = None
def __init__(self, type):
self.type = type
View local.py
def my_local(init):
key = object()
def getter():
t = _app_ctx_stack.top
l = getattr(t, 'my_locals')
if l is None:
t.my_locals = l = {}
if key not in l:
l[key] = init()
return l[key]
View pyhash.py
#!/usr/bin/env python2.7
#
# Install this in your PATH as `pyhash`.
#
# curl https://gist.github.com/jbenet/6502583/raw/pyhash.py -o pyhash
# mv pyhash /usr/bin/local/pyhash
# chmod +x /usr/bin/local/pyhash
#
# If you want more cryptographic hashing functions, try the PassLib module.
#
@shvechikov
shvechikov / fmtcsv.py
Created Mar 27, 2012 — forked from astanin/fmtcsv.py
Pretty-print CSV file with fixed width columns.
View fmtcsv.py
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Usage: %prog [width [columns]] < table.csv
Pretty-print CSV file with fixed width columns.
Arguments: