Skip to content

Instantly share code, notes, and snippets.

View drteeth's full-sized avatar

Benjamin Moss drteeth

View GitHub Profile

🥫 The Ketchup Technique

Controlled Bursts | TDD | TCR | 100% Coverage | Emergent Design | Extreme Ownership

Core Loop

Red → Green → TCR → Refactor → TCR → Done
TCR: test && commit || revert
- Pass → commit → continue
@slashdotdash
slashdotdash / unique_username.ex
Last active November 9, 2022 13:26
Unique username command dispatch middleware for Commanded
defmodule UniqueUsername do
@behaviour Commanded.Middleware
alias Commanded.Middleware.Pipeline
def before_dispatch(%Pipeline{command: %RegisterUser{} = command} = pipeline) do
%RegisterUser{username: username} = command
case Repo.insert(%Username{username: username}) do
{:ok, _} ->
@trarbr
trarbr / ble-debugging-guide.md
Last active June 30, 2022 03:33
Debugging Bluetooth with HCI packet logs

Are you using Blue Heron on your Nerves device? Are you having trouble figuring out why things aren't working? Fear not! The HCI packet log may be able to help you. And this gist will let you know how to read it with Wireshark.

The Blue Heron readme states:

This project includes a Logger backend to dump PKTLOG format. This is the same format that Android, IOS, btstack, hcidump, and bluez use.

By default, Blue Heron will write this PKGLOG to /tmp/hcidump.pklg on your Nerves device. You can transfer it to your computer with scp (scp nerves.local:/tmp/hcidump.pklg . should copy it to your local directory).

@jwilger
jwilger / 1 - PII Encryption with Elixir, Commanded, Vault.md
Last active December 1, 2024 06:52
Quick Code Sample on Encrypting PII with Commanded for GDPR/CCPA Compliance

This code is extracted from one of my private projects as an example of how to implement encryption of PII in event streams using two keys: a master key for each "data subject" that is stored in Vault and never transported to the systems that process the PII, and a key unique to each event that is stored (itself encrypted) with the event.

To be clear, the key that is stored with the data is encrypted by another key that is not stored with the data. The idea is that each "data subject" has an encryption key that is stored in Vault (external). When you encrypt data, the library will:

  1. create a new AES 256 encryption key
@ErikSaunier
ErikSaunier / cloud-sql-proxy.service
Created May 30, 2018 12:08
How to install Cloud SQL Proxy on Compute Engine instance and make it start on boot with Systemd
[Unit]
Description=Connecting MySQL Client from Compute Engine using the Cloud SQL Proxy
Documentation=https://cloud.google.com/sql/docs/mysql/connect-compute-engine
Requires=networking.service
After=networking.service
[Service]
WorkingDirectory=/usr/local/bin
ExecStart=/usr/local/bin/cloud_sql_proxy -dir=/var/run/cloud-sql-proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306
Restart=always
@slashdotdash
slashdotdash / README.md
Last active November 21, 2017 16:24
Using Commanded Ecto projections with Elixir's Registry for pub/sub read model notifications

Using Commanded Ecto projections

Example read model projections using Commanded Ecto projections where Elixir's Registry is used for pub/sub notifications of read model updates.

This alleviates the problem of async read model updates.

The command dispatcher can wait until the read model has been updated to the exact aggregate version (as returned by the dispatch command):

with {:ok, version} &lt;- Router.dispatch(register_user, include_aggregate_version: true) do
@donnfelker
donnfelker / circle.yml
Created June 2, 2016 16:05
Updated circle.yml file
#
# Build configuration for Circle CI
#
# See this thread for speeding up and caching directories: https://discuss.circleci.com/t/installing-android-build-tools-23-0-2/924
#
general:
artifacts:
- /home/ubuntu/AndroidCI/app/build/outputs/apk/
@mttkay
mttkay / Pager.java
Created November 4, 2015 15:46
A simple Rx based pager
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
@chsh
chsh / pg_pub_sub.rb
Last active June 6, 2025 20:51
PostgreSQL LISTEN/NOTIFY example for ruby
#
# A:
# pubsub = PgPubSub.new('channelname')
# pubsub.subscribe do |data|
# puts "data: #{data} is coming!"
# end
#
# B:
# pubsub = PgPubSub.new('channelname')
# pubsub.publish("hello world")