Skip to content

Instantly share code, notes, and snippets.

View diyan's full-sized avatar

Oleksii Diian diyan

View GitHub Profile
@diyan
diyan / run_cmd.py
Created September 5, 2013 16:41
Process runner which support stdout/stderr more than 65K
from __future__ import unicode_literals
import subprocess
from tempfile import TemporaryFile
import time
class Response(object):
"""Response from a remote command execution"""
def __init__(self, std_out, std_err, status_code):
self.std_out = std_out
@diyan
diyan / lock_free_bulk_alter_table.sh
Last active December 24, 2015 16:29
Bash script that automates routine operations on sharded data using Percona Toolkit
#!/bin/bash
set -e
declare -r DB_HOST=db_host
declare -r DB_USER=db_user
declare -r DB_PASSWORD=db_pass
db_table_info() {
local db_name=$1; shift
local table_name=$1; shift
class BaseFactory(SQLAlchemyModelFactory):
ABSTRACT_FACTORY = True
@classmethod
def get_factory_session(cls):
if not getattr(cls, '_LAZY_FACTORY_SESSION', None):
session = open_db('test')
Base.metadata.create_all(session.bind)
cls._LAZY_FACTORY_SESSION = session
return cls._LAZY_FACTORY_SESSION
@diyan
diyan / factory_boy_sqlalchemy.py
Last active December 25, 2015 19:19
factory_boy for SQLAlchemy needs a static/single Session declaration. Snippet below allow use a separate SQLAlchemy Session for each test method. This could be useful if you prefer to have fresh in-memory SQLite database for each test.
# database.py file
def open_db():
# Create and return SQLAlchemy session object here
# This method is only for example
# factories.py file
from database import open_db
class FactorySessionMaker(object):
#!/bin/bash
# Based on https://github.com/holman/dotfiles/blob/master/script/bootstrap
set -e
declare -r DOTFILES_ROOT=$(pwd)
# Ask for the admin password upfront
#sudo -v
#https://github.com/cowboy/dotfiles/blob/master/bin/dotfiles
# nxlog script that converts uid, gid into username and group name
#$id = getpwnam($name);
#$name = getpwuid($num);
#$name = getpwent();
#$gid = getgrnam($name);
#$name = getgrgid($num;
#$name = getgrent();
my %user_names = ();
@diyan
diyan / wheezy_web.py
Last active December 29, 2015 16:09
Simple script wheezy.web with content negotiation skeleton
from __future__ import unicode_literals
import json
from wheezy.http import WSGIApplication, HTTPResponse
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import bootstrap_defaults, path_routing_middleware_factory
from wsgiref.simple_server import make_server
class ResourceHandler(BaseHandler):
@diyan
diyan / bootstrap_env.sh
Last active December 30, 2015 12:09
Script that bootstraps dev environment for one Python project. Works on Windows (with installed Python 2.7.6 and msysgit) and Ubuntu Linux (out of box).
#!/bin/bash
set -e
OS=`uname`
mkdir -p pip_download_cache
if [ "$OS" == "Linux" ]; then
# libmysqlclient-dev -> mysql-python
# protobuf-compiler -> protobuf -> riak_pb -> riak
# libxml2-dev, libxslt1-dev -> lxml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="lshw-B.02.16" />
<style type="text/css">
.first {font-weight: bold; margin-left: none; padding-right: 1em;vertical-align: top; }
.second {padding-left: 1em; width: 100%; vertical-align: center; }
.id {font-family: monospace;}
@diyan
diyan / python_wrappers_test_result.md
Last active January 3, 2016 10:19
C wrappers benchmark result on Asus Zenbook Prime UX31A / Core i7 3517U 1900 Mhz / Ubuntu 13.10 64 bit / Python 2.7.5 64 bit

Python C wrappers benchmark result on Asus Zenbook Prime UX31A / Core i7 3517U 1900 Mhz / Ubuntu 13.10 64 bit / Python 2.7.5 64 bit

Installation instructions for Ubuntu 13.10

$ git clone https://github.com/koder-ua/wrappers_test.git && cd $_
$ virtualenv . && . bin/activate
$ sudo apt-get install python-dev swig python-sip-dev libffi-dev libboost-python-dev python-sip-dev
$ pip install cython cffi
$ make