Skip to content

Instantly share code, notes, and snippets.

View Hammer2900's full-sized avatar
🚚
Working from home

Yevhen Ts. Hammer2900

🚚
Working from home
View GitHub Profile
@Hammer2900
Hammer2900 / docker_exec_alias.md
Created February 25, 2019 14:05 — forked from danfergo/docker_exec_alias.md
Aliasing docker exec -it bash

How to alias docker exec (with autocompletion)

Aliasing docker exec -it some_container_name bash to d some_container_name.

Step 1.1 Add to your .bashrc

d(){
    docker exec -it $1 bash
}

Step 1.2 Then source it

@Hammer2900
Hammer2900 / notes.sh
Created January 25, 2019 08:40
fast note helper
#!/usr/bin/env bash
NOTES_FILE=~/.notes
# KEYS
delete_line="Ctrl+d"
edit_note="Ctrl+e"
menu=$(echo -e "< Exit\n---\n1 [ Browse Library ]>\n2 [ Current Artist ]>\n3 [ Current Queue ]>\n---\n4 [ Options ]>\n5 [ Ratings ]>\n6 [ Help ]")
@Hammer2900
Hammer2900 / run.sh
Created January 22, 2019 16:35
check yaml file in console
python -c 'import yaml, sys; print(yaml.safe_load(sys.stdin))' < data.yaml
@Hammer2900
Hammer2900 / vector.py
Created January 20, 2019 15:02 — forked from mcleonard/vector.py
A vector class in pure python.
"""
The MIT License (MIT)
Copyright (c) 2015 Mat Leonard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Hammer2900
Hammer2900 / py-code-update.py
Created January 15, 2019 06:13 — forked from javierarilos/py-code-update.py
Sample of reloading a class definition in python. Old and new instances point to the correct class definition.
# writing c1 class definition to module mod1
cs = """
class c1(object):
att = 1
def m1(self):
self.__class__.att += 1
# printing class name, class-id, and the id of the class, which happens to be its memory address
print "uno:", self.__class__, "class-id:", id(self.__class__), "att:", self.__class__.att
"""
@Hammer2900
Hammer2900 / app.py
Created December 25, 2018 21:09
fast json db in memry
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from tinydb.storages import MemoryStorage
from tinyrecord import transaction
from tinydb import TinyDB, Query
class TinyMemoryJsonClass(object):
def __init__(self, name):
@Hammer2900
Hammer2900 / toggle-nightlight.sh
Created December 11, 2018 19:01 — forked from kapad/toggle-nightlight.sh
Script to toggle the Gnome nightlight setting.
#!/bin/bash
setting=$(gsettings get org.gnome.settings-daemon.plugins.color night-light-enabled)
if [[ $setting == "true" ]]; then
gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled false
else
gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true
fi
@Hammer2900
Hammer2900 / test_log.py
Created September 20, 2018 07:07
Test log for python
import logging
import os
current_dir = os.path.dirname(os.path.abspath(__file__))
logging.basicConfig(
format="%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s",
handlers=[
logging.FileHandler("{0}/{1}.log".format(current_dir, 'parse_log')),
logging.StreamHandler()
@Hammer2900
Hammer2900 / fsm.py
Created September 8, 2018 16:29
small finite state machine example
class InitializationError(Exception):
pass
class TransitionClass:
def __init__(self, state):
self.state = state
def run(self, state_mashine):
return None
@Hammer2900
Hammer2900 / x11_watch_active_window.py
Created August 12, 2018 07:35 — forked from ssokolow/x11_watch_active_window.py
python-xlib example which reacts to changing the active window
#!/usr/bin/env python
"""python-xlib example which reacts to changing the active window/title.
Requires:
- Python
- python-xlib
Tested with Python 2.x because my Kubuntu 14.04 doesn't come with python-xlib
for Python 3.x.