Skip to content

Instantly share code, notes, and snippets.

@dcorrigan
dcorrigan / docker.md
Last active May 7, 2019
running postgres in docker
View docker.md

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 Jan 16, 2018
Console/REPL Test Runner
View console-test-runner.md

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 Dec 26, 2017
get host IP from inside docker container
View host-ip.sh
/sbin/ip route|awk '/default/ { print $3 }'
View console-hot-reloader-basic.md

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 Nov 16, 2017
run rails 2.3 tests in the console
View console-tests.md

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 Jul 31, 2017
quick script for wedding list CSV to IDTT for layout
View addr2idtt.rb
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
goaccess parse multiple logs
View goaccess-multi.sh
zcat -f logs/access.log* | goaccess --log-format=COMBINED --ignore-crawlers -a -o report.html
@dcorrigan
dcorrigan / webpacker-ujs.md
Created Apr 19, 2017
Rails 5.1 Webpacker with react_ujs from react-rails
View webpacker-ujs.md

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 Jan 31, 2017
run command with env vars from file
View cmd.sh
export $(cat file.env | xargs) && [command]
View hub_workers.rb
module Thoth
##
# Thoth::HubWorkers is the class responsible for creating
# and caching a Sidekiq job for a given WFDW
# project conversion. It's arguments are passed to it via
# a REST API.
class HubWorkers
CONVERSIONS = Prepper::CONVERSION_PATHS.keys
CHECKS = Prepper::CHECK_COMMANDS