Skip to content

Instantly share code, notes, and snippets.

View brandur's full-sized avatar

Brandur Leach brandur

View GitHub Profile
@brandur
brandur / go.mod
Last active July 25, 2023 21:41
PartialEqual implementation
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
# 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 / go-pipelines.md
Last active June 3, 2023 15:42
Go Pipelines

Go Pipelines

This document demonstrates a basic pipeline in Go and talks about a risk in in implementing them. Keep in mind that:

  • Using FizzBuzz here is contrived, but quite a nice way to demonstrate the concept. Obviously there is no advantage to running the basic workload of FizzBuzz in a Goroutine, but if the task involved heavy computation or long lived I/O, it starts to make a lot more sense.
  • The problem discussed only applies to Goroutines that actually need to have a way to
@brandur
brandur / redis-cell-informal-benchmarks.md
Last active June 3, 2023 02:31
redis-cell Informal Benchmarks

redis-cell Informal Benchmarks

I got these results when comparing CL.THROTTLE to SET on my early 2015 13" 3.1 GHz i7 MacBook Pro (not connected to a power source at the time):

$ ruby bench.rb
SET
Took total of: 5.975439 s
Per iteration: 5.975439e-05 s (0.05975439 ms)
@brandur
brandur / force-reset.md
Last active January 3, 2022 16:07
Force pull request's diff to reset itself against target branch

Force pull request's diff to reset itself against target branch

git checkout feature-branch
# empty commit; don't worry, this will not show up in the final pull
git commit --allow-empty -m "Empty commit"
git push origin feature-branch
# hard reset to before empty commit
git reset --hard HEAD~
git push -f origin feature-branch
@brandur
brandur / re-re-gh-ost.md
Last active May 20, 2021 16:17
RE: RE: gh-ost
@brandur
brandur / ractor_worker_pool.rb
Created January 13, 2021 17:37
Ractor worker pool
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
#!/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 / twitter-auth.md
Last active February 13, 2020 22:13
Twitter auth

Easy Twitter API OAuth 2 Access

  1. Go to your applications. Create a new one, and find the values in the Consumer Key and Consumer Secret fields.

  2. Use OAuth client information to produce an OAuth 2 access token:

    curl -i --user <consumer_key>:<consumer_secret> -X POST https://api.twitter.com/oauth2/token -d "grant_type=client_credentials"
    
    {"access_token":"<oauth2_token>","token_type":"bearer"}% 
    
@brandur
brandur / keybindings.json
Created September 8, 2019 21:01
VS Code Settings
[
//
// Ctrl + j/k for up/down in ALL the places
//
{
"key": "ctrl+j",
"command": "cursorDown",
"when": "textInputFocus"
},
{