Skip to content

Instantly share code, notes, and snippets.

View dln's full-sized avatar
🚀

Daniel Lundin dln

🚀
View GitHub Profile
@dln
dln / slog.go
Created November 18, 2022 11:25
structured logging in golang
package main
import (
"errors"
"os"
"golang.org/x/exp/slog"
)
func main() {
@dln
dln / pw
Last active August 31, 2022 08:58
A convenience script for using secrets on the commandline using keyctl as keyring
#!/bin/bash
#
# Author: Daniel Lundin <[email protected]>
#
# Convenience script to hide sensitive variables on the command line.
# Uses keyctl to store secrets in the keyring.
#
# Example usage: mycommand --user=foo --password=$(pw mypass)
set -eo pipefail
@dln
dln / test-csv-with-header.py
Last active August 25, 2022 10:07
csv processing with duckdb and arrow
#!/usr/bin/env python
import duckdb
import pyarrow as pa
import pyarrow.csv as csv
# curl -L https://www.stats.govt.nz/assets/Uploads/Annual-enterprise-survey/Annual-enterprise-survey-2021-financial-year-provisional/Download-data/annual-enterprise-survey-2021-financial-year-provisional-csv.csv | gzip > /tmp/test-header.csv.gz
data = csv.read_csv('/tmp/test-header.csv.gz')
con = duckdb.connect()
@dln
dln / tpm2-pkcs11-init-ssh.sh
Created March 27, 2022 10:52
Initialize a tpm-pkcs11 store for use with openssh
#!/bin/bash
set -e
store=$1
if [ -z "$store" ]; then
echo "Usage: $0 [store-name]"
exit 1
fi
export TPM2_PKCS11_STORE=$HOME/.local/share/tpm2-pkcs11/${store}
@dln
dln / scheduled-cloudbuild.sh
Created September 21, 2021 20:03
Cloud Build on a Schedule, without Trigger.
PROJECT_ID=myproject
gcloud scheduler jobs create http ${PROJECT_ID}-run-build \
--schedule='1 12 * * *' \
--uri=https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/builds?alt=json \
--message-body-from-file=- \
--oauth-service-account-email=${PROJECT_ID}@appspot.gserviceaccount.com \
--oauth-token-scope=https://www.googleapis.com/auth/cloud-platform \
<<EOF
{ "steps": [
{
@dln
dln / plastic-configure-client
Created September 18, 2021 11:10
Configures plasticscm client. Useful for CI jobs.
#!/bin/bash
set -eo pipefail
function _ensure_var() {
if [ -z "${!1}" ]; then
echo "$1 must be set"
exit 1
fi
}
@dln
dln / Dockerfile
Created July 1, 2021 12:29
Reproducible grpc build w/go using specific versions for protoc-gen-go + friends
FROM golang:1.16-buster AS builder
WORKDIR /src
RUN apt-get update && apt-get install -qy --no-install-recommends npm
COPY Makefile ./
RUN make deps
FROM builder AS build
WORKDIR /src
ENV GOPROXY="https://proxy.golang.org"
COPY go.mod go.sum ./
SHELL := /usr/bin/env bash -o pipefail
PROJECT := myproject
HTTPS_PROTOS := https://github.com/shelmangroup/myproject.git
SSH_PROTOS := ssh://[email protected]/shelmangroup/myproject.git
BUF_VERSION := 0.43.2
PROTOC_GEN_GO_VERSION := v1.26.0
PROTOC_GEN_GO_GRPC_VERSION := v1.1.0
@dln
dln / clip.sh
Created June 19, 2021 09:48
Copy to clipboard using OSC 52. Works over remote in most terminals.
#!/bin/sh
exec echo -en "\x1b]52;c;$(base64 -w0)\x07"
@dln
dln / envoy-static.yaml
Created June 3, 2021 20:31
Minimal envoy config with static endpoints
static_resources:
listeners:
- name: http
address:
socket_address: { address: 0.0.0.0, port_value: 8080 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager