Skip to content

Instantly share code, notes, and snippets.

View kristopolous's full-sized avatar
💣
New releases are coming soon!

chris mckenzie kristopolous

💣
New releases are coming soon!
View GitHub Profile
function wtf {
local -a files
while IFS= read -r i; do
files+=("$i")
done
local width=$(( ( $(tput cols) * 4 ) / 5))
local head=$(( width / 2 ))
local question="$1"
local each_question
#!/bin/bash
tool=./vast.py
tmp=$(mktemp -d --suffix .vastai)
tmp_host=$(basename $tmp)
instance=$1
_start=${2:-11000}
read -r port ip <<EOF
$($tool show instance $instance --raw | jq -r '.ports["22/tcp"][0].HostPort,.public_ipaddr' | tr '\n' ' ' )
EOF
ssh_url="ssh://root@$ip:$port"
@kristopolous
kristopolous / vast_catalog-v6.py
Last active January 29, 2025 18:03
vast_catalog-v6.py
#!/usr/bin/env python
#
# Due to the design of the sdk, pylint has a false
# positive for the functions.
#
# pylint: disable=assignment-from-no-return
import csv
import json
import math
ssh() {
local _ssh="/usr/bin/ssh"
local n=""
[[ "$*" =~ \/ ]] || { $_ssh $*; return }
echo "$*" | tr "/" " " | rev | while read -d' ' i; do
i=$(echo "$i" | rev)
[[ -n "$n" ]] && n="\"$n"\"
n="$_ssh $i $n"
done
i=$(echo "$i" | rev)
@kristopolous
kristopolous / covid-rent-investment.pl
Created June 7, 2023 18:15
The ROI if you decided to withhold your rent during COVID and invest it instead in LA county
#!/usr/bin/python3
import math
import numpy as np
for roi in np.arange(1.01, 1.07, 0.01):
monthly = math.log(roi)/12
rent = 1000
ttl = 0
# "From March 2020 - Sept 2021 is due by Aug 2023"
@kristopolous
kristopolous / merely-theoretical.sh
Last active May 4, 2023 06:37
Well well, I've never actually run this ...
#!/bin/bash
# nmap -sn subnet > scan
netmask=255.255.254.0
gw=172.19.248.1
cat > try.awk << ENDL
{
switch(NR % 3) {
case 0:
mac=\$3
@kristopolous
kristopolous / 7segscroll.ino
Created December 14, 2022 18:35
7segment scroll
#include <TM1637.h>
//
// This is just some mish-mash of a bunch of things but it's posted for the video over here:
// https://youtu.be/JN4j-aCagH0
//
// How you set the date:
// exec 3<> /dev/ttyUSB0
// printf "$(date "+obase=16;4096+(%H*60+%M)" | bc | sed -E s'/(..)/\\x\1/g')" > /dev/ttyUSB0
// exec 3<&-
@kristopolous
kristopolous / plug.py
Created November 13, 2022 10:33
A simple Emporia command line interface
#!/usr/bin/python3
import pyemvue as pyem, json, sys
with open('keys.json') as f:
data = json.load(f)
v = pyem.PyEmVue()
v.login(id_token=data['id_token'],
access_token=data['access_token'],
refresh_token=data['refresh_token'],
token_storage_file='keys.json')
@kristopolous
kristopolous / top-10-slow.sh
Last active November 3, 2022 02:59
top-10 URIs in the apache log in pure bash
#!/bin/bash
# This is a very crazy 1-liner that only uses builtins
#set -o noglob;declare -a mapper=() count=();exec 3<access.log; while read -a lines -u 3; do [[ ${lines[5]} != '"GET' ]] && continue; page="${lines[6]}"; ix=0;for i in "${mapper[@]}"; do [[ "$page" = "$i" ]] && break; (( ix++ )); done ; if [[ "$page" = "$i" ]]; then (( count[$ix] ++ )); else mapper+=( $page ); count[$ix]=1; fi; done; (( max=-1, winner=-1, show=10 )); while (( show > 0 )); do ix=0;for i in "${count[@]}"; do (( i > max )) && (( max=i, winner=ix )) ;(( ix++ ));done; builtin echo -e "${count[winner]}\t${mapper[$winner]}";(( count[$winner]=-1, max=0, show-- )); done;
# Here's a formatted nice version
# We need to make sure that bash doesn't do weird substitution
set -o noglob
declare -a mapper=() count=()
# And to avoid cat we do file descriptors
exec 3<access.log
@kristopolous
kristopolous / animal-say.sh
Last active October 31, 2022 05:05
Animal-say fortune, like cowsay but more animals and faster
#!/bin/bash
cat << ENDL
- - - ~ ~~~~==~#=###=#~==~~~~~ ~ - - -
$(fortune | sed -E 's/^\s+//g' | fold -sbw 40 | sed -E 's/^/ /')
- - - ~ ~~~~==~#=###=#~==~~~~~ ~ - - -
$(curl -s https://9ol.es/animals.db | shuf -n 1 | tr 'F' '\n' | gawk ' { if (FNR == 1) { printf " \\ ";} else if (FNR == 2) { printf " \\ "; } else { printf " " }; print $0 } ';)
ENDL