Skip to content

Instantly share code, notes, and snippets.

View ShaBren's full-sized avatar

ShaBren

  • South Carolina, USA
View GitHub Profile
@ShaBren
ShaBren / watch-lsof.py
Created May 23, 2014 16:50
Track TCP connections by process
#!/usr/bin/env python3
import sys
import time
from subprocess import check_output as qx
if len( sys.argv ) < 2:
print( "Usage: %s <pid>" % ( sys.argv[0], ) )
sys.exit(1)
@ShaBren
ShaBren / batt
Last active August 29, 2015 13:57
Get current battery percentage on OS X
input=`system_profiler SPPowerDataType | grep \(mAh\) | cut -d : -f 2 | cut -c 2-`
read current max <<< $input
echo $(($current/($max/100)-1))%