Skip to content

Instantly share code, notes, and snippets.

@geberl
geberl / script.go
Created July 12, 2023 07:26
Go scripting, chmod +x script.go
///usr/bin/env go run "$0" "$@"; exit
package main
import "fmt"
func main() {
fmt.Println("My first Go script")
}
@geberl
geberl / traceroute.go
Created October 15, 2022 09:27
Traceroute a Hetzner Cloud Load Balancer before and after deletion in Go
package main
import (
"fmt"
"net"
"os"
"sync/atomic"
"github.com/aeden/traceroute"
)
@geberl
geberl / parse_certs.go
Last active October 15, 2022 09:25
Parse certificate *.pem files, because some new parsing errors got added in Go 1.15 and what previously may have been parsed ok might not now.
package main
import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
@geberl
geberl / example_oklog_run_group.go
Last active October 15, 2023 20:59
Example oklog/run group
package main
import (
"context"
"net/http"
"os"
"syscall"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
@geberl
geberl / .hammerspoon
Last active October 21, 2020 12:38
My Hammerspoon (https://github.com/Hammerspoon/hammerspoon) config file. Set up to help with window management on a DELL U3419W widescreen (3440x1440) monitor.
-------------------------------------------------------------------------------
-- ShiftIt / Spectacle style window manager
-------------------------------------------------------------------------------
-- Source/inspiration: https://github.com/fikovnik/ShiftIt/wiki/The-Hammerspoon-Alternative
-- Docs hotkey module: https://www.hammerspoon.org/docs/hs.hotkey.html
-- Docs keycodes: https://www.hammerspoon.org/docs/hs.keycodes.html#map
hs.window.animationDuration = 0.1
units = {
tell application "System Events"
set procs to processes
set windowName to {}
repeat with proc in procs
# Ignore applications that are hidden altogether (cmd+H or via command from the application's menu)
# Applications open on different desktops are ignored alltogether
if (visible of proc) then
if exists (window 1 of proc) then
repeat with w in windows of proc
# Ignore application windows miniaturezed to the dock
@geberl
geberl / check_filetype.swift
Created February 29, 2020 19:12
Get the file type from NsDraggingInfo's draggingPasteboard
func checkFileType(sender: NSDraggingInfo) -> Bool {
let pasteboard = sender.draggingPasteboard()
// Iterate over accepted types of currently selected Workflow in its order of preference
// Return as soon as a present type of the dropped item matches an accepted type of the Workflow
for acceptedType in Workflows.activeAccepts {
if String(acceptedType) == "filename" {
if pasteboard.types?.contains("public.file-url") == true {
// File URLs from Finder (files, folders, drives)
@geberl
geberl / safe_unwrap.go
Last active December 22, 2019 10:13
Pointers vs literals & Swift-style safe unwrapping
package main
import "fmt"
type person struct {
firstName string
lastName *string
addressAsValue address
addressAsPointer *address
@geberl
geberl / inotify_watcher.sh
Last active November 29, 2019 11:36
Watch Envoy's config files and use the required mv command to trigger a reload
#!/bin/bash
# Install the inotify tools in Dockerfile:
# RUN apt-get update && apt-get install -y inotify-tools
# Then establish the watch in the Docker entrypoint.sh:
# ./inotify_watcher.sh &
inotifywait --monitor "/etc/envoy/k8s/" --event create --event modify --event moved_to |
while read path action file; do
@geberl
geberl / file_path_build_vs_run.go
Created October 28, 2019 07:43
Reliably access a file that resides next to the code/binary, whether it's started via go run or go build
package main
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
)
func main() {