Skip to content

Instantly share code, notes, and snippets.

View gordio's full-sized avatar

Oleh Hordiienko gordio

View GitHub Profile
@gordio
gordio / numfmt.py
Created May 14, 2019 23:43
simple numfmt for macOS (save as /usr/local/bin/numfmt)
#!/usr/bin/env python
from __future__ import print_function
import sys
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('fields', metavar='N', type=str, nargs='*', help="Fields if provided or stdin")
parser.add_argument('--field', nargs='?', type=int, default=1, help="Work with provided field")
parser.add_argument('--suffix', nargs='?', type=str, default="B", help="Suffix")
parser.add_argument('--padding', nargs='?', type=int, default=1, help="Insert spaces before")
@gordio
gordio / 01-git-list-large-files.sh
Created May 14, 2019 23:40
Cleanup Git repository (find and remove big files in git)
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
@gordio
gordio / utils.py
Last active March 2, 2019 20:34
Python function for getting deep keys
def getProp(obj, *args):
"""Get deep property or return None
Args:
obj: Target object
*args: nested properties
Returns:
Return deep property or None
>>> target = {'foo': {'baz': ["h1", "h2", "h3"]}}
@gordio
gordio / rpi3-human_readable_usb.rules.sh
Created February 22, 2018 19:41
Use static names for USB devices for Raspberry Pi 3. (ttyUSBUpperLeft, ttyUSBLowerLeft, ttyUSBUpperRight, ttyUSBLowerLeft)
cat > "/etc/udev/rules.d/99-human_readable_usb.rules" << EOF_USB_RULES
SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-3f980000.usb-usb-0:1.2:1.0", SYMLINK+="ttyUSBUpperLeft"
SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-3f980000.usb-usb-0:1.3:1.0", SYMLINK+="ttyUSBLowerLeft"
SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-3f980000.usb-usb-0:1.4:1.0", SYMLINK+="ttyUSBUpperRight"
SUBSYSTEM=="tty", ENV{ID_PATH}=="platform-3f980000.usb-usb-0:1.5:1.0", SYMLINK+="ttyUSBLowerLeft"
EOF_USB_RULES
udevadm control --reload-rules
@gordio
gordio / example.py
Last active February 16, 2018 12:33 — forked from diosmosis/example.py
Python decorator that catches exceptions and logs a traceback that includes every local variable of each frame.
import os
from log_exceptions import log_exceptions
def throw_something(a1, a2):
raise Exception('Whoops!')
@log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None)
def my_function(arg1, arg2):
throw_something(arg1 + 24, arg2 - 24)
@gordio
gordio / .tmux.conf
Last active August 19, 2017 15:42
Tmux
# -- general -------------------------------------------------------------------
set -g default-terminal "screen-256color" # colors!
setw -g xterm-keys on
set -s escape-time 1 # fastest command sequences
set -sg repeat-time 300 # increase repeat timeout
#set -s quiet on # disable various messages
set -s focus-events on
# GNU-Screen compatible prefix
@gordio
gordio / script.bin.fex
Last active July 17, 2017 21:18
Orange Pi Zero Plus2 (H3)
; from https://github.com/armbian/build/blob/master/config/fex/orangepizeroplus2-h3.fex
;
; Based on Armbian's fex for Orange Pi Zero and Xunlong's for H5 Zero Plus 2:
; https://github.com/OrangePiLibra/OrangePi_H5SDK/blob/71323b535b39a136ca206b22d4acc331310f0646/external/sys_config.fex
;
; TODO:
; - try to boot
; - verify DRAM parameters
; - fix powering on AP6212
;
@gordio
gordio / mutt-gmail-yandex.md
Created April 21, 2017 00:14 — forked from lazyfrost/mutt-gmail-yandex.md
Configuring mutt to work with gmail and yandex
@gordio
gordio / sVimcss
Last active October 6, 2017 02:54
#sVim-command {
background-color: rgba(0, 0, 0, 0.80) !important;
background-position: none !important;
background-repeat: none !important;
border-radius: 0 !important;
border: 0 !important;
box-shadow: none !important;
box-sizing: content-box !important;
color: #FFFFFF !important;
display: none;
@gordio
gordio / sVimRC
Last active September 19, 2017 17:12
unmap "space"
unmap "left"
unmap "right"
unmap "up"
unmap "down"
unmap "w"
unmap "r"
map "r" openReader
map "shift+r" openReader