Skip to content

Instantly share code, notes, and snippets.

Avatar

Leonid Shvechikov shvechikov

View GitHub Profile
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
View local.py
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]
View olimp_128.py
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
View gist:c28a08db6aac6f65a72e
from inspect import getattr_static
class dep:
name = None
def __init__(self, type):
self.type = type
View gist:6c339ddaf143ed5ac468
__author__ = 'archeg'
import httplib
import urllib
import urllib2
import re
def URLRequest(url, params, headers, method="GET"):
if method == "POST":
View json_editor_debug.log
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 []
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

View preview_decorator.py
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()
...
View super_custom_chunkify.py
# -*- coding: utf-8 -*-
"""
На работе как-то раз появилась довольно стандартная задача:
написать генаратор, который отдаёт элементы из некого итератора пачками
по n элементов.
Дополнительное условие:
Не возвращать пустой список на последней итерации (возникает, когда
общее количество элементов кратно размеру пачки).
В общем, как-то её в тот раз решили, хоть и не слишком красиво.
@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')