Skip to content

Instantly share code, notes, and snippets.

View kevinmilner's full-sized avatar

Kevin Milner kevinmilner

View GitHub Profile
@kevinmilner
kevinmilner / RotationCalcs.java
Last active February 22, 2021 21:05
Code for simulating Trevor Bauer on a 4-day pitching rotation with the rest of the 2021 Dodgers on a 5-day rotation
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class RotationCalcs {
@kevinmilner
kevinmilner / ssh_tunnel.bashrc
Last active May 6, 2020 19:04
SSH tunnel management .bashrc functions
FWD_CMD="ssh -f -N -o Compression=no -L $LOCAL_PORT:$REMOTE_HOST:$REMOTE_PORT $FWD_USER@$FWD_HOST"
function sshpid {
SSH_PID=$(ps aux | grep "$FWD_CMD" | grep -v 'grep' | awk '{print $2}')
}
function fwdrunning {
sshpid
if [[ -n $SSH_PID ]];then
echo "ssh tunnel is running with PID $SSH_PID"
@kevinmilner
kevinmilner / terminal_launch_check.bat
Last active February 19, 2020 18:49
Windows batch script to reliably launch gnome-terminal (or another terminal) in WSL
tasklist /FI "IMAGENAME eq vcxsrv.exe" 2>NUL | find /I /N "vcxsrv.exe">NUL
if "%ERRORLEVEL%"=="0" echo X server is running
if not "%ERRORLEVEL%"=="0" start "" "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -ac -terminate -lesspointer -multiwindow -clipboard -dpi auto
chcp utf8
ubuntu run "sh -ic 'if [ -z \"$(pidof dbus-launch)\" ]; then export DISPLAY=127.0.0.1:0.0; dbus-launch --exit-with-x11; fi;'"
ubuntu run "DISPLAY=:0 gnome-terminal --working-directory=/home/kevin; sleep 1"
@kevinmilner
kevinmilner / ZipEntryCopy.java
Created October 19, 2017 19:44
Efficiently copy a zip entry from one archive to another in java without decompressing/compressing with Apache Commons Compress
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
public class ZipEntryCopy {
@kevinmilner
kevinmilner / synology_surveillance_usb_archiver.sh
Created July 28, 2017 23:38
Synology Surveillance Station USB storage archive workaround cron job
#!/bin/bash
# Synology Surveillance Station doesn't let you store recordings on USB storage, which means that you must
# use the internal (often mirrored) disks. This is less than ideal. Unfortunately, just symbolically
# linking the surveillance store directory to one on USB storage causes surveillance station to fail after
# a day or so. This workaround still uses your main storage for recording, but moves older files to USB storage
# for archival. The moved files themselves are symbolically linked back to the original storage location.
#
# Script should be run regularly, either by editing /etc/crontab or through Synology's built in script scheduling.
# Be sure to edit the user inputs below, and set up SS to keep recordings for longer than the external archive period.