Skip to content

Instantly share code, notes, and snippets.

@temoto
temoto / test-imul-shl.c
Last active December 12, 2015 05:28
Benchmark IMULQ against SHL on x86-64
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/*
Compile with:
gcc -g -O0 -Wall -Werror
*/
static int64_t mul_imul(int64_t n) {
asm __volatile__ (
@temoto
temoto / stork-deploy-init.bash
Last active December 14, 2015 05:39
Super awesome, simple, fast and robust deploy system. It has only 2 drawbacks: flexible by changing code and user must know what he does. Part 1 - prepare access to target machine.
#!/bin/bash
# Stop on errors
set -e
# Config
: ${user=stork-deploy}
: ${ssh_public_key="ssh-dss AAAAB3NzaC1kc3MAAACBAIbzNCxj+N8ZGcEeel1jMfy9MpBOoLUQXR+fxgqsXYiFkAB6e2deqKHXh+TuntWQwsoPcXi2/0UaWZkgR3JmJxrqFM3/aAeUUupDFLnUFSuz+L2y4hke8GAeLHuzaZ30HfvDU+AO4uQF6obLl5xs88H5BYPvmzhxQcPdOiwkK1XDAAAAFQCwh2kXaGbJGWE+Jaw78cxKNq+JHQAAAIA4X3JfuQ6eYm0N1EWPcWf46rTT0O0TNnBXlhNRhSQNnxbcLjF8ZYG/tYLRJA/J8dMgi/4ZojW4Hq7CluYq68ycf2FOS3S60vdoEv++q7oq8jKHyfQtzo+Jq8q0yMXd+PBnHp7s4v8AHK7ifz/LotCfg7d9+XAbCt//qjwZgPTulQAAAIBzptzN3d+yLu63MraeVdvz5nYDCwiy94FKaSSfPbHWH9iKb8jyJ1smrsM4SV9/ongsMAnDIA340HYFZqBY/iZEak84BTnjA89sZmUP/8E1Ou7WL/Lsx/kMfLuh4zANoqzMbwir7zm69x5ZqRhSqBs2J8iLx2hCX5zwWhoDnpVIUg== stork deploy"}
: ${sudoers_conf="/etc/sudoers.d/$user"}
version=1
@temoto
temoto / aes-cfb-example.go
Created February 27, 2013 22:37
Example of AES (Rijndael) CFB encryption in Go. IMHO, http://golang.org/pkg/crypto/cipher/ could benefit a lot from similar snippet.
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
)
func EncryptAESCFB(dst, src, key, iv []byte) error {
aesBlockEncrypter, err := aes.NewCipher([]byte(key))
(function(){
var node = document.createElement('DIV');
var human_link = 'http://example.com/new-landing';
node.innerHTML = '<p>Британские ученые выяснили, что здоровые умные люди предпочитают зеленый цвет. Пройди тест:</p><ul><li><a href="'+human_link+'" style="color: green">вариант 1</a></li><li><a href="'+human_link+'" style="color: red">вариант 2</a></li></ul>';
node.style.position = 'absolute';
node.style.left = '0';
node.style.top = '0';
node.style.width = '100%';
node.style.height = '100%';
node.style.background = 'white';
@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):
@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 / helpers_data.py
Last active September 10, 2024 20:12
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 / 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 / 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 / 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