Skip to content

Instantly share code, notes, and snippets.

Avatar

Brandur Leach brandur

View GitHub Profile
@brandur
brandur / go.mod
Last active February 8, 2023 03:29
PartialEqual implementation
View go.mod
module github.com/brandur/prequire
go 1.19
require github.com/stretchr/testify v1.8.1
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
@brandur
brandur / uuid.rb
Created April 14, 2022 00:34
UUID data type in Ruby
View uuid.rb
# typed: strict
# frozen_string_literal: true
require "base32"
require "securerandom"
require "ulid"
# A type to represent UUIDs. Particularly useful for annotating fields in API
# representations or Sorbet parameters to help prevent accidentally mixing up
# UUIDs and EIDs as they're being passed around as loose strings.
@brandur
brandur / ractor_worker_pool.rb
Created January 13, 2021 17:37
Ractor worker pool
View ractor_worker_pool.rb
require 'kramdown'
require 'redcarpet'
require 'toml'
require 'yaml'
#
# pool
#
class WorkerPool
@brandur
brandur / downsize.rb
Created March 10, 2020 17:57
Image resize and optimize script
View downsize.rb
#!/usr/bin/env ruby
#
# Downsizes and optimizes (for size) an image so that it can be suitably/easily
# sent to people via email.
#
TARGET_DIR = "#{Dir.home}/Downloads"
TARGET_WIDTH = 2000
@brandur
brandur / github-actions-first-impressions.md
Last active November 7, 2019 19:45
GitHub Actions first impressions
View github-actions-first-impressions.md

Overall: very good experience. My migration from Travis involved quite a few prerequisites to get everything working in the same way again, and I was pleased to find all of them available in some form on GitHub Actions.

Here a couple problems I ran into:

  • Although there's a story for running background services like Postgres, there doesn't seem to be much of one for interacting with them with client tooling. After Postgres is running, I often want to createdb or raise a schema with psql. I ended up installing postgres via apt-get to get these tools, but it's mostly just good luck that the version drift between these old LTS versions and Postgres running in my container hasn't been too great for things not to work.

  • The above is true for all command line utilities. If I want Imagemagick, I have the choice between (1) Ubuntu's ancient version, and (2) running everything through a Docker container, and

@brandur
brandur / keybindings.json
Created September 8, 2019 21:01
VS Code Settings
View keybindings.json
[
//
// Ctrl + j/k for up/down in ALL the places
//
{
"key": "ctrl+j",
"command": "cursorDown",
"when": "textInputFocus"
},
{
@brandur
brandur / main.go
Created August 10, 2018 22:52
Request re-use
View main.go
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
@brandur
brandur / main.go
Created May 23, 2018 12:51
stripe-go API candidate #3: types with an interface, working
View main.go
// This example is similar to candidate #2, but compiles because we make sure
// to define an alternate type for int64 (Int64) that we're allowed to add the
// Convert function to.
//
// This approach works, and is fairly clever, but ergonomically it looks very
// similar to the pointer approach in candidate #1. You use a type conversion
// instead of a function call when invoking Int64, but they look identical in
// code.
//
// Arguably, it has a small advantage over pointers in that because Int64 here
@brandur
brandur / main.go
Last active May 21, 2018 17:35
stripe-go API candidate #3: types with an interface, working
View main.go
// This example is similar to candidate #2, but compiles because we make sure
// to define an alternate type for int64 (Int64) that we're allowed to add the
// Convert function to.
//
// This approach works, and is fairly clever, but ergonomically it looks very
// similar to the pointer approach in candidate #1. You use a type conversion
// instead of a function call when invoking Int64, but they look identical in
// code.
//
// Arguably, it has a small advantage over pointers in that because Int64 here
@brandur
brandur / build-failure.md
Created November 25, 2016 20:07
Build Failure
View build-failure.md

The linter is expecting that whitespace line up with an open parenthesis. In particular, this section starting on line 115:

        try:
            try:
                if(session is not None):
                    result = session.request(method,
                                                url,
                                                headers=session.headers,
                                                data=post_data,