Skip to content

Instantly share code, notes, and snippets.

View afonasev's full-sized avatar
🔥

Afonasev Evgeniy afonasev

🔥
View GitHub Profile
def get_obj_by_path(path):
"""
Example:
obj = get_obj_by_path('module.Object')
"""
module_path, target = path.rsplit('.', maxsplit=1)
module = __import__(name=module_path, fromlist=(target,))
return getattr(module, target)
import collections
class NoStrIterable(collections.Iterable):
"""
'isinstance(smt, NoStrIterable)'
instead of
'isinstance(smt, collection.Iterable) and not isinstance(smt, str)'
"""
import subprocess
from pathlib import Path
import typer
def main(task_name: str):
task_dir = Path(task_name)
code_path = task_dir / 'code.py'
def convert_timestamp_to_local_tz(dt):
if dt.tzinfo is None:
return dt
# convert to utc
utc_dt = dt - dt.utcoffset()
utc_dt = utc_dt.replace(tzinfo=None)
offset = (
dt.datetime.now().replace(minute=0, second=0, microsecond=0) -
@afonasev
afonasev / .gitconfig
Last active September 16, 2021 15:46
[user]
name = Afonasev Evgeniy
email = ea.afonasev@gmail.com
[ea]
afonasev = Afonasev Evgeniy
[core]
autocrlf = input
safecrlf = false
editor = /usr/bin/vim
pager = less
{
"auto_complete_commit_on_tab": true,
"auto_complete_triggers":
[
{
"characters": ".",
"selector": "source.python - string - comment - constant.numeric"
}
],
"bold_folder_labels": true,
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["ctrl+t"], "command": "show_panel", "args": {"panel": "console", "toggle": true} },
{ "keys": ["ctrl+alt+c"], "command": "exec", "args": {"kill": true} }
]
@afonasev
afonasev / .zshrc
Last active September 10, 2021 07:01
export ZSH=/Users/afonasev/.oh-my-zsh
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="amuse"
fpath+=~/.zfunc
autoload -U compinit && compinit
plugins=(
docker, git, django, colored-man, colorize, github,
@afonasev
afonasev / .py
Created March 14, 2018 09:47
SequenceKeyWrapper (bisect with key)
class SequenceKeyWrapper(object):
"""
for bisect with key function
"""
def __init__(self, iterable, key):
self.iterable = iterable
self.key = key
def __getitem__(self, i):
@afonasev
afonasev / .py
Created March 14, 2018 09:48
Synchronized method with mutex
def synchronized_method(mutex_attr='mutex'):
def decorator(method):
@wraps(method)
def wrapped(instance, *args, **kw):
with getattr(instance, mutex_attr):
return method(instance, *args, **kw)
return wrapped
return decorator