Skip to content

Instantly share code, notes, and snippets.

@bofm
bofm / output.txt
Last active Dec 6, 2018
consul-template dedup test
View output.txt
#### Running consul...
------------ CONSUL KEYS BEFORE -------------
---------------------------------------------
#### Running 10 consul-template instances with different templates...
#### Killing all consul-template instances with SIGTERM signal...
Cleaning up...
Cleaning up...
Cleaning up...
Cleaning up...
Cleaning up...
@bofm
bofm / x.md
Created Aug 29, 2018
Tarantool upgrate problem
View x.md

How to reproduce?

$ docker network create n1

first instance

$ docker run --rm -it --name t1 --net n1  -e TARANTOOL_REPLICATION=t1:3301,t2:3301 progaudi/tarantool:1.10.1-135-g193ef4150
@bofm
bofm / err.py
Created Jul 27, 2018
asynctnt_err
View err.py
Python 3.7.0 (default, Jun 29 2018, 09:12:54)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio, asynctnt
>>> asyncio.run(asynctnt.Connection(host='aa', port=1234).connect())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
@bofm
bofm / defer.py
Last active Mar 5, 2018
Python deferred execution helper.
View defer.py
from collections import deque
from functools import partial, wraps
class Deferred:
"""
Deferred functions execution.
Usage:
@bofm
bofm / it.py
Last active Mar 2, 2018
It. A handy iterator with method chaining.
View it.py
import itertools
import functools
class It:
"""A handy iterator with method chaining.
>>> It([1, 2, 3]).map(lambda x: x**2).filter(lambda x: x<5).chain_after('abc').apply(list)
['a', 'b', 'c', 1, 4]
"""
@bofm
bofm / repl_test.sh
Created Feb 14, 2018
tarantool replication test
View repl_test.sh
#!/usr/bin/env bash
cat <<EE > app.lua
box.cfg {
listen = 3301,
read_only = false,
wal_mode = "write",
replication = {"t1:3301", "t2:3301"},
}
@bofm
bofm / run_timeout.py
Created Nov 8, 2017
set maximum execution time for a python script
View run_timeout.py
import signal
def set_run_timeout(timeout):
"""Set maximum execution time of the current Python process"""
def alarm(*_):
raise SystemExit("Timed out!")
signal.signal(signal.SIGALRM, alarm)
signal.alarm(timeout)
@bofm
bofm / jupyter-system-site-packages.sh
Created Apr 20, 2017
Use virtualenv python kernel inside the Jupyter Notebook installed in the system site-packages
View jupyter-system-site-packages.sh
# install Jupyter Notebook into system site-packages
pip install -U notebook
# create a virtualenv and use the Jupyter from the system site-packages
mkvirtualenv --system-site-packages myvenv
# the virtualenv is now activated
pip install ipykernel
VM_NAME=myvm python -m ipykernel install --user --name $VM_NAME --display-name $VM_NAME
python -m jupyter notebook
# In the browser: New -> select kernel "myvm"
@bofm
bofm / st_capture_edits.py
Last active Mar 3, 2017
Sublime Text captute edits
View st_capture_edits.py
# Source:
# https://forum.sublimetext.com/t/retrieving-inserted-and-deleted-text/18697/24
import sublime
import sublime_plugin
def get_cursors(view):
# can't use `view.sel()[:]` because it gives an error `TypeError: an integer is required`
return [cursor for cursor in view.sel()]
@bofm
bofm / side_effect.py
Created Feb 2, 2017
Side Effect Python decorator.
View side_effect.py
from functools import wraps
def side_effect(callback, before=True, after=False):
"""A decorator.
Wraps the decorated function. The callback will be called before and after each
call of the decorated function according to the parameters.
Args: