Skip to content

Instantly share code, notes, and snippets.

@szastupov
szastupov / event_bus.py
Created July 6, 2016 12:35
Event bus using PostgreSQL's LISTEN
import asyncio
import logging
from sqlalchemy import text
logger = logging.getLogger(__name__)
class PGEventBus:
def __init__(self):
{
"bold_folder_labels": true,
"caret_style": "wide",
"color_scheme": "Packages/User/SublimeLinter/One Dark (Flake8Lint) (SL).tmTheme",
"enable_tab_scrolling": false,
"ensure_newline_at_eof_on_save": true,
"fold_buttons": false,
"font_size": 14,
"ignored_packages":
[
async def main_loop():
req = await get_request()
msg = req["msg"]
await db.insert(msg)
await post("https://parse.com/...", msg)
return Response("Ok")
import os
from fabric.api import *
CWD=os.path.basename(os.getcwd())
def deploy(bot=CWD):
with cd("/home/stepan/%s" % bot):
run("git pull")
run("git submodule update")
sudo("systemctl restart %s" % bot)
@szastupov
szastupov / pbar.py
Created June 11, 2015 23:56
Simple python progress bar
def progress(perc):
bar = "\r[{0:<50}] {1}%".format("=" * int(perc/2), perc)
sys.stdout.write(bar)
sys.stdout.flush()
from nodebox.graphics import *
from math import sin, pi
class Vis(object):
def __init__(self):
self.t = 0
self.s = 8
self.color = Color(77, 77, 255, 200, base=255)
def draw(self, canvas):
from nodebox.graphics import *
from random import randint, choice, uniform
SIZE = (1280, 720)
class Circle(object):
def __init__(self):
self.x = randint(0, SIZE[0])
self.y = randint(0, SIZE[1])
self.color = [255, 204, 34, randint(20, 150)]
from __future__ import division, print_function
from nodebox.graphics import *
from random import randint, getrandbits, uniform
from collections import deque
SIZE = (1280, 800)
LAYERS = 20
STARS_COLOR = Color(189, 155, 0, 255, base=255)
WINDOWS_COLOR = Color(189, 155, 0, 255, base=255)
from nodebox.graphics import *
from random import randint, choice, uniform
SIZE = (1280, 720)
class Circle(object):
def __init__(self):
self.x = randint(0, SIZE[0])
self.y = randint(0, SIZE[1])
self.color = [255, 204, 34, randint(20, 150)]
var zmq = require('../../')
, sock = zmq.socket('push');
sock.bindSync('tcp://127.0.0.1:5556');
setInterval(function(){
console.log('sending pub');
sock.send('10001 some pub');
}, 500);