Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonid Shvechikov shvechikov

View GitHub Profile
@shvechikov
shvechikov / vim_last_position
Created Jul 6, 2010
Vim: Return to last edit position
View vim_last_position
" Put to .vimrc
" Return to last edit position (You want this!) *N*
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
View super_custom_chunkify.py
# -*- coding: utf-8 -*-
"""
На работе как-то раз появилась довольно стандартная задача:
написать генаратор, который отдаёт элементы из некого итератора пачками
по n элементов.
Дополнительное условие:
Не возвращать пустой список на последней итерации (возникает, когда
общее количество элементов кратно размеру пачки).
В общем, как-то её в тот раз решили, хоть и не слишком красиво.
@shvechikov
shvechikov / upprint.py
Created Feb 27, 2012
UnicodePrettyPrinter
View upprint.py
# -*- 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 Oct 1, 2015
Using timezones in python
View utc_timestamp.py
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 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:
@shvechikov
shvechikov / simple-git-branching-model.md
Last active Oct 23, 2020
a simple git branching model
View simple-git-branching-model.md

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.

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 / mux.py
Created Dec 17, 2013
Mux Youtube DASH audio and video
View mux.py
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 Feb 17, 2014
Evgeny Muravjev Typograph, http://mdash.ru
View typograph.py
#!/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 ##
###################################################
View .gitconfig
[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