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 / 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 / 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:
@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 / mandelbrot.c
Last active February 8, 2021 23:47
137 char mandelbrot code golf
// 137 char mandelbrot code golf
// collaboration by myself and others on a programming discord server
y=40,x;main(i){for(;y--;puts(""))for(x=170;x--;printf(L" .'-+=%@#"+i/12))for(typeof(0.i)z=i=0;cabs(z)<2&i++<99;z=z*z-x/50.+y/20.i+1+1i);}
// 130 char, lower-detail:
y=40,x;main(i){for(;--y;puts(""))for(x=170;x--;printf(L" *"+i/99))for(typeof(0.i)z=i=0;cabs(z)<2&i++<98;z=z*z-x/50.+y/20.i+1+1i);}
// compiler: gcc, may need -lm
@jeremy-rifkin
jeremy-rifkin / brainf_interpreter.c
Created February 11, 2021 03:20
Code golfed brainf interpreter
// brainf interpreter code golf
// collaboration by some folks on discord and myself
#include <stdio.h>
#define r(c) ;i++;goto w;case c:
i;t[99];s;p=1024;char b[2048];main(int j,char**a) {
fread(b,1,p,fopen(a[1],"r"));
w: switch(b[i]) {
r(45) b[p]--
r(43) b[p]++
r(60) p--
@jeremy-rifkin
jeremy-rifkin / range.h
Last active March 26, 2021 01:06
C++ range iterator
#include <cmath>
#include <cassert>
#include <type_traits>
template<typename T> int sign(T t) {
return t < 0 ? -1 : 1;
}
template<typename T> class range {
typedef typename std::make_signed<T>::type ST;