Skip to content

Instantly share code, notes, and snippets.

View shvechikov's full-sized avatar

Leonid Shvechikov shvechikov

View GitHub Profile
[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
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]
def find(diamonds, share, shift=0, skip=()):
for i in range(shift, len(diamonds)):
if i in skip:
continue
d = diamonds[i]
if d > share:
continue
from inspect import getattr_static
class dep:
name = None
def __init__(self, type):
self.type = type
__author__ = 'archeg'
import httplib
import urllib
import urllib2
import re
def URLRequest(url, params, headers, method="GET"):
if method == "POST":
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []
jsoneditor.js:4923 []

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

def add_preview_for(*fields):
"""
This is a decorator for model classes that adds preview methods.
So instead of manually adding preview methods:
>>> class Student(models.Model):
... photo = models.ImageField()
... icon = models.ImageField()
...
@shvechikov
shvechikov / super_custom_chunkify.py
Created September 2, 2010 21:17
Super Chunkify
# -*- coding: utf-8 -*-
"""
На работе как-то раз появилась довольно стандартная задача:
написать генаратор, который отдаёт элементы из некого итератора пачками
по n элементов.
Дополнительное условие:
Не возвращать пустой список на последней итерации (возникает, когда
общее количество элементов кратно размеру пачки).
В общем, как-то её в тот раз решили, хоть и не слишком красиво.
@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')