Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / sql-stat.py
Last active August 29, 2015 14:04
Django SQL DB query statistics. Now you may find https://pypi.python.org/pypi/django-devserver SQLSummaryModule better.
try:
# DB profiling.
# TODO: extract this to separate module.
TERMINAL_WIDTH = 124 # fine for 15" in 12px mono font.
SHOW_TOP_N_QUERIES = 5
import itertools
import textwrap
queries = django.db.connection.queries
if queries:
@temoto
temoto / sql-trace.py
Created August 1, 2014 05:22
Django SQL DB trace: see where your queries are coming from. Now you may find https://pypi.python.org/pypi/django-devserver better.
from django.db.models.sql import Query
from functools import wraps
import inspect
TRACE_THIS_QUERY = u'SELECT "blog_group"."id", "blog_group"."name", "blog_group"."arg" FROM "blog_group" INNER JOIN "blog_group_members" ON ("blog_group"."id" = "blog_group_members"."group_id") WHERE "blog_group_members"."user_id" = %s '
def trace_get_compiler(fun):
@wraps(fun)
@temoto
temoto / table2cron.py
Last active August 29, 2015 14:06
Manage cron jobs in a nice spreadsheet, export to crontab format using this script.
#!/usr/bin/env python3
'''
каждый день{tab}13:45{tab}игнорируется{tab}http://ping.url/
->
45 13 * * *{tab}/usr/bin/curl -fsS 'http://ping.url/'
'''
import re
import sys
@temoto
temoto / shingle-compare.py
Created November 27, 2014 17:24
Shingle based fuzzy text comparison
def shinglize(s):
return frozenset(s[i:i + 3] for i in xrange(len(s) - 2))
def shingle_compare(sh1, string):
'''set(shingle), 'string' -> float 0..1
'''
sh2 = shinglize(string)
if not sh1 or not sh2:
return 0
import multiprocessing as mp
import sys
import resource
def memory():
self = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
children = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
return self + children
static struct addrinfo tcp_hints = {
.ai_flags = AI_NUMERICSERV,
.ai_socktype = SOCK_STREAM,
.ai_family = AF_INET,
};
static struct addrinfo https_ai;
static struct addrinfo
make_https_addrinfo (void) {
int r = 0;
crawler/crawler
*.o
*.pyc
*.pyo
@temoto
temoto / a better programming language builtin types.rst
Created September 2, 2009 14:35
a better programming language features

Types

  • Atoms (Erlang, Ruby)

>>> ok

>>> :ok

  • Infinite size integers