Skip to content

Instantly share code, notes, and snippets.

@dbernheisel
dbernheisel / req_wrapper.ex
Last active November 18, 2023 13:43
Req adapter that raises while in MIX_ENV=test
defmodule MyApp.Req do
@moduledoc """
Wrapper around Req to apply defaults. See [Req](https://hexdocs.pm/req)
This will also protect from external requests running while MIX_ENV=test.
To set the adapter in controller or integration tests, you may configure
your mock with `Process.put(:req_adapter, my_mock)`.
You must specify `external_service` and `request_name` telemetry tags
@dbernheisel
dbernheisel / earmark-for-with-mermaid.ex
Last active August 22, 2023 17:28
How to handle switching themes in Mermaid
# keep the src around for mermaid for re-renders.
def maybe_rewrite_mermaid(
{"pre", _attrs, [{"code", [{"class", "mermaid"}], inner, meta}], pre_meta}
) do
{"div",
[
{"phx-update", "ignore"}
],
[
@dbernheisel
dbernheisel / footer.html.heex
Last active November 2, 2022 02:16
Theme Chooser in Phoenix and JavaScript
@dbernheisel
dbernheisel / fzf-mix.vim
Created February 23, 2022 17:57
Use fzf.vim to fuzzy-find available mix commands
function! g:MixRun(selection) abort
if !empty(a:selection)
execute "!mix ".a:selection
endif
endfunction
function! g:MixFzf(selection = '') abort
if empty(a:selection)
call fzf#run(fzf#wrap({
\ 'source': 'mix help --names',
@dbernheisel
dbernheisel / rename_phx.sh
Last active February 14, 2021 06:58
Rename a Phoenix project
export FROM="petal"
export FROM_MOD="Petal"
export TO="elixir_stream"
export TO_MOD="ElixirStream"
cp -R "$FROM" "$TO"
cd "$TO"
git ls-files -z | xargs -0 perl -p -i -e "s/$FROM/$TO/g; s/$FROM_MOD/$TO_MOD/g;"
mv "lib/${FROM}" "lib/$TO"
mv "lib/${FROM}.ex" "lib/${TO}.ex"
@dbernheisel
dbernheisel / default.pa
Created October 20, 2020 14:48
Pulseaudio Focusrite 6i6 config
# Put this at the bottom
## Remap Scarlett input 1 separately
load-module module-remap-source source_name=scarlett-xlr-1 source_properties="device.description='Focusrite Scarlett 6i6 XLR 1'" master=alsa_input.usb-Focusrite_Scarlett_6i6_USB_00074100-00.multichannel-input remix=no channels=2 master_channel_map=front-left,front-left channel_map=left,right
### Remap Scarlett input 2 separately
load-module module-remap-source source_name=scarlett-xlr-2 source_properties="device.description='Focusrite Scarlett 6i6 XLR 2'" master=alsa_input.usb-Focusrite_Scarlett_6i6_USB_00074100-00.multichannel-input remix=no channels=2 master_channel_map=front-right,front-right channel_map=left,right
### Remap Scarlett inputs 3&4 separately
load-module module-remap-source source_name=scarlett-inputs-3-4 source_properties="device.description='Focusrite Scarlett 6i6 3/4'" master=alsa_input.usb-Focusrite_Scarlett_6i6_USB_00074100-00.multichannel-input remix=no channels=2 master_channel_map=front-center,lfe channel_map=left,right
@dbernheisel
dbernheisel / employer-test.md
Created February 24, 2020 14:37
Employer Test

employer-test

A list of questions to ask potential employers.

Work Style

Ownership

  • Does one single person own a unit of work (task, project, product, etc)?
  • Can that single person's manager override the decisions made by that person on that unit of work?
@dbernheisel
dbernheisel / mass-expire-redis.sh
Last active October 8, 2019 17:34
Expire redis keys en-masse
#!/bin/bash
# Mass expire Redis keys using the SCAN command so it doesn't block or overwhelm
# memory
# Usage example: ./mass-expire-redis.sh "127.0.0.1" "6379" "mykey:*" "300"
# Logs to ./filename.ext.log
if [ $# -ne 4 ]; then
echo "Usage: $0 <host> <port> <pattern> <expiration>"
exit 1
@dbernheisel
dbernheisel / install-old-ruby.sh
Last active September 20, 2020 14:58
Installing old Ruby with old OpenSSL requires a couple flags. Here they are.
# Install prerequisites. I'm using arch, but you can do similar things with brew but paths change.
yay gcc6
pacman -S openssl-1.0
OPENSSL_DIR="/usr/lib/openssl-1.0"
# If you're on mac and installed with brew, you can do this:
# OPENSSL_DIR=$(brew --prefix openssl-1.0)
# A patch to let older Ruby to work with newer OpenSSL
SSL_PATCH="https://gist.github.com/mislav/055441129184a1512bb5/raw"
@dbernheisel
dbernheisel / myapp.conf
Created September 20, 2019 14:46
nginx phoenix app
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream myapp {
server localhost:4000;
}
server {