Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am samuelhavron on github.
  • I am samh (https://keybase.io/samh) on keybase.
  • I have a public key whose fingerprint is 4059 AC71 169A 91DB C8B2 A7DF F0B2 1A52 20CE BBFB

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am havron on github.
  • I am samh (https://keybase.io/samh) on keybase.
  • I have a public key whose fingerprint is 4059 AC71 169A 91DB C8B2 A7DF F0B2 1A52 20CE BBFB

To claim this, I am signing this object:

@havron
havron / MITM_to_csv.py
Last active September 15, 2021 01:44
MITMProxy's default dump script is *not* Pandas friendly! Run `mitmdump -s MITM_to_csv.py -q` with this gist to get CSV for requests and responses. The 'id' is what uniquely links requests with their response pair -- I might eventually move to HAR style dump to join reqs and resps.
from mitmproxy import http
from mitmproxy.net.http import cookies
from mitmproxy.utils import strutils
from datetime import datetime
import csv
import base64
import json
REQUESTS_LOG = 'requests.mitm.csv'
RESPONSES_LOG = 'responses.mitm.csv'
@havron
havron / netgear_linux_driver.sh
Last active October 2, 2018 15:47
If you have bought a netgear A7000 wifi dongle for your desktop, this is the easy way to ensure it plays nice with your Linux distro. Some of the versioning could be outdated, so be sure to change the versions for your system (and find new dkms module if needed).
$driver = rtl8814au
cd $HOME
sudo apt update
sudo apt install git dkms libelf-dev
git clone https://github.com/zebulon2/$driver.git
sudo dkms add ./$driver
sudo dkms build -m $driver -v 4.3.21
sudo dkms install -m $driver -v 4.3.21
echo "How to enroll the driver as a trusted module:"
echo "Reboot and allow custom keys in Secure Boot in BIOS."
@havron
havron / inCaseOfFire.sh
Created October 12, 2018 19:00
Leave no repo behind!
commit_msg="THIS MACHINE IS IN PERIL: NO REPOS WILL BE LEFT BEHIND!"
echo "$commit_msg"
find ~ -name ".git" -type d -exec bash -c "echo 'Saving {} from peril!' \
&& cd '{}'/.. && git add -A && git commit -m "$commit_msg"\
&& git push" \;
echo "WHAT ARE YOU DOING STAYING HERE?? RUN!!!"
@havron
havron / hw_groups.py
Last active October 16, 2018 12:55
Easily form random groups of students for homework assignments. Aimed at Cornell faculty/staff using CMSX for course management.
#!/usr/bin/env python3
import pandas as pd
import numpy as np
GROUPSIZE = 4
INFILE = 'CS_5435_student_table.csv'
OUTFILE = 'CS_5435_hw_groups.csv'
'''
Load the student data (download it from
https://cmsx.cs.cornell.edu/web/auth/?action=exporttable&courseid=<YOURCOURSEID>)
@havron
havron / android_permissions_labels.py
Last active October 29, 2018 14:16
Get full human-readable labels for Android permissions. Run `adb shell pm list permissions -g -f > permissions_dump.txt` on an Android device, then run this Gist to convert to pandas-friendly CSV.
'''
Get full human-readable labels for Android permissions.
Run `adb shell pm list permissions -g -f > permissions_dump.txt` on an Android device,
then run this Gist to convert to pandas-friendly CSV.
'''
from rsonlite import simpleparse
import pandas as pd
OUTFILE = 'android_permissions.csv'
def permission_labels(permissions_dumpfile):
print('Parsing permissions dumpfile...')
@havron
havron / cross_validate.py
Last active November 10, 2018 19:42
Easier cross validation algorithm than what I could find on the WWW.
from sklearn.model_selection import KFold
from sklearn.base import clone
def cross_validate(features, labels, nsplits, model):
'''Returns tuple of (scores : list, average_score : float) over K folds.
Keyword arguments:
nsplits : int -- the number of folds to perform cross validation on.
model -- an object that is the model for CV. Assumes fit() and score() methods,
akin to sklearn model APIs.
features : pandas.DataFrame -- a Pandas DataFrame containing preprocessed training data features.
@havron
havron / disk_analyze.sh
Last active December 11, 2018 20:32
figure out what is taking up all of the space on disk. also consider https://dev.yorhel.nl/ncdu
du -cha --max-depth=2 /home/ | grep -E "M|G" | sort -rh
#!/usr/bin/env python3
# coding: utf-8
import pandas as pd
import sys
import os
# pass in infile and CMSX assignment name as commandline args
if len(sys.argv) < 3:
print("Usage: python3 {}".format(os.path.basename(__file__))\