Skip to content

Instantly share code, notes, and snippets.

View shvechikov's full-sized avatar

Leonid Shvechikov shvechikov

View GitHub Profile
@shvechikov
shvechikov / vim_last_position
Created July 6, 2010 15:08
Vim: Return to last edit position
" Put to .vimrc
" Return to last edit position (You want this!) *N*
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
@shvechikov
shvechikov / super_custom_chunkify.py
Created September 2, 2010 21:17
Super Chunkify
# -*- coding: utf-8 -*-
"""
На работе как-то раз появилась довольно стандартная задача:
написать генаратор, который отдаёт элементы из некого итератора пачками
по n элементов.
Дополнительное условие:
Не возвращать пустой список на последней итерации (возникает, когда
общее количество элементов кратно размеру пачки).
В общем, как-то её в тот раз решили, хоть и не слишком красиво.
@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'
@shvechikov
shvechikov / utc_timestamp.py
Last active October 1, 2015 07:18
Using timezones in python
import time
import datetime
import pytz
def utc_timestamp(dt, tz):
tz = pytz.timezone(tz)
return int(time.mktime(dt.replace(tzinfo=tz).utctimetuple()))
print utc_timestamp(datetime.datetime.now(), 'Europe/Moscow')
@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:
@shvechikov
shvechikov / simple-git-branching-model.md
Last active October 23, 2020 06:17
a simple git branching model

a simple git branching model

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@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 / 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 ##
###################################################
[alias]
st = status
ci = commit
ca = commit --amend
co = checkout
br = branch
d = diff
dc = diff --cached
lg = log -p
lol = log --graph --decorate --pretty=oneline --abbrev-commit