Skip to content

Instantly share code, notes, and snippets.

View onjin's full-sized avatar

Marek Wywiał onjin

View GitHub Profile
[gui]
editor = gvim
[color]
ui = auto
diff = auto
branch = always
status = off
[color "branch"]
current = yellow reverse
local = yellow
@onjin
onjin / terminal_size_linux.py
Created March 24, 2014 07:32
get current terminal size on linux with python
import os
rows, columns = os.popen('stty size', 'r').read().split()
@onjin
onjin / tuple_to_namedtuple.py
Created March 24, 2014 10:14
tuple to namedtuple
from collections import namedtuple
# magic data accessed with magic numbers, f.i.:
# print "{} {}".format(row[2], row[3])
row = ('SS', 'asdf', 12.3, 'USD')
# let's create something self describing
Price = namedtuple('Price', ['symbol', 'name', 'amount', 'currency'])
import re
p = re.compile('^(?P<head>\d{2})(?:[-\s]?(?P<tail>\d{3})?$)')
zip = "-".join(p.match('11123').groups())
print zip
zip = "-".join(p.match('11-123').groups())
print zip
@onjin
onjin / lazyproperty.py
Created April 4, 2014 16:02
lazy property
import math
class lazyproperty(object):
def __init__(self, func):
self.func = func
def __get__(self, instance, cls):
if instance is None:
return self
@onjin
onjin / droppub.py
Last active August 29, 2015 13:58
Push and publish on dropbox from shell
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Put and publish given file to dropbox.
Install
-------
1. open https://www.dropbox.com/developers/apps and register app
2. pip install dropbox
from collections import defaultdict
from contextlib import contextmanager
class Exchange:
def __init__(self):
self._subscribers = set()
def attach(self, task):
self._subscribers.add(task)
#!/bin/bash
# firefox profile runner
# ln -s ff-runner ff-profilename to run specific profile
FIREFOX=/usr/bin/firefox
PROFILE=`basename $0|cut -d\- -f2`
${FIREFOX} -P ${PROFILE} --no-remote
@onjin
onjin / shakeit.py
Last active August 29, 2015 14:07
#!/usr/bin/env python
# encoding: utf-8
import random
import fileinput
def shakeit(word):
if len(word) < 3:
return word
@onjin
onjin / Makefile
Created December 4, 2014 08:15
long running job notification
job:
longjob()
if [ -f /usr/bin/notify-send ]; then /usr/bin/notify-send -t 60000 -u critical -a "frontend" -c docker,frontend "Docker build" "Frontend docker build at<br/>`pwd`"; fi