Skip to content

Instantly share code, notes, and snippets.

@dcorrigan
dcorrigan / console-tests.md
Last active November 16, 2017 16:25
run rails 2.3 tests in the console

fire up the console in the test env:

RAILS_ENV=test script/console

then require a Ruby test runner:

require 'test/unit/ui/console/testrunner'
@dcorrigan
dcorrigan / console-hot-reloader-basic.md
Created December 15, 2017 15:20
console hot reloader basic

reloader:

  server = TCPServer.new 2222
  puts 'loading hot reloader...'
  Thread.new do
    puts 'firing up a thread....'
    loop do
      Thread.start(server.accept) do |client|
 file = client.gets.chomp.gsub('/Users/dan/promptworks/colonial-surety/', '')
@dcorrigan
dcorrigan / host-ip.sh
Created December 26, 2017 14:40
get host IP from inside docker container
/sbin/ip route|awk '/default/ { print $3 }'
@dcorrigan
dcorrigan / console-test-runner.md
Last active January 16, 2018 18:48
Console/REPL Test Runner

A Quick REPL Test Runner

This is a small helper class demonstrating how to run unit tests in IRB or a similar Ruby REPL:

# console_runner.rb
require 'test/unit/ui/console/testrunner'

class ConsoleRunner
  def initialize(file_list)
@dcorrigan
dcorrigan / docker.md
Last active May 7, 2019 19:27
running postgres in docker

Docker postgres command:

docker run --rm --name my-postgres -p 5432:5432 -v [full dir path]/postgres.bk:/var/lib/postgresql/data postgres

--rm: remove an existing instances

-p bind the port to the host machine

# in this version i'm explicitly specifying the serializer to test upgrading from :marshal to :hybrid or :json
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(
cookie,
serializer = Marshal,
secret_key_base = Rails.application.secret_key_base
)