Skip to content

Instantly share code, notes, and snippets.

View aphor's full-sized avatar

Jeremy McMillan aphor

View GitHub Profile
@aphor
aphor / salt_cloud_map_run.py
Created February 23, 2021 02:58
salt_cloud_map_run.py
#!/usr/bin/python3
import salt
import sys
if __name__ == '__main__':
MINION_NAME = 'salt-cloud'
HOSTNAME = sys.env['hostname']
FOLDER = sys.env['folder']
IP = sys.env['ip']
@aphor
aphor / rsync_tm.sh
Last active November 15, 2020 22:15
Rescue a Time Machine backup from a failing readonly volume
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]
then
echo "ERROR: must supply CLI arguments for source and destination paths" >&2 &&
exit 1
fi
export SRCVOL="$1"
export DSTVOL="$2"
@aphor
aphor / Ubuntu1804onZFS.sh
Last active June 14, 2019 14:46
Ubuntu 1804 ZFS root install hack
#!/bin/bash
# Starting from the work detailed on
# https://github.com/zfsonlinux/zfs/wiki/Ubuntu-18.04-Root-on-ZFS
ROOTPASSWD='ch4ng3m3P13453'
if [ -z "$HOSTNAME" ]
then
echo env HOSTNAME must be set >&2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aphor
aphor / .javapath
Created January 4, 2019 21:46
Mac shell java switching
#!/bin/bash
# Put this .javapath file in your home directory with execute permission.
# Run it to create java dotfiles in your home directory to set up
# PATH and JAVA_HOME for indicated java distros
# Source the resulting dotfiles to switch current JAVA
if (return 2>/dev/null)
then
PATH=$(echo "$PATH" |
awk -F: '{for (i=1;i<=NF;i++){print $i}}' |
@aphor
aphor / ReportCpuCount.java
Created November 8, 2018 20:37 — forked from thomasdarimont/ReportCpuCount.java
Using LD_PRELOAD to pass a fake CPU count to Java on Linux
public class ReportCpuCount {
public static void main(String[] args) throws Exception{
while(true){
System.out.printf("#Found %d CPUs%n", Runtime.getRuntime().availableProcessors());
Thread.sleep(1000);
}
}
}
@aphor
aphor / truthy_dict.py
Created November 3, 2018 00:47
Truthy dict()
if {}:
print("yay!")
else:
print("boo!")
@aphor
aphor / abc_def_csv_to_pandas.py
Created October 3, 2018 00:10
ABC DEF files
import os, pandas
cwd = os.getcwd() # this is where to find the csv directories and files
dfs = {} # this is where we will put the pandas DataFrame for each color
for root, dirs, files in os.walk(cwd):
for fn in files:
if fn.endswith(".csv"): # skip non csv files silently
color = fn.split('.',3)[1] # extract color name like 'ABC' or 'DEF'
fqpn = os.path.sep.join((root,fn)) # construct a filename to read
@aphor
aphor / java_signal_exit.md
Created August 12, 2018 19:57
Java default signal handler exit behavior

Thank you to @thobe, please try Neo4J, the coolest NoSQL DB

Tuesday, February 19, 2013 JVMs and kill signals Ever wondered how a JVM reacts to various kill signals? The (intended) behaviour might be documented somewhere already, but I found having a table of > the actual behaviour available quite useful. In particular I wanted to know which kill signals trigger the JVM to run registered shutdown hooks, and > > which kill signals don't actually terminate the JVM. So I decided to compile a table of that information.

I wrote up a small Java application that just registers a shutdown hook that I can detect whether it has executed or not, and then sleeps until I get a chance to kill it:

@aphor
aphor / puffyCloud.md
Last active June 4, 2018 16:52
Puffy Cloud: Ween didn't know how important this song would be to the software industry.
Drift away on a puffy cloud  
Go away on a puffy cloud  
My product is dead from too much vapor  
Cuz (gene) (dean) + I sell too much vapor

Cloudy cloudy cloudy cloud
Cloudy cloud cloudy cloud

Cloudy cloudy cloudy cloud