Skip to content

Instantly share code, notes, and snippets.

View shvechikov's full-sized avatar

Leonid Shvechikov shvechikov

View GitHub Profile
@shvechikov
shvechikov / README.md
Last active July 20, 2018 06:01 — forked from snehesht/Concurrent HTTP Requests with Python3 and asyncio
Concurrent HTTP Requests with Python3 and asyncio

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.

@shvechikov
shvechikov / timed_code.py
Created July 9, 2018 05:54 — forked from lericson/timed_code.py
Python Timer Class - Context Manager for Timing Code Blocks
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"
#!/bin/python3
def get_direction(n, m, x, y):
if y == 0 and x != n - 1:
return '>', n-x-1
if y == m - 1 and x != 0:
return '<', x
if x == 0:
return '^', y
if x == n - 1:
def print_matrix(matrix):
for line in matrix:
print(' '.join(map(str, line)))
def empty(n, m):
matrix = []
for i in range(m):
matrix.append(['.'] * n)
return matrix