Skip to content

Instantly share code, notes, and snippets.

View wesinator's full-sized avatar

Wes wesinator

View GitHub Profile
@wesinator
wesinator / objects_dict_metrics.py
Last active May 24, 2020 16:52
Code to count occurrences of unique keys, within object dicts, across list of multiple objects
def sort_dict(dictionary):
# https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value
return dict(sorted(dictionary.items(), key=lambda kv: kv[1], reverse=True))
# Code to count occurrences of unique keys, within object dicts, across list of multiple objects
def count_occurrences_keys(objects_list):
counts = {}
for object in objects_list:
@wesinator
wesinator / requests_json_invalid.py
Last active May 12, 2020 17:37
Demonstrate requests .json() JSONDecodeError on empty or invalid input
import requests, simplejson
resp_blank = "https://httpbin.org/status/200"
resp_200 = "http://httpstat.us/200"
try:
requests.get(resp_blank).json()
except simplejson.JSONDecodeError as e:
print(e)
@wesinator
wesinator / macos_libmagic_file.sh
Created April 16, 2020 16:14
Install latest libmagic file command on macOS
brew install file-formula
/usr/local/opt/file-formula/bin/file -v
@wesinator
wesinator / floor_int.py
Created March 26, 2020 10:53
test proof that python math.floor() is equivalent to int()
import math
for i in range(0, 10000000):
f = i + 0.6
if math.floor(f) != int(f):
print("%.2f floor different from int conv" % f)
print(f)
@wesinator
wesinator / hash_lengths.py
Created March 26, 2020 10:24
enum of hash text repr lengths (double the actual data size)
hash_lengths = {
32: "md5",
40: "sha1",
64: "sha256",
128: "sha512",
}
key = "VkvX7CK7X7*t$x&hssLR6fOyFSaKrFJKx&@#AK*Fnukj@J9J40f1mKaN$nsCNKPe"
def decrypt(enc,offset):
decrypted = ""
for i in range(len(enc)):
decrypted += chr((ord(enc[i]) ^ ord(key[(i + offset) & 0x3f])))
return decrypted
@wesinator
wesinator / ntfsfix.md
Created March 15, 2020 15:47
ntfsfix example
sudo ntfsfix /dev/sdb3
[sudo] password for ubuntu: 
Mounting volume... $MFTMirr does not match $MFT (record 0).
FAILED
Attempting to correct errors... 
Processing $MFT and $MFTMirr...
@wesinator
wesinator / extract_oleobject_payload.sh
Last active March 13, 2020 21:42
Extract oleObject files from Office files
unzip $1 word/embeddings/oleObject*
unzip $1 ppt/embeddings/*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wesinator
wesinator / pip_update_full.md
Last active February 13, 2020 20:31
pip update package and all its dependencies to latest versions