Skip to content

Instantly share code, notes, and snippets.

def has_methods(*methods):
def decorator(Base):
def __subclasshook__(Class, Subclass):
if Class is Base:
attributes = collections.ChainMap(*(Superclass.__dict__ for Superclass in Subclass.__mro__))
if all(method in attributes for method in methods):
return True
return NotImplemented
Base.__subclasshook__ = classmethod(__subclasshook__)
return Base
@misebox
misebox / runtest
Last active October 11, 2017 11:36
#!/bin/bash
success=true
# Echo the line number and result of the last command.
verify () {
local result=$?
local frame=($(caller 0))
local lno=${frame[0]}
echo -n "$lno: "
if [ $result -eq 0 ]; then
from django.urls.resolvers import URLResolver, URLPattern
def compose_decorators(decorators, wrappee):
if not hasattr(decorators, '__iter__'):
decorators = (decorators, )
for wrapper in decorators:
wrappee = wrapper(wrappee)
return wrappee
@misebox
misebox / main.py
Created August 21, 2019 15:24
A Simple CLI tool foundation
from datetime import datetime
import functools
import logging
import sys
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)
@misebox
misebox / ut.sh
Created May 18, 2020 04:24
Simple I/O test manager written in shellscript
#!/bin/bash
set -eu
test_prefix="tests"
function name_cmd () {
local grp=$1
echo "./${test_prefix}/cmd_${grp}"
}
@misebox
misebox / cmd-to-wid.sh
Created May 26, 2020 07:18
Shellscript getting Window ID from command name with pgrep and xdotool.
#!/bin/bash
pid=`pgrep $1`
[ "$pid" != "" ] && xdotool search --onlyvisible --pid $pid
@misebox
misebox / foxhunt.sh
Last active May 26, 2020 09:32
Shellscript to search firefox and close its all tabs and windows.
#!/bin/bash
while [ `pgrep firefox` != "" ]
do
for winid in $(xdotool search --onlyvisible --pid `pgrep firefox`)
do
echo $winid
sleep 0.2
if [ "$winid" != "" ]
then
while true
@misebox
misebox / clip.sh
Created May 26, 2020 10:00
Copy input from stdin into clipboard
#!/bin/bash
xsel --clipboard --input
@misebox
misebox / keybindings.json
Last active June 1, 2020 10:18
VSCode minimal KeyBindings for vim extension on linux user.
[
// Side bar is toggled with [CTRL + SHIFT + B]
{
"key": "ctrl+shift+b",
"when": "sideBarVisible",
"command": "workbench.action.closeSidebar"
},
{
"key": "ctrl+shift+b",
"when": "!sideBarVisible",
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
l = log --oneline --decorate --graph --date=short
type = cat-file -t
dump = cat-file -p
[core]