Skip to content

Instantly share code, notes, and snippets.

from concurrent import futures
import collections
import time
def job(job_id):
time.sleep(job_id)
return job_id
import json
import re
with open("AARON1.DAT", "r") as f:
workoutfile = f.read().strip()
workouts_json = "[" + workoutfile.replace(" }\n}\n{", "},\n{").replace("}\n{", "},\n{").strip()[0:-1] + "]"
try:
workouts = json.loads(workouts_json)
@nijave
nijave / aws-login-setup.sh
Last active January 29, 2020 19:15
Sets up aws-login alias
if [[ ! -d ~/code/aws-login-windows ]]; then
mkdir -p ~/code/aws-login-windows
git clone https://github.com/Root-App/aws-login-windows.git ~/code/aws-login-windows
fi
pushd ~/code/aws-login-windows
git pull
popd
if [[ "$ZSH_NAME" != "" ]]; then
@nijave
nijave / util.py
Created May 19, 2020 14:05
Python helper functions
def find(func, i):
"""
Finds the first match in an iterable
Works like `filter` but returns a single item
"""
try:
return next(filter(func, i))
except StopIterator:
raise ValueError("No matching item found")
#!/usr/bin/env python
# coding: utf-8
# In[27]:
import logging
import json
import requests
import uuid
@nijave
nijave / hvkvp.py
Last active September 8, 2020 13:56
Read Hyper-V key-value pair data on Linux guest
# Inspired by https://github.com/ejsiron/hvkvp
# explanation of format https://www.altaro.com/hyper-v/key-value-pair-data-exchange-3-linux/
# pool_3 host->guest (read-only)
with open("/var/lib/hyperv/.kvp_pool_3", "r") as f:
data = f.read()
# Each k, v is a nul terminated string. k is 512 bytes, v 2048 bytes
# so 2560 bytes is a single item
n = 2560
@nijave
nijave / jupyter.sh
Created October 31, 2020 16:10
Compile code required for Jupyter on FreeBSD (jupyter on opnsense)
# Set up a jail
iocage create -r 12.1-RELEASE -n wheelhouse
iocage set dhcp=on bpf=on vnet=on wheelhouse
iocage start wheelhouse
# Build some wheels inside the jail
iocage console wheelhouse
env ASSUME_ALWAYS_YES=yes pkg update
pkg install -y python38 libzmq4 bash
@nijave
nijave / json_parse.sh
Last active December 22, 2020 01:56
Parallel parse json files (Cloudtrail Logs)
#1/bin/sh
# --line-buffer to prevent json from accidentally getting split in the middle
# -n 128 cat-ing large quantities of files is faster since the programs aren't re-invoked as often (too high and you risk not using all the threads in the final batches)
# -P 125% slightly over subscribe the CPU to lessen the chance of wasting cycles if something becomes blocked
# -q -m 4M make a small file buffer to smooth out I/O (don't make it too large as a single cat process could starve the other threads)
# -rc for single line per json object and "raw" output
# final jq is just to format and colorize the results
# zcat can be used to read json.gz files. This examples read off zfs compressing with zstd
@nijave
nijave / 42-dell-quirks.conf
Last active January 6, 2021 19:35
/usr/share/X11/xorg.conf.d/42-dell-quirks.conf
Section "InputClass"
Identifier "DELL08AF:00 06CB:76AF Touchpad"
MatchProduct "DELL08AF:00 06CB:76AF Touchpad"
MatchIsTouchpad "on"
MatchOS "Linux"
MatchDevicePath "/dev/input/event*"
Driver "mtrack"
#Option "Ignore" "on"
Option "IgnorePalm" "true"
@nijave
nijave / verify.sh
Created February 14, 2021 04:17
OpenSSL Decrypt with x509 Public Key
encrypted_file=some_file
cert=certificate.pem
openssl x509 -pubkey -noout -in $cert -out certificate.key
openssl rsautl -pubin -inkey certificate.key -in some_file