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: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: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;
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: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
@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: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;
sudo apt-get install build-essential libsqlite3-dev zlib1g-dev libncurses5-dev libgdbm-dev libbz2-dev libreadline5-dev libssl-dev libdb-dev
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xzf Python-2.7.3.tgz
cd Python-2.7.3
./configure --prefix=/usr --enable-shared
make
sudo make install
cd ..
@muzhig
muzhig / gist:4451452
Last active December 10, 2015 14:58
TAR
tar -c "$srcdir" | tar -C "$destdir" -xv
tar -cf archive.tar foo bar
tar -xf archive.tar # Extract all files from archive.tar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
sudo su - <username>
sudo -u username <cmd>
@muzhig
muzhig / gist:4460471
Created January 5, 2013 08:12
GITOLITE
gitolite admin repo – this is where you add new repos, users, and access.
git clone ssh://gitolite@hostname_or_ip:ssh_port/gitolite-admin
You now have a gitolite-admin directory with conf/ and keydir/ inside. Conf directory contains gitolite.conf file and you will add users, privileges and projects/repos here. Keydir is where you save the ssh key files. Note: Make sure the filename of ssh key matches the user on gitolite.conf without the .pub. As example, you will have your ssh key file in keydir/user.pub and in gitolite.conf you have the following:
repo gitolite-admin
RW+ = user
To add users, upload the ssh key file inside keydir/ and add his access inside gitolite.conf.
vi keydir/user2.pub
To create new repository, just add the following lines in conf/gitolite.conf:
repo drupal_dev
RW+ = user user2