Skip to content

Instantly share code, notes, and snippets.

View blairdrummond's full-sized avatar

Blair Drummond blairdrummond

View GitHub Profile
@blairdrummond
blairdrummond / vault-reauth.sh
Last active February 9, 2022 01:47
Re-Authenticate with MinIO Instances via Vault
#!/bin/sh
# Re-Authenticate all vault tokens.
# Dependencies: jq, curl
# Example:
#
# $ bash vault-renew.sh
# {
# "minio_gateway_premium": {
# "accessKeyId": "profile-blair-drummond-XXXXXXXXXXXXXXXX",
@blairdrummond
blairdrummond / Makefile
Last active February 15, 2023 13:01
install kubernetes tools
# Works with "darwin" and "linux"
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
# Create a local bin
BIN := /usr/local/bin
# Most of the binaries just grab the latest version.
# For better, or for worse!
TERRAFORM_VERSION := 1.0.6
@blairdrummond
blairdrummond / parse-mpd.py
Created May 8, 2021 16:30
Print mpd.db database file into jsonlines (for jq, or sqlite-utils --nl)
#!/bin/python3
# Convert an mpd.db file into jsonlines.
# Example usage:
#
# > parse-mpd.py /nfs/music | sqlite-utils insert --alter --nl music mpd.sqlite3 music -
#
# Based on: https://github.com/Delapouite/mpdump
#
# NOTE: If your Artist, Album, or Track names start/end with " ",
@blairdrummond
blairdrummond / Main.hs
Created August 14, 2018 17:11
getGenomes function using way too much memory
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
module Main where
-- parsing arguments
import Control.Exception
import Control.Monad
import Data.Semigroup ((<>))
import Options.Applicative
clumps :: (Num a, Ord a) => GHC.Int.Int64 -> GHC.Int.Int64 -> a -> T.Text -> [T.Text]
clumps k l t text = M.keys $ M.filter (>=t) $ (\(m,_,_,_) -> m) $ T.foldl'
(\x y -> slideDrop $ slideInsert x y)
(M.singleton prefix 1, prefix, prefix, k)
text'
where
(prefix, text') = T.splitAt k text
slideInsert (m, word, window, delay) c = let wtail = (snd . fromJust . T.uncons) word
word' = T.snoc wtail c
» Fri Jul 27 23:43 2018 Time and Allocation Profiling Report (Final)
» code +RTS -p -h -M1000m -RTS
» total time = 0.60 secs (596 ticks @ 1000 us, 1 processor)
» total alloc = 1,826,831,176 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
clumps.slideInsert Main code.hs:(24,7)-(26,121) 51.2 54.3
» Fri Jul 27 23:32 2018 Time and Allocation Profiling Report (Final)
» code +RTS -p -h -M1000m -RTS
» total time = 0.27 secs (274 ticks @ 1000 us, 1 processor)
» total alloc = 1,196,325,952 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
clumps Main code.hs:(18,1)-(43,38) 51.8 28.3
@blairdrummond
blairdrummond / clumps.hs
Created July 28, 2018 03:07
Find length k words which occur t or more times in a length L window - Memory is a bit out of control
import Data.List
import Data.String
import Data.Char
import Data.Maybe
import GHC.Int
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as TI
import qualified Data.Map.Strict as M