Skip to content

Instantly share code, notes, and snippets.

View onjin's full-sized avatar

Marek Wywiał onjin

View GitHub Profile
@onjin
onjin / nju-cli.py
Created November 21, 2018 21:48
example of writing cli program
#!/usr/bin/env python
import argparse
import getpass
import sys
from contextlib import contextmanager
from distutils.util import strtobool
def yes_or_no(question, default='no'):
"""Ask question and wait for yes/no answer.
@onjin
onjin / tests_responsibilities.md
Last active February 12, 2019 11:58
tests responsibilities
@onjin
onjin / modularity.md
Last active December 6, 2018 13:18
software modularity
@onjin
onjin / python_code_profiling.md
Last active March 6, 2019 13:19
python code profiling

requirements

Install https://github.com/jrfonseca/gprof2dot

Run profiler

$ python -m cProfile -o profiler.pstats ./some/python/code.py
$ gprof2dot -f pstats profiler.pstats | dot -Tpng -o profiler.png  # generate PNG calltree image
$ pyprof2calltree -i profiler.pstats -k # debug with kcachegrind
@onjin
onjin / feature-toggles-memo.md
Last active August 29, 2019 13:03
Categories of feature toggles

Feature toggles types

Short memo from:

Release Toggles

For not finished / not tested features

  • Configuration type: static - per environment, f.i. enabled only on test/stage
  • Lifetime: Short - until feature is finished / tested
@onjin
onjin / renew_env.sh
Last active December 23, 2021 14:16
#!/usr/bin/env bash
set -eu
pane_fmt="#{pane_id} #{pane_in_mode} #{pane_input_off} #{pane_dead} #{pane_current_command}"
tmux list-panes -s -F "$pane_fmt" | awk '
$2 == 0 && $3 == 0 && $4 == 0 && $5 ~ /(bash|zsh|ksh|fish)/ { print $1 }
' | while read -r pane_id; do
# renew environment variables according to update-environment tmux option
# also clear screen
@onjin
onjin / .bashrc
Created June 8, 2020 11:08
run tmux on ssh connect
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux
fi
@onjin
onjin / docker-compose.yml
Created June 29, 2020 21:38
sentry /traefik / docker-compose
version: '3'
services:
sentry:
image: 'sentry:latest'
command: start
networks:
- sentry
- traefik-public
depends_on:
- redis
@onjin
onjin / typing_decorator.py
Created October 21, 2020 09:25
python typing decorators
from typing import Any, Callable, TypeVar, cast
F = TypeVar('F', bound=Callable[..., Any])
# A decorator that preserves the signature.
def my_decorator(func: F) -> F:
def wrapper(*args, **kwargs):
print("Calling", func)
return func(*args, **kwargs)