Skip to content

Instantly share code, notes, and snippets.

nathants nathants

Block or report user

Report or block nathants

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nathants
nathants / pys.sh
Last active Jan 13, 2020
3 bash functions for quick python oneliners
View pys.sh
# exec a python snippet and print the result, stdin is not used
# >> p '60*60*24'
# 86400
p() {
python -c "
$PY_IMPORTS
val = $@
if val:
if isinstance(val, list):
@nathants
nathants / email.py
Last active Dec 18, 2019
a cli to interact with email via imap and smtp
View email.py
#!/usr/bin/env python3
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 auto-restart.sh
#!/bin/bash
set -eou pipefail
# usage: auto-restart.sh python program.py
trap 'exit 1' SIGINT
count=$(ps -eo args | grep ^/bin/bash | grep "auto-restart $*"$ | grep -v grep | wc -l)
if (($count > 2)); then
echo already running: auto-restart $@ >&2
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)
View license.txt
All public gists https://gist.github.com/nathants
Copyright 2012-present, Nathan Todd-Stone
MIT License, http://www.opensource.org/licenses/mit
@nathants
nathants / pip-upgrade.py
Created Jun 18, 2018
check for updates and optionally upgrade packages via pip
View pip-upgrade.py
#!/usr/bin/env python3
"""
check for updates and optionally upgrade packages via pip
"""
import os
import subprocess
import sys
import termios
@nathants
nathants / aws-rotate-access-key.py
Last active Jun 18, 2018
quickly rotate your aws access key
View aws-rotate-access-key.py
#!/usr/bin/env python3.6
import boto3
import os
import pprint
import sys
import termios
import tty
"""
View new-password.py
#!/usr/bin/env python3.6
import secrets
import string
import sys
import tty
import termios
import functools
import math
import operator
View keybase.md

Keybase proof

I hereby claim:

  • I am nathants on github.
  • I am nathants (https://keybase.io/nathants) on keybase.
  • I have a public key ASBvsxkJ-Tl1HIlxes6dJ3bGDfOqAhC_HBJXGuglMvDnOgo

To claim this, I am signing this object:

View log-watcher.py
#!/usr/bin/env python3
import functools
import sys
import time
import collections
import threading
import queue
email_to = '_@_.com'
email_subject = 'error'
You can’t perform that action at this time.