How to encrypt/decrypt a file with GPG

Tagged password, decrypt, encrypt, gpg  Languages bash

First, install GPG:

brew install gpg

To encrypt a file with GPG, run:

gpg -c secrets.txt

To decrypt the encrypted and password-protected GPG file, run:

gpg secrets.txt.gpg

failed to push some refs to

Tagged push, git, rebase, pull  Languages bash

git push fails:

❯ git push
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to ''
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Use pull and rebase to rewind and replay your commit, otherwise you will end up with a “merge commit” in your git history:

❯ git pull --rebase
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), done.
   aaa..bbb  master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: <Your commit message>.

How to Undo Almost Anything With Git:

Git Pretty - Git Flowchart:

Oh Shit, Git!?!:

Running Rubocop on commit, changes, or branch

Tagged rubocop, branch, git  Languages 
  • To RuboCop the current commit
git diff-tree --no-commit-id --name-only -r HEAD --diff-filter AMT | xargs bundle exec rubocop
  • To RuboCop the working tree changes
git diff --name-only --diff-filter AMT | xargs bundle exec rubocop
  • To RuboCop all of the changes from the branch
git diff --name-only master --diff-filter AMT | xargs bundle exec rubocop


Also see:

Procfile dependencies

Tagged sleep, dependencies, foreman, overmind, procfile  Languages bash

You can use the sleep command as a way of specifying dependencies in a Procfile even if dependencies are not explicitly supported.

For example:

redis:        redis-server
sidekiq:      sleep 5; bundle exec sidekiq
rails:        sleep 5; bundle exec rails
proxy:        sleep 10; haproxy -c haproxy.cfg

SSH jump host

Tagged ssh, host, jump  Languages bash
# Connect to server-b by going through server-a (you => server-a => server-b):
$ ssh -t <user>@<server-a> ssh <server-b>

How to solve "CreateContainerConfigError" in Kubernetes

Tagged kubectl, k8s, createcontainerconfigerror  Languages bash

To solve CreateContainerConfigError you can try this command:

$ kubectl describe pod xxx-86cbd7555b-2zrs2
  Warning  Failed     75s (x8 over 2m50s)  kubelet, k8s-node1  Error: couldn't find key XXX in ConfigMap default/xxx

Bash aliases / functions for kubectl

Tagged kubectl, aliases, k8s  Languages bash

Put the following functions in, for example, ~/.bash_aliases:

# Open a bash shell in the pod
function kshell() { kubectl exec -it "$1" -- /bin/bash ;}
# List pods
function kpods() { kubectl get po -n default -o wide ;}
function klogs() { kubectl logs -f "$1" ;}
function ktail() { kubectl logs --tail=100 -f "$1" ;}
# Restarts a pod
function krestart() { kubectl rollout restart "deployment/$1" ;}
# Stops a pod by scaling it to zero
function kstop() { kubectl scale --replicas=0 "deployment/$1" ;}
function kdesc() { kubectl describe pod $1 ;}
function ksecret() { kubectl get secret $1 -o jsonpath="{.data.$2}" | base64 --decode ;}
function ksecrets() { kubectl get secret/$1 -o yaml ;}

Your RSI symptoms and cognitive dissonance will disappear in about 6 months.

Debugging Webpacker (Rails)

Tagged rails, webpacker  Languages bash

If Webpacker fails to compile your Javascripts without including any output:

[Webpacker] Compiling…
[Webpacker] Compilation failed:

Try running webpacker from the command line:

$ ./bin/webpack --progress --profile

How to find all tables referring to another table in Postgres

Tagged column, postgresql  Languages sql

This example lists all tables that contain a column named ‘organization_id’:

SELECT c.relname AS table,
       a.attname AS column,
       n.nspname AS schema
FROM   pg_class AS c
       INNER JOIN pg_attribute AS a
               ON a.attrelid = c.oid
       JOIN pg_namespace n
         ON n.oid = c.relnamespace
WHERE  a.attname = 'organization_id'
       AND c.relkind = 'r'
       AND c.relname NOT LIKE 'pg_%'
ORDER  BY c.relname,