Skip to content

Instantly share code, notes, and snippets.

View diyan's full-sized avatar

Oleksii Diian diyan

View GitHub Profile
@diyan
diyan / proxied_circushttpd.py
Created May 23, 2013 16:57
Helper script for host circus-web app behind Nginx reverse proxy with prefixed path.
class ReverseProxied(object):
'''Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.
In nginx:
location /myprefix {
proxy_pass http://192.168.0.1:5001;
proxy_set_header Host $host;
@diyan
diyan / python_qa_automation.md
Last active February 21, 2023 20:33
Learning Python for QA automation tasks

Hello all,

In this gist you may find resources in Russian/English which could be useful for writing Python script for test automation tasks.

What Python runtime I should use?

While Python 3.x (>=3.3) is reccomended for new project development it much better and easier to go with a bit older but rock-solid Python 2.x (>=2.7) for test automation.

Some Python packages comes with binary modules and it much easier to use 32-bit Python under Windows due to this reason.

@diyan
diyan / test_parametrized_samples.py
Last active December 19, 2015 23:59
Samples how-to use parametrized tests in pyt.test framework.
"""
3 samples how-to use parametrized tests in pyt.test framework:
1. Parametrized fixture with simple string types will generate friendly test name.
2. Parametrized fixture with complex type require you implement __hash__ and __str__ methods. But you will not see friendly test names.
3. The only way to see friendly test names with complex types is to implement pytest_generate_tests hook.
"""
from pytest import fixture
@diyan
diyan / post-update.sh
Last active December 20, 2015 09:09
Git. Hooks. Post update hook to deploy site from repo host to the remote host or web-farm
NEW
#!/bin/bash
set -e
declare -r SSH_USER=www-data
declare -r SSH_KEY=~/.ssh/www-data.pem
declare -r GIT_URL=ssh://git@domain.com/sample_repo.git
declare -r GIT_KEY=/var/www/.ssh/deploy_push.pem
declare -r GIT_DIR=/usr/local/sample_app
declare -r DEV_SERVERS=weblinux-dev01
declare -r STAGE_SERVERS=weblinux-stage
@diyan
diyan / i3.conf
Last active November 26, 2022 22:53
i3 tiling window manager configuration
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout somewhen, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
@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