Skip to content

Instantly share code, notes, and snippets.

View jeremy-rifkin's full-sized avatar
🐉

Jeremy Rifkin jeremy-rifkin

🐉
View GitHub Profile
@jeremy-rifkin
jeremy-rifkin / dhcp_starvation.py
Created April 25, 2020 01:47
DHCP Starvation Attack (Python/Scapy)
#!/bin/python3
from scapy.all import *
import binascii
conf.checkIPaddr=False
display = False
def run_dhcp_transaction(requestMAC, hostname, interface="eth0"):
localmac = get_if_hwaddr(interface)
@jeremy-rifkin
jeremy-rifkin / blackwhite_filter.py
Created June 2, 2020 22:09
Filter black and white images from a directory
# Filter black and white images from a directory
# walk the photos/ directory and copy bw photos
# to the bw/ directory.
# Runs in parallel to help with analyzing large
# batches of photos.
import colorsys
import multiprocessing
import os
import shutil
@jeremy-rifkin
jeremy-rifkin / 1d_kmeans.js
Created June 4, 2020 03:18
simple javascript implementation of the k-means algorithm for 1 dimentional data and the silhouette method for calculating the optimal number of clusters
// Couple quick utilities
// compute the average of an array
function average(data) {
let sum = 0;
for(let i = 0, l = data.length; i < l; i++)
sum += data[i];
return sum / data.length;
}
// compute the variation of an array
function variation(data) {
@jeremy-rifkin
jeremy-rifkin / README.txt
Last active January 2, 2021 01:31
C++ utility for tracking memory allocations and identifying memory leaks
Include "memory_tracker.h" in every source file where you want to track allocations.
The memory tracker header should come after all other includes.
Include -DMEMORY_DEBUG in the build to enable memory tracking.
@jeremy-rifkin
jeremy-rifkin / stringf.cpp
Last active September 11, 2021 06:20
c++ string formatting
#include <assert.h>
#include <string>
template<typename... T> std::string stringf(T... args) {
int length = snprintf(0, 0, args...);
if(length < 0) assert(("invalid arguments to stringf", false));
std::string str(length, 0);
snprintf(str.data(), length + 1, args...);
return str;
}
@jeremy-rifkin
jeremy-rifkin / non-recursive-ackermann.py
Created November 10, 2020 08:26
To show a friend (who confused recursion and primative recursion) that the ackermann function can be computed without recursion.
# definition recursive ackermann
def A(m, n):
if m == 0:
return n + 1
elif n == 0:
return A(m - 1, 1)
else:
return A(m - 1, A(m, n - 1))
# non-recursive ackermann
@jeremy-rifkin
jeremy-rifkin / file_sample.py
Created November 25, 2020 19:10
Quick utility to pick n random files from a directory
#!/usr/bin/python
import os
import shutil
import sys
import random
def pick_random(src, dest, N):
all_files = []
for path, dirs, files in os.walk(src):
for f in files:
@jeremy-rifkin
jeremy-rifkin / ifunny_filter.py
Last active June 28, 2023 11:58
A script to detect photos with "ifunny" watermarks and filter them from other photos.
# This is a program to filter photos with ifunny watermarks.
# I wrote this script for personal use to separate saved ifunny memes from other photos on my phone.
# The script is fully parallelized and is able to make good use of technologies like Intel
# hyperthreading because substantial program time is spent in IO. Bottleneck will be IO.
#
# Watermark false positive rate appears to be < 1/500
# Watermark false negative rate appears to be ~ 1/500
# False positive / negative rate checked with manual spot check sample size = 500.
#
# Rifkin 2020
@jeremy-rifkin
jeremy-rifkin / playtime.py
Created November 26, 2020 01:25
Script to parse minecraft server logs and add up users' playtime.
#!/bin/python
# Script to parse minecraft server logs and add up users' playtime.
# Usage: python3 playtime.py path/to/logs
#
# Rifkin 2020
import datetime
import gzip
import os
@jeremy-rifkin
jeremy-rifkin / duplicate_file_resolution.py
Created December 3, 2020 03:22
7zip has trouble compressing a directory on windows if it contains two filenames which differ only in capitalization... This script will find problematic file pairs and delete conflicts.
import os
import sys
def main():
filedict = {}
for path, dirs, files in os.walk(sys.argv[1]):
for f in files:
full_path = os.path.join(path, f)
l = full_path.lower()
if l not in filedict: