Skip to content

Instantly share code, notes, and snippets.

@garthk
garthk / xdg.plugin.zsh
Created August 30, 2023 21:55
zsh XDG directory specification environment variables plugin
XDG_DATA_DIRS=/usr/local/share:/usr/share
XDG_CONFIG_DIRS=/etc/xdg
case $(uname) in
Linux)
XDG_CONFIG_HOME="$HOME/.config"
XDG_CACHE_HOME="$HOME/.cache"
XDG_DATA_HOME="$HOME/.local/share"
XDG_STATE_HOME="$HOME/.local/state"
XDG_RUNTIME_DIR="/run/user/$(id -u)"
@garthk
garthk / README.md
Last active August 21, 2022 04:26
Fixing Docker on QNAP
$ export DOCKER_HOST=tcp://fnord.local:2376 DOCKER_TLS_VERIFY=1
$ docker ps
An error occurred trying to connect: Get https://fnord.local:2376/v1.21/containers/json: x509: certificate is valid for fnord, 192.168.23.23 , localhost, not fnord.local
$ ssh admin@fnord.local
# /sbin/setcfg global realm local -f /etc/config/smb.conf
# /etc/init.d/network.sh restart
# hostname -f
fnord.local
# cd $(dirname $(readlink /etc/init.d/container-station.sh))
@garthk
garthk / demo.go
Last active February 21, 2022 22:50
Propagating OpenTelemetry trace context through the HTTP to GRPC gateway to the request handlers
package demo
import (
"context"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
@garthk
garthk / README.md
Created February 18, 2022 22:37
/usr/share/dict/wordle

dict wordle

A dump taken 2022-02-19 of the NY Times version of the Wordle dictionary, suitable for installation as /usr/share/dict/wordle.

@garthk
garthk / dumpsqlite3tocsv.py
Created May 1, 2012 01:07
Unicode-safe Python script to dump sqlite3 tables to CSV for Trac data extraction
#!/usr/bin/env python
"""
Script to open a sqlite3 database and dump all user tables to CSV files.
Tested in Unicode-rich environment.
Usage:
dumpsqlite3tocsv foo.db
"""
import sqlite3, csv, codecs, cStringIO, os, os.path
@garthk
garthk / example.ex
Created February 17, 2021 21:37
Forging span links using OpenCensus and Honeycomb
@doc """
Forge links between spans.
Preferred, but not supported by our reporter:
:PARENT_LINKED_SPAN
|> :oc_span.link(link_trace_id, link_span_id, %{})
|> :oc_trace.add_link(span_ctx)
... but that's ok, [Honeycomb can link using the attributes of extra spans][send-links].
@garthk
garthk / flash_leds_on_boot.py
Created January 30, 2021 06:55
Flash LEDs on boot #lca2021
# Flash configured LEDs on boot.
import aiko.led
import time
import binascii
DURATION_MS = 100
COLOURS = ["e40303", "ff8c00", "ffed00", "008026", "004dff", "750787"]
GAMMAS = [v for v in binascii.a2b_base64(b"".join([
# Overkill, but I wanted the orange to look orange.
@garthk
garthk / bundler.py
Created December 18, 2020 05:23
Poetry Lambda bundler
#!/usr/bin/env python3
"""
Bundle the converter.
Inspiration: https://github.com/python-poetry/poetry/pull/2682
"""
from argparse import ArgumentParser
from contextlib import contextmanager
@garthk
garthk / PASTE_ME.exs
Last active November 5, 2020 19:08
Watch all Phoenix.LiveView and LiveComponent handle_event callbacks
(fn gl ->
:dbg.stop_clear()
repr = fn
%Phoenix.LiveView.Socket{} -> "socket"
v -> inspect(v)
end
{:ok, _} =
:dbg.tracer(
@garthk
garthk / smuggle.ex
Last active October 13, 2020 02:58
Smuggle Terms as Self-Extracting Elixir
defmodule Smuggle do
@moduledoc """
Make it easier to smuggle data from one system to another.
If your target is an `iex` prompt:
Smuggle.dump(value)
# copy
# paste into other iex