Skip to content

Instantly share code, notes, and snippets.

@lpar
lpar / petstore2.yaml
Created January 12, 2022 16:53
Modified petstore.yaml to demonstrate openapi-generator bug
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: >-
This is a sample server Petstore server. For this sample, you can use the api key
`special-key` to test the authorization filters.
version: 1.0.0
title: OpenAPI Petstore
license:
@lpar
lpar / ec2tags.go
Created November 12, 2020 00:23
How to fetch the tags for the current EC2 instance, from Go, using only official AWS Go SDK calls.
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 (
"errors"
"fmt"
"github.com/aws/aws-sdk-go/aws"
@lpar
lpar / elephantoplasty.sh
Last active June 15, 2020 16:47
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
lpar / ocrimg.rb
Created November 11, 2019 17:17
OCR random images using Google Cloud Vision and put the results in the Finder metadata for macOS Spotlight search
# 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:
# https://cloud.google.com/vision/docs/setup
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path-to-google-cloud-vision-credentials-file.json"
require "shellwords"
@lpar
lpar / KotlinPipeline.md
Last active September 12, 2019 10:16
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
lpar / moon.c
Last active June 16, 2023 22:24
A small C program to add the current moon phase to your prompt
#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
lpar / config.go
Last active May 1, 2018 18:25
Very simple example of reading a config file into an object which provides an interface for fetching config values
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
type Config interface {
@lpar
lpar / noo.json
Last active April 26, 2018 20:41
Quick test of YAML parsing in Go
[{"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
lpar / mviplayer.go
Last active March 3, 2018 15:49
Rename radio shows downloaded from BBC iPlayer with get_iplayer to have human-friendly filenames
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 http://www.wtfpl.net
import (
"fmt"
@lpar
lpar / Evernote filing droplet.dmg
Last active August 27, 2021 22:40
AppleScript droplet to file documents into specific Evernote notebooks