Skip to content

Instantly share code, notes, and snippets.

View muzhig's full-sized avatar
👨‍💻
working

Arseniy Potapov muzhig

👨‍💻
working
View GitHub Profile
@muzhig
muzhig / fizzbuzz.py
Created January 16, 2018 13:52
Fizzbuzz
import itertools
def fizzbuzz():
for i in itertools.count(1):
fizz = i % 3 == 0
buzz = i % 5 == 0
if fizz and buzz:
yield 'fizz buzz'
elif fizz:
from bitcoinrpc.connection import BitcoinConnection
con = BitcoinConnection(host='127.0.0.1', port=18332, user='u', password='p')
destination_addr = 'mh5YsB8cSLT2NxLKkdaZANBqhLSDgMFgGj'
num_signatures = 2
signer_addr = 'mfcWQhBtWGPcSBPiPDeUJZ5n1Ud7XF2hSK'
additional_signer_addr = 'mr37a4xtZZByapa9neEPC3oYLxbEaFyCkP'
amount = 20.0
@muzhig
muzhig / rql.py
Created May 16, 2016 18:46
Fetch Rollbar Occurances via RQL
def start_rql(rql, access_token):
base_url = 'https://api.rollbar.com'
start_job_url = base_url + '/api/1/rql/jobs?access_token=' + access_token
body = json.dumps({'query_string': rql})
resp = requests.post(start_job_url, data=body, headers={'Content-Type': 'application/json'}).json()
get_job_res = '{}/api/1/rql/job/{}?access_token={}&expand=result'.format(base_url, resp['result']['id'], access_token)
def getter():
return requests.get(get_job_res).json()['result']['result']['rows']
return getter
@muzhig
muzhig / gist:18ac2374e4b3aa99dd59
Last active August 29, 2015 14:05
MySQL delete all tables
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;
SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
@muzhig
muzhig / gist:7faa490c37619ecef4de
Created August 19, 2014 11:11
local connection to sock file
nc -U /var/run/memcached/memcached.sock
@muzhig
muzhig / gist:6bda9b7d0022921b6047
Last active August 29, 2015 14:03
iter_stack (with locals of each frame)
def iter_stack(tb, limit=None):
"""modified version of traceback.extract_stack. it yields same tuples, but with frame.f_locals appended."""
if limit is None:
if hasattr(sys, 'tracebacklimit'):
limit = sys.tracebacklimit
n = 0
while tb is not None and (limit is None or n < limit):
f = tb.tb_frame
lineno = tb.tb_lineno
co = f.f_code
import json
from pprint import pprint
import requests
rtb_request = {
"id": "1234FcDe",
"imp": [{
"id": "1",
"banner": {
"w": 100, # width - this be used as width parameter in request in case of dynamic size placements
@muzhig
muzhig / gist:86b8041cd6352c1f15c1
Created June 6, 2014 08:24
postgres table sizes
SELECT relname, pg_size_pretty(relpages::bigint * 8 * 1024) as size, relkind, reltuples::bigint as rows, relpages, relfilenode FROM pg_class ORDER BY relpages DESC;
@muzhig
muzhig / gist:3c84cc41f0c131760ac5
Created May 5, 2014 16:32
twisted process fork
@classmethod
def start(cls, port=8080, extra_workers=0):
reactor.listenTCP(port, server.Site(cls()))
for i in range(extra_workers):
pid = os.fork()
if pid == 0:
# Proceed immediately onward in the children.
# The parent will continue the for loop.
break
else:
@muzhig
muzhig / gist:8086673
Last active January 1, 2016 03:39
python class name inside it's declaration
def get_classname():
return traceback.extract_stack()[-2][2] # in inner call
def get_classname_for_method_decorator():
return traceback.extract_stack()[-3][2] # in inner call
def decorator(func):
classname = get_classname_for_method_decorator()
return func