Skip to content

Instantly share code, notes, and snippets.


Ian Vaughan IanVaughan

View GitHub Profile
IanVaughan / db rows
Created Aug 19, 2020
get db row counts
View db rows
tables = [ "users" ]
tables.each do |table|
count = ActiveRecord::Base.connection.execute("SELECT count(*) from #{table};")
puts "#{table}, #{count.entries.first["count"]}"
IanVaughan / git-push-all
Created Aug 6, 2020
Push each commit on the branch on its own so CI builds each one by one
View git-push-all
branch=$(git branch --show-current)
for sha1 in $(git rev-list --reverse ...master) ; do
git push origin $sha1:$branch --force
View gist:8e1a42b06237bfdeffe865c0701aeb46
"blocks": [
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<|This message *is* a link>"
View gist:e08c552474b46b829cf1fc72702458b8
gcloud config set project ${PROJECT_ID}
gcloud sql instances create ex-kills-db-us-west1 --region=us-west1 --database-version=POSTGRES_9_6 --tier=db-f1-micro
gcloud sql instances describe ex-kills-db-us-west1 #=> connectionName: ex-kills:us-west1:ex-kills-db-us-west1
gcloud sql users set-password postgres --instance=ex-kills-db-us-west1 --prompt-for-password #=> 123456
gcloud container clusters create ex-kills-cluster-us-west1 --num-nodes=1 --zone=us-west1 --scopes=gke-default,sql-admin
gcloud container clusters get-credentials --zone=us-west1 ex-kills-cluster-us-west1
gcloud config set container/cluster ex-kills-cluster-us-west1
mkdir -p /tmp/cloudsql
May 13 08:00:33.022	/app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/access_token.rb:114:in `get'
May 13 08:00:33.022	/app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/access_token.rb:107:in `request'
May 13 08:00:33.022	pid=4 tid=baglec WARN: /app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/client.rb:119:in `request'
May 13 08:00:33.021	pid=4 tid=baglec WARN: OAuth2::Error: internal_server_error: Sorry, we are experiencing technical difficulties. Please try again later.
May 12 20:00:59.103	/app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/access_token.rb:114:in `get'
May 12 20:00:59.103	/app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/access_token.rb:107:in `request'
May 12 20:00:59.103	pid=4 tid=40uw WARN: /app/vendor/bundle/ruby/2.7.0/gems/oauth2-1.4.2/lib/oauth2/client.rb:119:in `request'
View git-rename
# Put somewhere in your $PATH, and chmod +x git-rename
# On a branch with files already moved and changed locally but not in git.
# Usage:
# git rename existing-checked-in-filename new-and-changed-filename
#!/usr/bin/env bash
mv $TO ${TO}-1
IanVaughan / cred-diff
Created Apr 8, 2020
See diffs between rails credentials
View cred-diff
#!/usr/bin/env bash
# usage: On your branch or commit 'cred-diff production'
git checkout production --quiet
rails credentials:show --environment $1 > /tmp/prod
git checkout - --quiet
rails credentials:show --environment $1 > /tmp/yours
diff /tmp/prod /tmp/yours
rm /tmp/prod /tmp/yours

The part which wasn’t clear enough was on the topic how the read models extraction can help in designing aggregates. Here’s my written attempt to explain this strategy:

Introduce a Service objects layer (aka application layer)

class RegisterUser
  def call
View gist:c7f5bf6cea3be8615c3056fb06aa2a4d
-----> Fetching heroku/ci-postgresql buildpack...
buildpack downloaded
-----> Fetching heroku/ci-redis buildpack...
buildpack downloaded
-----> Fetching heroku/ruby buildpack...
buildpack downloaded
-----> Fetching heroku/nodejs buildpack...
buildpack downloaded
-----> Postgresql app detected
IanVaughan / schema.rb.diff
Created Mar 18, 2020
Flipper schema commit
View schema.rb.diff
diff --git a/db/schema.rb b/db/schema.rb
index 79ce7b88..d9914a59 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_03_16_124239) do
+ActiveRecord::Schema.define(version: 2020_03_17_181241) do