Skip to content

Instantly share code, notes, and snippets.

View rterehov's full-sized avatar

Ruslan Terekhov rterehov

  • Gost group
  • Moscow, Russia
View GitHub Profile
@rterehov
rterehov / sqlalchemy-render-query.py
Last active February 23, 2017 08:47
Generate an SQL expression string with bound parameters rendered inline for the given SQLAlchemy statement
from datetime import datetime, date
from sqlalchemy.orm.query import Query
def render_query(statement, bind=None):
"""
Generate an SQL expression string with bound parameters rendered inline
for the given SQLAlchemy statement.
This is some improvement variant of this code:
https://gist.github.com/gsakkis/4572159
@rterehov
rterehov / auto-workon.sh
Last active December 26, 2020 09:47
It overrides 'cd' command for automatic change environment
# If you use virtualenvwrapper you might want to
# use this script for automatic change environment
# with 'cd' command.
#
# How to use:
# 1. Add this lines to ~/.bashrc
# 2. Place .env file in project folder.
# 3. And write environment name into the file.
#
# Use it at your own risk ;-)
@rterehov
rterehov / .python-autocomplete.py
Last active September 29, 2022 13:19
Python autocomplete and history for Mac OS X
"""
Place the script into your home folder and set PYTHONSTARTUP
variable like this:
export PYTHONSTARTUP=$HOME/.python-autocomplete.py
"""
import os
import sys
import readline
@rterehov
rterehov / set-creation-date-from-exif.sh
Last active October 12, 2025 18:26
Set creation date from EXIF
#!/bin/bash
# MacOS:
# brew install exiftool
# Debian/Ubuntu/RpP:
# sudo apt install libimage-exiftool-perl
show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS] [PATH]
import time
import tornado
import tornadis
import redis
import asyncio
import asyncio_redis
N = 50000
sync_client = redis.Redis('localhost')
@rterehov
rterehov / git-del-local-branches.sh
Last active June 18, 2019 08:54
Delete old local branches
# Delete old local branches (no longer on remote)
git fetch -p && \
for branch in `git branch -vv | gawk '{print $1,$4}' | grep -e ' исчез' -e ' gone]' | awk '{print $1}'`; do
git branch -D $branch;
done
@rterehov
rterehov / .vimrc
Last active April 8, 2025 16:42
.vimrc
" включить подсветку синтаксиса
syntax on
setf dosini
" размер табуляции
set tabstop=2
set shiftwidth=2
set smarttab
set et
@rterehov
rterehov / postgresql-usefull-queries.sql
Created May 18, 2022 13:13
PostgreSQL Usefull Queries
# Инфа по коннектам
select max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal
from
(select count(*) used from pg_stat_activity) t1,
(select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
(select setting::int max_conn from pg_settings where name=$$max_connections$$) t3
# Текущие запросы
select pid, usename, client_addr,query_start, state_change, state, query from pg_stat_activity order by query_start;