Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / hammerspoon-cool.txt
Created October 4, 2015 19:53
Explanation of using hammerspoon to watch for configuration changes
Simple configuration reloading
You may have noticed that while you're editing the config, it's a little bit annoying to have to keep choosing the Reload Config menu item every time you make a change. We can fix that by adding a keyboard shortcut to reload the config:
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
We have now bound ⌘+⌥+⌃+R to a function that will reload the config and display a simple alert banner on the screen for a couple of seconds.
One important detail to call out here is that hs.reload() destroys the current Lua interpreter and creates a new one. If we had any code after hs.reload() in this function, it would not be called.
@iolloyd
iolloyd / in.sh
Last active October 2, 2024 08:53
file_or_pipe
#!/bin/bash
# Function to process input (file or stdin)
process_input() {
while IFS= read -r line; do
# Perform any processing here
echo "$line"
done
}
@iolloyd
iolloyd / Spot the Hijack
Created September 2, 2012 20:09
Use Audio Hijack Pro to record Spotify tracks while you listen
* Script to record and tag spotify tracks, by Lloyd Moore *)
(* Make sure you are already recording in Audio Hijack Pro with a session called 'spotifySession' *)
tell application "Spotify"
set currentTrack to (current track)
set trackName to (name of currentTrack)
tell application "Audio Hijack Pro"
set theSession to my getSession()
end tell
repeat
@iolloyd
iolloyd / ezdl.sh
Last active November 1, 2023 20:18
Script to download from easynews
#!/bin/sh
USER=god
PASS=allyourbasearebelongtous
FILE=`echo "$1" | sed 's_\(https://\)\(.*\)\(secure\.\)\(.*\)\(/.*\)_\2\4\5_'`
FILE=`echo "$1" | sed 's_\(https://\)\(boost4-\)*\(.*\)\(secure\.\)\(.*\)\(/.*\)_\3\5\6_'`
CMD='curl -Y 12800 -y 5 -C - -O http://'$USER':'$PASS'@'$FILE
echo $CMD
@iolloyd
iolloyd / ssv.py
Created October 20, 2023 15:32
simple binary shapley values for data records against query output
import itertools
import math
def query_age(dataset):
"""
A query function that returns records with age less than 26.
"""
return [record for record in dataset if record['age'] < 26]
def query_trust(dataset):
@iolloyd
iolloyd / branch_fix.sh
Created December 9, 2016 10:37
Branching from the wrong branch in git
# branch/current <- Branch with commits
# branch/main <- Branch that should have been branched from
# branch/other <- Branch that was actually branched from
git checkout branch/main
git checkout -b branch/correct
git rebase --onto branch/correct branch/other branch/current
@iolloyd
iolloyd / demo.tpl
Last active January 8, 2020 17:56
dynamic inventory from terraform
[kube-master]
${k8s_master_name}
@iolloyd
iolloyd / flask.py
Last active August 27, 2019 19:19
Dynamically generating endpoints based on model in flask
def set_end_point(view_class, endpoint, url, pk='id', pk_type='int'):
view = view_class()
app.add_url_rule(url, defaults={id: None}, view_func=view.as_view, methods=['GET',])
app.add_url_rule(url, view_func=view.as_view, methods=['POST',])
url = '%s/<%s:%s>' % (url, pk_type, pk)
app.add_url_rule(url, view_func=view.as_view, methods=['GET', 'PUT', 'DELETE'])
def register_url(name):
@iolloyd
iolloyd / ec2_connect.sh
Last active August 1, 2019 11:06
AWS EC2 temporarily connect to an instance by id
#!/bin/sh
# Allows you to temporarily connect to an ec2 instance, using
# awscli to first push your own key to the instance, then using ssh
# to log in to the instance.
# Assumes a public key called ec2.pub and a private
# key called ec2.
# Usage ec2_connect.sh i-12345679abcdef <other-user> <other-file>
@iolloyd
iolloyd / golang.secure.small.Dockerfile
Created November 11, 2018 17:46
a super small secure docker container for golang binaries using Alpine and multi-stage builds
# The smallest starting point is the alpine image
FROM golang:alpine as builder
RUN apk update && apk add git && add ca-certificates
RUN adduser -D -g '' appuser
COPY . $GOPATH/src/mypackage/myapp/
WORKDIR $GOPATH/src/mypackage/myapp/
RUN go get -d -v
RUN CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/hello