Skip to content

Instantly share code, notes, and snippets.

View 0x1b-xyz's full-sized avatar

Jason Stiefel 0x1b-xyz

View GitHub Profile
@0x1b-xyz
0x1b-xyz / DeepMaps.kt
Created September 20, 2023 14:45
Deep merge and deep get on kotlin `Map<String,Any>` maps
import java.util.*
import kotlin.reflect.KClass
/**
* Produces a new map that represents a merge of [source] into [this], returning an immutable view. Map leaves will be
* overwritten from [source] into [this].
*
* @param source Nested [Map<String,Any>] that will be merged over [this]. Must be [Map<String,Any>]
*
* @throws IllegalArgumentException When [source] causes a [ClassCastException] caused by a non-[String] key
@0x1b-xyz
0x1b-xyz / btc_jimmysong.sh
Last active February 17, 2022 16:15
Launches the jimmysong btc jupyter notebooks in a container
#!/bin/bash
# To launch blindly and with great trust:
# $ bash <(curl -s https://gist.githubusercontent.com/jason-stiefel/57f55a14d3f47931edf03a0dd56a5e83/raw/btc_jimmysong.sh)
# Or pass a command and start a shell if you'd rather skip jupyter launch:
# $ bash <(curl -s https://gist.githubusercontent.com/jason-stiefel/57f55a14d3f47931edf03a0dd56a5e83/raw/btc_jimmysong.sh) bash
set -euox pipefail
mkdir -p ${PWD}/sandbox ${PWD}/cache ${PWD}/local
@0x1b-xyz
0x1b-xyz / header.sh
Last active September 16, 2021 22:42
Bash header opts and reminder to declare for subshell assignments
#!/bin/bash
set -euo pipefail; shopt -s inherit_errexit
# Dont.
export MYVAR=$(exit 1) && echo "I'll run because bash is kind of unpredictable"
# Do.
declare MYVAR
MYVAR=$(exit 1) && echo "I wont run because ... well whatever."
@0x1b-xyz
0x1b-xyz / eap_proxy-udmpro-health.sh
Last active August 20, 2021 22:25
A script that manages the lifecycle of the eap_proxy-udmpro container on a UDM PRO between reboots or firmware updates. See https://github.com/pbrah/eap_proxy-udmpro for the upstream image.
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TARGET_HOST="${TARGET_HOST:?"You must define TARGET_HOST"}"
PASSWORD_FILE="${PASSWORD_FILE:?"You must define PASSWORD_FILE"}"
EAP_PROXY_IMAGE="${EAP_PROXY_IMAGE:-"pbrah/eap_proxy-udmpro:v1.1"}"
HC_CONTAINER_NAME="eap_proxy-healthcheck"
UDM_CONTAINER_NAME="eap_proxy-udmpro"
@0x1b-xyz
0x1b-xyz / abspath.sh
Created September 18, 2018 13:48
I hate you bash. Seriously.
# Resolves an absolute path regardless of distribution or arch.
absPath() {
python -c "import os,sys; print os.path.abspath(sys.argv[1])" ${1}
}
set softtabstop=4 shiftwidth=4 expandtab autoindent smartindent
import java.io.*;
import java.util.*;
import java.util.stream.*;
import com.google.common.collect.ImmutableMap;
/*
Given a list of flights (in any order), construct the trip that this list represents. For example, if we have a flight from San Francisco to Los Angeles and a flight from New York City to San Francisco, the trip is "NYC to SFO to LAX".
Assumptions:
- A city will only be visited once per trip. (you can't go back to a given city after visiting it).
- The list will only represent one single trip.
#!/bin/bash
echo "Writing DATATIME_* environment variables out to a properties file ..."
echo "" > ${DATATIME_HOME}/datatime.properties
for ENV in $(env); do
key="$( cut -d '=' -f 1 <<< "${ENV}" )"
val="$( cut -d '=' -f 2- <<< "${ENV}" )"
if [[ ${key} == DATATIME_* ]]; then
key=$(echo $key | tr _ . | tr '[:upper:]' '[:lower:]')
echo "Copying datatime.properties value from environment: ${key}"
# Call with a machine name to load the environment for that machine. Called
# without a machine name it will load a ~/.docker_env file into the shell
# environment and into launchctl
#
# Added a new var to the mix - DOCKER_HOST_IP
function useDockerMachine() {
if [ $# -eq 0 ]; then
if [ ! -f ~/.docker_env ]; then
>&2 printf "Error: No ~/.docker_env file exists. Specify machine to use.\n"
return
@0x1b-xyz
0x1b-xyz / GroovyDates.groovy
Created July 30, 2015 01:22
Date examples I bust out when I'm showing off Groovy
def tomorrow = new Date() + 1
use (TimeCategory) {
def appointment = now + 1.week + 1.days + 15.hours + 10.minutes
def monday = new Date().with { it.clearTime(); it - it.calendarDate.dayOfWeek }
def recurringWeeklyForYear = (1..52).collect { monday + it.weeks }
}