Skip to content

Instantly share code, notes, and snippets.

View shvechikov's full-sized avatar

Leonid Shvechikov shvechikov

View GitHub Profile
@shvechikov
shvechikov / fmtcsv.py
Created March 27, 2012 12:06 — forked from astanin/fmtcsv.py
Pretty-print CSV file with fixed width columns.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Usage: %prog [width [columns]] < table.csv
Pretty-print CSV file with fixed width columns.
Arguments:
def find_best_subarray(array):
best_sum = 0
best_start = 0
best_end = 0
cur_sum = 0
cur_start = 0
cur_end = 0
for i, x in enumerate(array):
@shvechikov
shvechikov / pyhash.py
Created December 9, 2013 18:09 — forked from jbenet/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 / mux.py
Created December 17, 2013 21:07
Mux Youtube DASH audio and video
from __future__ import unicode_literals
import sys
from sh import ffmpeg
from unipath import Path
_, src_dir, dest_dir = sys.argv
src_dir = Path(src_dir)
@shvechikov
shvechikov / upprint.py
Created February 27, 2012 09:11
UnicodePrettyPrinter
# -*- coding: utf-8 -*-
import sys
from pprint import PrettyPrinter
class UnicodePrettyPrinter(PrettyPrinter):
"""Unicode-friendly PrettyPrinter
Prints:
- u'привет' instead of u'\u043f\u0440\u0438\u0432\u0435\u0442'
"""
This module is no more needed. It could be useful for implementing Django-level authentication.
Now it works using DRF-level authentication -- dating.apps.mongo_auth.authentication.MongoTokenAuthentication.
So it's here JFYI.
"""
# from django.contrib import auth
from django.utils.functional import SimpleLazyObject
from .models import User, AnonymousUser
@shvechikov
shvechikov / signed_s3_upload.py
Created April 28, 2016 13:10
Upload files to S3 using generated signed URLs
import requests
from boto.s3.connection import S3Connection
c = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KET)
data = 'file content'
filename = 'dir/name.txt'
bucket_name = 'your-bucket-name'
headers = {'Content-Type': 'text/plain'}
@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"
@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 / typograph.py
Created February 17, 2014 04:03
Evgeny Muravjev Typograph, http://mdash.ru
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
###################################################
## Evgeny Muravjev Typograph, http://mdash.ru ##
## Version: 3.2-py (beta) ##
## Release Date: February 6, 2014 ##
## Authors: Evgeny Muravjev & Alexander Drutsa ##
###################################################