Skip to content

Instantly share code, notes, and snippets.

View petrushev's full-sized avatar

Baze Petrushev petrushev

View GitHub Profile
@petrushev
petrushev / gist:8932942
Created February 11, 2014 11:03
tickets notifications
CREATE OR REPLACE FUNCTION trigger_notify()
RETURNS trigger AS
$BODY$
BEGIN
IF NEW.state = 'pending' THEN
EXECUTE 'NOTIFY tickets_pending'||NEW.id::text;
RETURN NULL;
END IF;
END;
$BODY$
@petrushev
petrushev / hub.py
Created June 10, 2012 14:40
[nsnd struga] Simple hub/worker architecture
import zmq
from json import loads, dumps
HUB_ADDR = 'tcp://*:5555'
DEALER_ADDR = 'tcp://*:5566'
def main():
num = 1
@petrushev
petrushev / worker.py
Created June 10, 2012 14:41
[nsnd struga] Simple hub/worker architecture
import zmq
from time import sleep
from random import random
from json import loads, dumps
HUB_ADDR = 'tcp://127.0.0.1:5555'
DEALER_ADDR = 'tcp://127.0.0.1:5566'
import sys
@petrushev
petrushev / ircwatch.py
Created June 14, 2012 00:36
Irc logger on the command line
import requests
from time import sleep
from simplejson import loads, dumps
from datetime import datetime
BASE = 'http://irc.softver.org.mk/api/_changes'
DEFAULT_PARAMS = {'feed':'longpoll', 'heartbeat':'30000', 'include_docs':'true',
'filter':'log/channel', 'channel':'lugola'}
@petrushev
petrushev / collate_specific.py
Created June 21, 2012 11:59
Sort list of strings by a specific locale
# -*- coding: utf-8 -*-
import locale
default_locale = locale.getlocale(locale.LC_COLLATE)
def sort_strings(strings, locale_=None):
if locale_ is None:
return sorted(strings)
locale.setlocale(locale.LC_COLLATE, locale_)
sorted_strings = sorted(strings, cmp=locale.strcoll)
@petrushev
petrushev / matplotlibrc
Created July 25, 2012 12:25 — forked from huyng/matplotlibrc
my default matplotlib settings
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@petrushev
petrushev / crawl_mp.py
Created October 11, 2012 20:35
Get large thumbnails from imgur album
# Get name and image of mps from sobranie.mk and put them in `PATH`
import requests as rq
from lxml.html import fromstring
PATH = 'target'
base = 'http://www.sobranie.mk/'
start = base+'?ItemID=C5223B907BD9D247A9245C0C30C2E6AE'
def main():
@petrushev
petrushev / mudrecot.py
Created October 13, 2012 16:41
Create custom `mudrecot` meme
# -*- coding: utf-8 -*-
"""Create custom `mudrecot` meme"""
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
font_path = "/usr/share/fonts/TTF/LiberationSans-Bold.ttf"
@petrushev
petrushev / qpac.py
Created October 28, 2012 14:12
Get missing optional dependencies and see which packages need them
from subprocess import check_output
EMPTY = tuple()
def get_pkgs():
"""Query local packages"""
tmp = check_output(["pacman", "-Qi"])
li = tmp.strip().split("\n\n")
@petrushev
petrushev / point_in_polygon.py
Created April 23, 2013 23:56
Determine if a point is inside a given polygon or not Polygon is a list of (x,y) points. Uses the 'Ray Casting' algorithm
def is_inside(polygon, point):
"""Determine if a point is inside a given polygon or not
Polygon is a list of (x,y) points.
Uses the 'Ray Casting' algorithm"""
x, y = point
n = len(polygon)
inside = False