Skip to content

Instantly share code, notes, and snippets.

View imankulov's full-sized avatar

Roman Imankulov imankulov

View GitHub Profile
@imankulov
imankulov / detached_screen.sh
Created November 27, 2015 09:50
Detached screen
screen -d -m -S screen_with_cat /bin/cat
@imankulov
imankulov / cldr_test.sh
Created December 8, 2015 21:53
CLDR test
#!/bin/bash
function create_venv() {
test -d env || virtualenv env
source ./env/bin/activate
pip install -q -U pip
}
function babel_from_pip() {
echo "=================================================="
echo "Running tests with Babel 2.1.1, installed with pip"
{
"af": {
"name": "Afrikaans",
"formula": "n != 1",
"plurals": 2,
"cases": [
"one",
"other"
],
"examples": {
@imankulov
imankulov / recursive.py
Created March 9, 2016 14:32
recursive.py
def change_type(root, old_type, new_type):
"""
Helper function to recursively walk through the datastructure and change old_type to new_type
"""
def _match(obj, **kwargs):
return isinstance(obj, old_type)
def _replace(obj, **kwargs):
return new_type(obj)
@imankulov
imankulov / jump_hash.py
Created May 30, 2016 16:23
Jump hash with linear probing
"""
Jump hash with linear probing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
JumpHash(N) maps consistently integer values onto the range [0, N), which can
be used to map users (by their user ids) to servers (by their indexes in
a configuration file, for example).
There is one important limitation of the hash, which affects its
use: buckets (servers) must be numbered sequentially, and it's important
@imankulov
imankulov / .tmux
Created December 27, 2016 13:56
mx sample config
session=wahoo
[first]
cmd='echo Wahoo!' C-m
[second]
cmd='echo Heya.' C-m
@imankulov
imankulov / bitmapist_workaround.py
Created February 23, 2017 19:13
Workaround for broken "foo AND NOT bar" logic in bitmapist
>>> bitmapist.mark_unique('foo', 1)
>>> bitmapist.mark_unique('foo', 1000)
>>> bitmapist.mark_unique('bar', 1)
>>> list(bitmapist.UniqueEvents('foo') & ~bitmapist.UniqueEvents('bar'))
[]
>>> list(bitmapist.UniqueEvents('foo') ^ bitmapist.UniqueEvents('bar') & bitmapist.UniqueEvents('foo'))
[1000]
@imankulov
imankulov / timezone.php
Created March 1, 2017 14:35
Timezone magic to find the boundaries of the day
<?
$utc = new DateTimeZone('UTC');
$user_tz = new DateTimeZone('Europe/Moscow');
// current time in UTC
date_default_timezone_set('UTC');
$datetime = new DateTime();
// convert current time to user's local time
$datetime->setTimezone($user_tz);
@imankulov
imankulov / chrome_moscow.sh
Created April 5, 2017 16:00
How to run a Google Chrome under Mac OS with a different timezone
#!/bin/bash
export TZ='Europe/Moscow'
exec open -na "Google Chrome" --args "--user-data-dir=$HOME/chrome-profile"
@imankulov
imankulov / browser_utils.py
Last active May 28, 2019 08:53
A MacOS python script to run Google Chrome or Firefox instance with given timezone settings. Requires pytz
import pytz
import os
def guess_timezone(city):
"""
Take the city name and try to guess the timezone
"""
tz_map = {tz.split('/')[-1].lower(): tz for tz in pytz.all_timezones}
try: