Skip to content

Instantly share code, notes, and snippets.

@temoto
temoto / fix-pep8-e128.py
Created July 18, 2014 11:25
Fix PEP-8 E128 (function call wrapped to multiple lines with first argument still on first line)
#!/usr/bin/env python3
'''Fix PEP-8 E128.
function(argument1, argument2,
argument3, argument4)
->
function(
argument1, argument2,
@temoto
temoto / git-rebase-all
Created July 10, 2014 09:24
Git rebase all branches onto origin/master
#!/bin/bash
set -e
onto=origin/master
git fetch --prune
git branch --remotes --list 'origin/*' |grep -vE 'HEAD|master|gh-pages' |cut -d/ -f2 |while read -r b; do
printf "\nRebasing $b\n\n"
git checkout -B $b origin/$b
git rebase $onto && continue
@temoto
temoto / clean-requirements.py
Created July 3, 2014 14:01
Helper to clean requirements.txt from unused dependencies
#!/usr/bin/env python
from __future__ import print_function
import argparse
import collections
import re
import subprocess
import sys
KNOWN_IMPORT_PACKAGE_MAP = {
@temoto
temoto / meetup.go
Last active November 24, 2017 20:20
Meetup is a micro proxy program that enables to connect two endpoints via TCP sockets. https://github.com/temoto/meetup
// Moved to https://github.com/temoto/meetup
@temoto
temoto / awesome-strace-process-profile.py
Created October 4, 2013 12:57
Super awesome strace driven process profiler. Generates tree of children execution times. Very useful for debugging long package builds.
'''
Generate data:
strace -qf -ttt -s10000 -e trace=process -o build-strace-0 program
7744 1380876635.688736 execve("./build.sh", ["./build.sh"], [/* 19 vars */]) = 0
7744 1380876635.702388 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f8c267e79d0) = 7745
7744 1380876635.702780 wait4(-1, <unfinished ...>
7745 1380876635.702992 execve("/bin/mkdir", ["mkdir", "-p", "packages/common/etc"], [/* 20 vars */]) = 0
7745 1380876635.721350 exit_group(0) = ?
7744 1380876635.721609 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 7745
@temoto
temoto / compare-repositories.sh
Created August 15, 2013 14:17
Compare git and mercurial repositories
repo1=~/dev/github.com/eventlet/eventlet
repo2=~/dev/bitbucket.org/eventlet/eventlet
diff -ru <(cd $repo1; git ls-files |sort |xargs md5sum) <(cd $repo2; hg locate |sort |xargs md5sum)
@temoto
temoto / pre-commit
Created August 8, 2013 09:39
my git pre-commit hook: standard checks + autopep8 (Python)
#!/bin/bash
set -e
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
@temoto
temoto / helpers_data.py
Last active March 22, 2022 05:19
Part of py-helpers. Gzip compression shortcuts. Encoding. Database helpers. Retry decorator.
def namedlist(typename, field_names):
"""Returns a new subclass of list with named fields.
>>> Point = namedlist('Point', ('x', 'y'))
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain list
33
>>> x, y = p # unpack like a regular list
@temoto
temoto / git-hg-import.py
Created July 9, 2013 14:17
Python3 script to export git commit in format suitable for hg import Usage: cd ~/dev/bitbucket.org/eventlet/eventlet ~/bin/git-hg-import -git ~/dev/github.com/eventlet/eventlet HEAD^.. |hg import -
#!/usr/bin/env python
__author__ = 'Sergey Shepelev <temotor@gmail.com>'
__version__ = '1'
import argparse
import codecs
import functools
import logging
import os
import re
import subprocess
@temoto
temoto / benchmark_try_or_with_timeout.py
Created July 1, 2013 14:42
Eventlet micro benchmark try/except or with handling of timeouts.
import eventlet
from eventlet.timeout import Timeout
import gc
import sys
import time
def do_with(tt, ts):
ok = False
with Timeout(tt, False):