Skip to content

Instantly share code, notes, and snippets.

Avatar

nathants nathants

View GitHub Profile
@nathants
nathants / grid.py
Last active Aug 5, 2020
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()
View new-password.py
#!/usr/bin/env python3
import secrets
import string
import sys
import tty
import termios
import functools
import math
import operator
@nathants
nathants / aws-rotate-access-key.py
Last active Jul 19, 2020
quickly rotate your aws access key
View aws-rotate-access-key.py
#!/usr/bin/env python3
import boto3
import os
import pprint
import sys
import termios
import tty
"""
@nathants
nathants / monitor-usage.py
Last active Jun 30, 2020
simple server usage monitoring, writing json to stdout.
View monitor-usage.py
#!/usr/bin/env python3
"""
simple server usage monitoring, writing json to stdout.
usage: nohup python3 monitor_usage.py 3 > /var/log/usage.log &
"""
@nathants
nathants / tail_tinysnitch_logs.sh
Created Jun 15, 2020
a small and colorful format to tail tinysnitch logs
View tail_tinysnitch_logs.sh
# tinysnitch: https://github.com/nathants/tinysnitch
# pys: https://gist.github.com/nathants/741b066af9faa15f3ed50ed6cf677d67
# color: https://gist.github.com/nathants/336bc5e501ad174aeeb7986f2b0633e4
# colorful snitch logs
tail -f /tmp/tinysnitchd.log \
| grep --line-buffered -e allow -e deny \
| grep --line-buffered -v 1.1.1.1:53 \
| pys 'i.split("INFO")[-1]' \
| stdbuf -oL sed -E 's:\|.+>::' \
@nathants
nathants / color.py
Last active Jun 15, 2020
colorize input text
View color.py
#!/usr/bin/env python3
"""
colorize input text
usage: echo a b c | color a:green c:red
"""
import functools
import sys
View license.txt
All public gists https://gist.github.com/nathants
Copyright 2020-present, Nathan Todd-Stone
MIT License, http://www.opensource.org/licenses/mit
@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 Jun 5, 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 re
import datetime
import email
import os
import os
import smtplib
View rotate-logs.sh
#!/bin/bash
set -euo pipefail
# usage: myprogram.py | rotate-logs /tmp/myprogram.log [1000000]
file=$1
max_lines=${2:-1000000}
touch $file
line_count=$(cat $file | wc -l)
You can’t perform that action at this time.