Skip to content

Instantly share code, notes, and snippets.

@exAspArk
exAspArk / friday_deploy_cap2.rb
Last active November 14, 2020 23:13
Friday deploy script for Capistrano
# Capistrano 2
before "deploy", "friday:good_luck"
namespace :friday do
friday_jumper = %{
┓┏┓┏┓┃
┛┗┛┗┛┃⟍ ○⟋
┓┏┓┏┓┃ ∕ Friday
┛┗┛┗┛┃ノ)
@exAspArk
exAspArk / state_machine.rb
Last active February 22, 2016 22:28
HACK StateMachine gem to make it work with ActiveRecord 4.2
# HACK to enable using protected methods from Rails 4.2 and initial states as default attributes for ActiveRecord
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
module ActiveRecord
public :around_save
@exAspArk
exAspArk / hacks.rb
Last active August 29, 2015 14:08 — forked from conf/monkey_patches.rb
Get rid of TZInfo::AmbiguousTime exception
# config/initializers/hacks.rb
Dir[Rails.root.join("lib/hacks/**/*.rb")].each { |file| require file }
@exAspArk
exAspArk / gist:d81e5d7b6ad1bdd3bcf6
Created October 31, 2014 16:50
Immutable deep hash merge (ruby)
def deep_merge(hash1, hash2)
result = hash1.dup
hash2.keys.each do |key|
if hash2[key].is_a?(Hash) && hash1[key].is_a?(Hash)
result[key] = deep_merge(hash1[key], hash2[key])
else
result[key] = hash2[key]
end
end
require "timeout"
module WaitSteps
extend RSpec::Matchers::DSL
matcher :become_true do
match do |block|
begin
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = block.call

Commands examples

If the namespace is not used then the commands will perform on top of the default database.

  bundle exec rake db:create
  bundle exec rake db:migrate 

By using the namespace we are going to use all the configuration for our alternate DB.

@exAspArk
exAspArk / gist:4aa5fa70acf5d492eda7
Last active August 29, 2015 14:02
Nested symbolize keys (ruby)
def nested_symbolize_keys(thing)
case thing
when Array
thing.map { |value| nested_symbolize_keys(value) }
when Hash
Hash[thing.map { |key, value| [key.to_sym, nested_symbolize_keys(value)] }]
else
thing
end
end
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do

Docker Cheat Sheet

Why

Why Should I Care (For Developers)

"Docker interests me because it allows simple environment isolation and repeatability. I can create a run-time environment once, package it up, then run it again on any other machine. Furthermore, everything that runs in that environment is isolated from the underlying host (much like a virtual machine). And best of all, everything is fast and simple."

TL;DR, I just want a dev environment