Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
"""
Runs a simple pubsub listener which pushes to clients via sockjs
Based on https://gist.github.com/mrjoes/3284402
Eventually I'd like to have one redis connection listening on user_* channel
and pushing messages ONLY to that user's client.
Setup:
virtualenv testenv
@Pentusha
Pentusha / waiter.py
Last active August 29, 2015 14:00
Function for tracking state of async tasks unexpectedly used to sort a list. Dumbest sorting ever.
def waiter(tasks):
""" async tasks to sync
tasks -> yield + tasks_wo_result
1 2 3 4
[0,0,0,0] -> [ ] + [0,0,0,0] 1, 3 solved
[1,0,3,0] -> [1,3 ] + [ 0, 0] 2 solved
[ 2, 0] -> [1,3,2 ] + [ 0] 4 solved
[ 4] -> [1,3,2,4] + [ ]
"""
while tasks:
@Pentusha
Pentusha / chunk_numeration.py
Created October 29, 2015 14:01
chunk_numeration.py
from itertools import zip_longest
from pprint import pprint
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
def chunks(iterable, n, fill_value=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fill_value)
c1 = list(chunks(a, 3))
('Platform:', 'Linux', '3.13.0-77-generic')
('Python version:', sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0))
('SAP NW RFC:', (7200, 0, 33))
('PyRFC:', '1.9.4\r\n')
000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFE
0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9
from typing import Iterator
from functools import wraps, singledispatch
def wrap(begin: bytes=None, end: bytes=b'e'):
def outer_wrapper(func):
@wraps(func)
def inner_wrapper(*args, **kwargs):
yield begin
yield from func(*args, **kwargs)
#! /bin/bash
BASE_URL='http://0.0.0.0:8000'
USERNAME='testtest'
PASSWORD='testtest'
ENV_NAME='env_dev'
PROJ_NAME='proj_demo'
APP_NAME='app_demo'
HHDEMO_2TABLES='hhdemo_2tables'
curl \
-s \
-X POST \
-H "Content-Type: application/json" \
-b "api_sessionid=$SESSION_ID" \
-d '{"scalar_bigint": 105, "scalar_numeric": 888.1, "scalar_smallint": 123, "scalar_real": 999.256, "scalar_double": 66.1256, "scalar_boolean": true, "scalar_bytea": "QQ==", "scalar_character": "k", "scalar_varchar": "hhh", "scalar_text": "fghfhh fhjfhjkl", "scalar_date": "2016-10-25", "scalar_timestamptz": "2016-12-12T12:12:12.12+0300", "scalar_integer": 55}' \
"$BASE_URL/api/v0.6/table/$HHDEMO_BASESCALARS/"
@Pentusha
Pentusha / hh_api_curl_builder.py
Last active March 21, 2017 16:09
pip3 install requests && python3 hh_api_curl_builder.py --resource hhdemo_2tables_2scalars_pg
from argparse import ArgumentParser
from getpass import getpass
from json import dumps
from os.path import expanduser, join, exists
from sys import exit, stdout
from yaml import load, dump
from requests import Session, codes
from pyrfc import Connection
from pprint import pprint
connection_info = {
'ashost': '...',
'client': '...',
'lang': '...',
'user': '...',
'passwd': '...',
@Pentusha
Pentusha / wat.py
Created June 15, 2017 11:58
cycle groups and sorting
class Cmp:
def __init__(self, value):
self._value = value
def __eq__(self, other: 'Cmp'):
return self._value == other._value
def __ne__(self, other: 'Cmp'):
return self._value != other._value