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 / gist:4473717
Created January 7, 2013 09:38
Django-admin-like configurable search view
from django.db.models import Q
from django.views.generic import ListView
import itertools
class BaseSearchView(ListView):
search_fields = []
def get_search_fields(self):
return self.search_fields
query_key = 'q'
@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: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
#pragma once
template < typename T > class SP
{
private:
T* pData; // pointer
int* refcnt; // Reference count
public:
SmartPointer() : pData(0), refcnt(0)
{
@muzhig
muzhig / gist:5346671
Created April 9, 2013 15:30
Bluetooth Com port
me@hardy:~$ sudo hcitool scan
Scanning ...
00:02:C7:7D:F5:17 BlueGPS 7DF517
me@hardy:~$ sudo rfcomm bind /dev/rfcomm0 00:02:C7:7D:F5:17 1
me@hardy:~$ ls -l /dev/rfcomm0
crw-rw---- 1 root dialout 216, 0 2008-12-14 23:15 /dev/rfcomm0
@muzhig
muzhig / gist:4707541
Created February 4, 2013 15:46
POSTGRES
generate drop all tables statement
select 'drop table if exists "' || tablename || '" cascade;' from pg_tables where schemaname = 'public';
class backtrace
{
boost::shared_array<void*> m_backtrace;
size_t m_trace_size;
public:
static const int DEFAULT_STACK_DEPTH = 100;
static const int DEFAULT_EXCLUDE_FIRST_FRAMES_COUNT = 1;
typedef std::vector<std::string> stack_type;
@muzhig
muzhig / gist:4474079
Created January 7, 2013 10:46
OPENSSL
tar -cvpj /path/to/directory | openssl aes-256-cbc -kfile /path/to/enc.key | split -d -b 4000m - backup.tar.bz2.enc.
cat backup.tar.bz2.enc.* | openssl aes-256-cbc -d -kfile /path/to/enc.key | tar xvjf -