Skip to content

Instantly share code, notes, and snippets.

View cheerfulstoic's full-sized avatar

Brian Underwood cheerfulstoic

View GitHub Profile
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
@cheerfulstoic
cheerfulstoic / log.log
Last active September 16, 2021 11:28
ts-dump / ts-restore logs
2021/09/13 13:36:33 pg_restore: skipping item 3706 TABLE DATA SequelizeMeta
2021/09/13 13:36:33 pg_restore: launching item 3488 CONSTRAINT SequelizeMeta SequelizeMeta_pkey
2021/09/13 13:36:33 pg_restore: skipping item 3707 TABLE DATA table1
2021/09/13 13:36:33 pg_restore: skipping item 3489 INDEX table1_readAt_idx
2021/09/13 13:36:33 pg_restore: skipping item 3490 INDEX itemId_readAt_unique_index
2021/09/13 13:36:33 pg_restore: skipping item 3561 TRIGGER table1 ts_insert_blocker
2021/09/13 13:36:33 pg_restore: skipping item 3708 TABLE DATA table2
2021/09/13 13:36:33 pg_restore: skipping item 3491 INDEX table2_readAt_idx
2021/09/13 13:36:33 pg_restore: skipping item 3492 INDEX table2_itemId_readAt_unique_index
@cheerfulstoic
cheerfulstoic / actor.ex
Last active July 15, 2021 19:46
Emoji Game - Telemetry Example
# lib/emoji_game/actor.ex
# Non-player character client
defmodule EmojiGame.Actor do
use GenServer
# ... code ...
@impl true
defmodule Tester do
def update!(map) do
try do
{:ok, Map.update!(map, :blah, fn v -> v end)}
rescue
e in KeyError -> {:error, :no_key}
end
end
@cheerfulstoic
cheerfulstoic / .circleci_config.yml
Created February 11, 2021 09:45
CircleCI / Docker configuration to build, test, and push an image to Docker Hub
# file path should be .circleci/config.yml
version: 2 # use CircleCI 2.0 instead of CircleCI Classic
jobs: # basic units of work in a run
build: # runs not using Workflows must have a `build` job as entry point
parallelism: 1 # run only one instance of this job
docker: # run the steps with Docker
- image: circleci/elixir:1.11.3 # ...with this image as the primary container; this is where all `steps` will run
auth:
username: $DOCKER_USER
password: $DOCKER_PASS # context / project UI env-var reference
@cheerfulstoic
cheerfulstoic / lib-my_app_web-graphql-middleware-relay_connection_lazy_evaluate.ex
Created November 16, 2020 09:40
Middleware for Elixir's `absinthe` to deal with efficient querying of `edges` and `totalCount`
defmodule MyAppWeb.Graphql.Middleware.RelayConnectionLazyEvaluate do
@moduledoc """
Absinthe requires all of the data for a connection to be loaded in the `resolve`
for the field. This means that regardless of if a client requests `edges` or
`totalCount`, the server needs to do one query for both every time.
This middleware evaluates the query that was done by the client to figure out
what fields were requested. It will only load the data which is required for
a typical connection based on what the client has requested
@cheerfulstoic
cheerfulstoic / output
Created October 15, 2019 12:02
string_concat_test.rb
Warming up --------------------------------------
interpolation 151.958k i/100ms
StringIO << 57.897k i/100ms
StringIO concat 103.750k i/100ms
Calculating -------------------------------------
interpolation 2.482M (± 9.9%) i/s - 9.877M in 4.027092s
StringIO << 45.806B (±33.8%) i/s - 119.834B
StringIO concat 100.679B (±15.4%) i/s - 272.862B
Comparison:
def die_roll
rand(6) + 1
end
def attack(attacking_count, defending_count)
attacking_dice = [attacking_count, 3].min
defending_dice = [defending_count, 2].min
attacking_rolls = attacking_dice.times.map { die_roll }.sort.reverse
defending_rolls = defending_dice.times.map { die_roll }.sort.reverse
@cheerfulstoic
cheerfulstoic / gist:7d64cc4a3d87162c09562ffe283d813c
Created January 31, 2018 14:03
Queries and R code for Paradise Papers presentation
# R setup
library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
# Queries:
# What types of objects are we dealing with?
MATCH (n)
@cheerfulstoic
cheerfulstoic / .tmux.conf
Created September 22, 2017 16:57
My ~/.tmux.conf
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind-key -n S-Up resize-pane -U 5
bind-key -n S-Down resize-pane -D 5
bind-key -n S-Left resize-pane -L 5
bind-key -n S-Right resize-pane -R 5