Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

# 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
)
@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

@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 / 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-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 / 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 / addr2idtt.rb
Last active July 31, 2017 14:29
quick script for wedding list CSV to IDTT for layout
require 'csv'
require 'erb'
class Address
def initialize(row)
@row = row
end
def name
text(@row[0])
@dcorrigan
dcorrigan / goaccess-multi.sh
Created May 4, 2017 14:38
goaccess parse multiple logs
zcat -f logs/access.log* | goaccess --log-format=COMBINED --ignore-crawlers -a -o report.html
@dcorrigan
dcorrigan / webpacker-ujs.md
Created April 19, 2017 16:45
Rails 5.1 Webpacker with react_ujs from react-rails

Some quick notes about using Rails 5.1 webpacker gem for React integration and react_ujs to premount components.

For reference, react_ujs is the JS library from react-rails that renders React components with props. It expects a parent with data-react-class and data-react-props set. I don't remember my initial setup, but probably:

bundle exec rails new . --webpack=react --force
yarn add react_ujs
@dcorrigan
dcorrigan / cmd.sh
Created January 31, 2017 15:07
run command with env vars from file
export $(cat file.env | xargs) && [command]