Skip to content

Instantly share code, notes, and snippets.

View troolee's full-sized avatar
🇺🇦
Be brave like Ukraine

Pavel Reznikov troolee

🇺🇦
Be brave like Ukraine
View GitHub Profile
@troolee
troolee / date_utils.py
Created August 10, 2010 07:46
Python datetime utils
import calendar
from datetime import datetime, date
def inc_months(d, value, specifying_date=None):
'''
Adds `value` of months to the date `d`. If `specifying_date` is passed, the day of resulting month
will be taken from the `specifying_date` instead of `d`.
>>> inc_months(datetime(2010, 3, 31), 0)
@troolee
troolee / counties.json
Created September 21, 2010 13:49
List of US Counties (taken from http://www.his.com/~wfeidt/Misc/usc_ind.html)
{
"WA": {
"name": "Washington",
"counties": [
"Adams",
"Asotin",
"Benton",
"Chelan",
"Clallam",
"Clark",
@troolee
troolee / .bashrc
Created April 23, 2011 12:36
prompt
### PROMPT ####################
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
@troolee
troolee / gist:957832
Created May 5, 2011 20:18
split_on_packets
def split_on_packets(iterable, packet_size):
'''
>>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> list(split_on_packets(a, 3))
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11]]
>>> list(split_on_packets(a, 13))
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]
>>> list(split_on_packets(a, 1))
@troolee
troolee / gist:1140516
Created August 11, 2011 19:23
Automatically creates user's profile in django
from django.contrib.auth.models import User, SiteProfileNotAvailable
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.signals import post_init
from django.dispatch.dispatcher import receiver
@receiver(post_init, sender=User)
def user_post_init(sender, instance, **kwargs):
def get_profile():
# -*- coding: utf-8 -*-
#
# Author: Pavel Reznikov <[email protected]>
# Created: 10/6/11
#
# Id: $Id$
from datetime import datetime, timedelta
@troolee
troolee / gist:6edfea5857f4cd73e6f1
Created March 2, 2015 06:19
gridstack-ie8.css
.grid-stack > .grid-stack-item { min-height: 60px }
.grid-stack > .grid-stack-item[data-gs-height="1"] { height: 60px }
.grid-stack > .grid-stack-item[data-gs-height="2"] { height: 140px }
.grid-stack > .grid-stack-item[data-gs-height="3"] { height: 220px }
.grid-stack > .grid-stack-item[data-gs-height="4"] { height: 300px }
.grid-stack > .grid-stack-item[data-gs-height="5"] { height: 380px }
.grid-stack > .grid-stack-item[data-gs-height="6"] { height: 460px }
.grid-stack > .grid-stack-item[data-gs-height="7"] { height: 540px }
.grid-stack > .grid-stack-item[data-gs-height="8"] { height: 620px }
.grid-stack > .grid-stack-item[data-gs-height="9"] { height: 700px }
# pylint: disable=E0401,E1002
import array
import functools
import dbus
import dbus.exceptions
import dbus.mainloop.glib
import dbus.service
import pprint
try:
from gi.repository import GObject as gobject