Skip to content

Instantly share code, notes, and snippets.

@nathants
nathants / disable_keyboard.sh
Last active Jun 7, 2022
after some work minutes, lock the screen requiring password entry, and disable the keyboard for a few minutes, delaying possibility of unlock and forcing break minutes
View disable_keyboard.sh
#!/bin/bash
set -euo pipefail
seconds=$1
start=$(date +%s)
while true; do
for id in $(xinput list|grep -e USB -e 'AT Translated Set 2 keyboard' -e 'IBM TrackPoint'|grep -Po 'id=[0-9]+'|cut -d= -f2); do
xinput disable $id
View yaml.py
#!/usr/bin/env python3
# flake8: noqa
# type: ignore
"""
convert json/yaml to colorized yaml for easy reading
"""
import os
import re
View count-last.py
#!/usr/bin/env python3
import blessed # pip install blessed
import sys
term = blessed.Terminal()
last = None
count = 1
for line in sys.stdin:
line = line.rstrip()
if line == last:
count += 1
@nathants
nathants / matplot.py
Last active Jun 10, 2022
>> echo timestamp=2021-10-07T00:38:00Z a=160.2 b=20.8 c=1 | matplot
View matplot.py
#!/usr/bin/env python3
# type: ignore
import matplotlib as mpl
from matplotlib import pyplot # pip install matplotlib
import argh # pip install argh
import pandas # pip install pandas
import sys
import datetime
@nathants
nathants / plot.py
Last active Oct 7, 2021
>> echo 1 1 1 2 2 2 4 4 4 4 8 8 8 8 16 16 16 16 | tr ' ' '\n' | plot
View plot.py
#!/usr/bin/env python3
# type: ignore
import math
import argh # pip install argh
import sys
import blessed # pip install blessed
term = blessed.Terminal()
def avg(xs):
@nathants
nathants / grid.py
Last active Jun 19, 2022
live visualizing simple data as a grid
View grid.py
#!/usr/bin/env python3
# type: ignore
import argh
import json
import sys
import time
import blessed
term = blessed.Terminal()
@nathants
nathants / tail_tinysnitch_logs.sh
Last active Nov 28, 2021
a small and colorful format to tail tinysnitch logs
View tail_tinysnitch_logs.sh
# tinysnitch: https://github.com/nathants/tinysnitch
# color: https://gist.github.com/nathants/336bc5e501ad174aeeb7986f2b0633e4
# count-last: https://gist.github.com/nathants/f6d3f2cd4147af102c65a69a7e729b53
# colorful snitch logs
tail -f /tmp/tinysnitch.log \
| sed -ur 's:(tcp|udp) [^ ]+ \->:\1:' \
| grep --line-buffered -v -e :51820$ -e :53$ \
| color tcp:blue udp:cyan dns:magenta icmp:yellow allow:green deny:red \
| count-last
@nathants
nathants / color.py
Last active Feb 2, 2021
colorize input text
View color.py
#!/usr/bin/env python3
"""
colorize parts of lines to arbitrary colors
usage: echo a b c | color a:green c:red
usage: echo /a/b/c | sep=/ color a:green c:red
usage: echo /a123/b/c | sep=/ sub=y color a:green c:red
@nathants
nathants / pys.sh
Last active Jun 5, 2020
3 bash functions for quick python oneliners
View pys.sh
PY_IMPORTS="
import datetime
import string
import random
import math
import time
import itertools
import collections
import functools
import fcntl
@nathants
nathants / email.py
Last active Nov 7, 2020
a cli to interact with email via imap and smtp
View email.py
#!/usr/bin/env python3
from dateutil import parser
from email.header import decode_header
from email.mime.text import MIMEText
import contextlib
import re
import datetime
import email
import os
import os