Skip to content

Instantly share code, notes, and snippets.

View IanVaughan's full-sized avatar
👯‍♀️
OMG

Ian Vaughan IanVaughan

👯‍♀️
OMG
View GitHub Profile
@IanVaughan
IanVaughan / db rows
Created August 19, 2020 15:54
get db row counts
tables = [ "users" ]
tables.each do |table|
count = ActiveRecord::Base.connection.execute("SELECT count(*) from #{table};")
puts "#{table}, #{count.entries.first["count"]}"
end
@IanVaughan
IanVaughan / git-push-all
Created August 6, 2020 14:53
Push each commit on the branch on its own so CI builds each one by one
branch=$(git branch --show-current)
for sha1 in $(git rev-list --reverse ...master) ; do
git push origin $sha1:$branch --force
done
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<http://www.foo.com|This message *is* a link>"
}
}
]
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'
# 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
FROM=$1
TO=$2
mv $TO ${TO}-1
@IanVaughan
IanVaughan / cred-diff
Created April 8, 2020 09:53
See diffs between rails credentials
#!/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
    User.create
    Mailer.send
  end
@IanVaughan
IanVaughan / gist:c7f5bf6cea3be8615c3056fb06aa2a4d
Created March 18, 2020 14:13
rake db load fails using flipper
-----> 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
IanVaughan / schema.rb.diff
Created March 18, 2020 14:12
Flipper schema commit
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