Skip to content

Instantly share code, notes, and snippets.


Brian Underwood cheerfulstoic

View GitHub Profile
cheerfulstoic / log.log
Last active Sep 16, 2021
ts-dump / ts-restore logs
View log.log
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 / actor.ex
Last active Jul 15, 2021
Emoji Game - Telemetry Example
View actor.ex
# lib/emoji_game/actor.ex
# Non-player character client
defmodule EmojiGame.Actor do
use GenServer
# ... code ...
@impl true
View benchmark.exs
defmodule Tester do
def update!(map) do
try do
{:ok, Map.update!(map, :blah, fn v -> v end)}
e in KeyError -> {:error, :no_key}
cheerfulstoic / .circleci_config.yml
Created Feb 11, 2021
CircleCI / Docker configuration to build, test, and push an image to Docker Hub
View .circleci_config.yml
# 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
username: $DOCKER_USER
password: $DOCKER_PASS # context / project UI env-var reference
cheerfulstoic / lib-my_app_web-graphql-middleware-relay_connection_lazy_evaluate.ex
Created Nov 16, 2020
Middleware for Elixir's `absinthe` to deal with efficient querying of `edges` and `totalCount`
View lib-my_app_web-graphql-middleware-relay_connection_lazy_evaluate.ex
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 / output
Created Oct 15, 2019
View output
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
View risk_battle.rb
def die_roll
rand(6) + 1
def attack(attacking_count, defending_count)
attacking_dice = [attacking_count, 3].min
defending_dice = [defending_count, 2].min
attacking_rolls = { die_roll }.sort.reverse
defending_rolls = { die_roll }.sort.reverse
cheerfulstoic / gist:7d64cc4a3d87162c09562ffe283d813c
Created Jan 31, 2018
Queries and R code for Paradise Papers presentation
View gist:7d64cc4a3d87162c09562ffe283d813c
# R setup
graph = startGraph("http://localhost:7474/db/data/")
# Queries:
# What types of objects are we dealing with?
View .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
cheerfulstoic / neo4jrb.yml
Last active Sep 22, 2017
tmuxinator file for working on Neo4j.rb projects
View neo4jrb.yml
# ~/.tmuxinator/neo4jrb.yml
name: neo4jrb
root: ~/github/neo4jrb
# Optional tmux socket
# socket_name: foo
# Runs before everything. Use it to start daemons etc.