Skip to content

Instantly share code, notes, and snippets.

lpar / ec2tags.go
Created Nov 12, 2020
How to fetch the tags for the current EC2 instance, from Go, using only official AWS Go SDK calls.
View ec2tags.go
package main
// An example of obtaining the tags for the current EC2 running instance,
// from a Go program running inside the instance, using the official AWS SDK (v1).
import (
lpar /
Last active Jun 15, 2020
Change the name of your default Git branch to `trunk`.
#!/bin/sh -e
# This is a terrible hack of a Github script to change the name of your
# default or main branch from 'master' to 'trunk', both in your local
# repo and on Github. I don't usually write shell scripts, so if someone
# wants to clean it up and make it robust, that'd be great.
# As to why you might want to rename your default branch...
# Consider that the entire metaphor of source control is that of a
lpar / ocrimg.rb
Created Nov 11, 2019
OCR random images using Google Cloud Vision and put the results in the Finder metadata for macOS Spotlight search
View ocrimg.rb
# Ruby script to OCR random JPEG and PNG files using Google Cloud Vision,
# then add the results to the macOS Finder metadata for Spotlight search purposes.
# Before you can use this you need to set up billing for Google Cloud Vision, and
# download the public/private key credentials as a JSON file. See:
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path-to-google-cloud-vision-credentials-file.json"
require "shellwords"
lpar /
Last active Sep 12, 2019
Example of a processing pipeline in Kotlin — once with threads and BlockingQueue, once with channels and suspend functions

Kotlin pipeline example

Example of a processing pipeline in Kotlin, implemented two different ways:

  1. Using JVM threads and BlockingQueue (package threads)
  2. Using Kotlin coroutines and channels (package coroutines)

The pipeline in both cases goes Source -> Filter -> Output, with all three stages containing blocking code.

lpar / moon.c
Last active Jul 27, 2021
A small C program to add the current moon phase to your prompt
View moon.c
#include <stdio.h>
#include <string.h>
#include <time.h>
* Output the current moon phase as an emoji for your prompt.
* Build:
* gcc -o moon moon.c
lpar / scurl.js
Created Mar 18, 2019
scurl.js: fetch web pages, process them with Mozilla Firefox Readability, write the results as html files to squirrel away
View scurl.js
const request = require("request");
const Readability = require("readability");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fs = require("fs");
function makeCallback(url) {
return function callback(error, response, body) {
if (error || response.statusCode != 200) {
lpar / config.go
Last active May 1, 2018
Very simple example of reading a config file into an object which provides an interface for fetching config values
View config.go
package main
import (
type Config interface {
lpar / noo.json
Last active Apr 26, 2018
Quick test of YAML parsing in Go
View noo.json
[{"designation":"419880 (2011 AH37)","discovery_date":"2011-01-07T00:00:00.000","h_mag":"19.7","i_deg":"9.65","moid_au":"0.035","orbit_class":"Apollo","period_yr":"4.06","pha":"Y","q_au_1":"0.84","q_au_2":"4.26"}
,{"designation":"419624 (2010 SO16)","discovery_date":"2010-09-17T00:00:00.000","h_mag":"20.5","i_deg":"14.52","moid_au":"0.028","orbit_class":"Apollo","period_yr":"1","pha":"Y","q_au_1":"0.93","q_au_2":"1.08"}
,{"designation":"414772 (2010 OC103)","discovery_date":"2010-07-28T00:00:00.000","h_mag":"19","i_deg":"23.11","moid_au":"0.333","orbit_class":"Apollo","period_yr":"1.31","pha":"N","q_au_1":"0.39","q_au_2":"2"}
,{"designation":"414746 (2010 EH20)","discovery_date":"2010-03-06T00:00:00.000","h_mag":"18","i_deg":"23.89","moid_au":"0.268","orbit_class":"Amor","period_yr":"4.24","pha":"N","q_au_1":"1.25","q_au_2":"3.99"}
,{"designation":"407324 (2010 OB101)","discovery_date":"2010-07-18T00:00:00.000","h_mag":"20.7","i_deg":"9.12","moid_au":"0.111","orbit_class":"Apollo","period_yr":"2.06","pha":"N"
lpar / mviplayer.go
Last active Mar 3, 2018
Rename radio shows downloaded from BBC iPlayer with get_iplayer to have human-friendly filenames
View mviplayer.go
package main
// This is a quick Go program to rename radio shows downloaded from BBC iPlayer
// by removing the program IDs and _original from the end of the filename
// and converting underscores to spaces.
// Copyright status: WTFPL
import (
lpar / Evernote filing droplet.dmg
Last active Aug 27, 2021
AppleScript droplet to file documents into specific Evernote notebooks