Rails ApplicationController test (minitest)

Tagged application_controller, minitest, rails  Languages ruby
require 'test_helper'

class ApplicationControllerTest < ActionController::TestCase
  class DummyController < ApplicationController
    layout nil
    def index
      render plain: 'OK'
    end
  end

  tests DummyController

  Rails.application.routes.draw do
    controller 'application_controller_test/dummy' do
      get :index
    end
  end

  test "requires session cookie" do
    get :index
    assert_equal 'http://test.host/login', response.location
  end
end

Tested with Rails 6.

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

From https://about.gitlab.com/handbook/tools-and-tips/rubocop/

Also see:

Procfile dependencies

Tagged procfile, dependencies, sleep, foreman, overmind  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 host, ssh, 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, createcontainerconfigerror, k8s  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:

function kshell() { kubectl exec -it "$1" -- /bin/bash ;}
function kpods() { kubectl get po -n default -o wide ;}
function klogs() { kubectl logs -f "$1" ;}
function ktail() { kubectl logs --tail=100 -f "$1" ;}
function krestart() { kubectl rollout restart "deploy/$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 and symptoms of cognitive dissonance will disappear in about 6 months.

Debugging Webpacker (Rails)

Tagged webpacker, rails  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,
          a.attname  

The Scientific Method

Tagged growth, hypothesis, marketing, method, research, scientific, testing  Languages 

“The Scientific Method” from https://www.reforge.com/blog/run-growth-team-like-a-scientist

Inputs

  1. Question: What do I want to understand?
  2. Hypothesis: What is my proposed explanation to the question?
  3. Experiment: Design an experiment to test the hypothesis.

Outputs

  1. Observation: Observe the experiment and record results.
  2. Analysis: Interpret the results.

Notes

the qualitative inputs - question, hypothesis, and experiment design - are the most important steps of the process. If you get these steps right, you increase your chances of running successful experiments that produce valid results and actionable insights.

So, what separates the good growth teams (and research labs) from the great ones?

It’s the quality of the questions they ask, the hypotheses they come up with, and how they construct their experiments.

A one-day or one-week in vitro test using a landing page builder to mockup a subscription pricing page, driving traffic to it via ads, and measuring conversion rates against current pricing may have quickly revealed that a subscription pricing model wasn’t appealing to their customer base.

the point is to use an in vitro test to get validation that an in vivo test is worth the additional resources. Tools like Unbounce, Optimizely, and paid advertising make these kinds of in vitro tests easy and fast.

One of my favorite mentors, Anantha Katragadda, told me when I was starting out in growth that if I couldn’t think of a way to fake a product experience in order to get validating data, I simply wasn’t trying hard enough.

To publish a paper, every result must disprove the null hypothesis. This means that you prove, with statistical significance, that the result you are seeing is not due to random chance or biased observation