Skip to content

Instantly share code, notes, and snippets.

View KelseyDH's full-sized avatar

Kelsey Hannan KelseyDH

  • Bite Interactive
  • Vancouver
View GitHub Profile
@KelseyDH
KelseyDH / ruby_rails_windows.md
Last active May 16, 2024 07:48
Ruby on Rails Microsoft Windows Troubleshooting Tips

Ruby on Rails Windows Troubleshooting Tips & Survival Guide

Intro/Overview

The Ruby on Rails Windows Troubleshooting tips & Survival Guide is a random catalogue of issues I faced working with Ruby on Rails on Windows (Windows 7 specifically). This guide is not exhaustive, but covers many of the challenges that causes Windows Ruby developers to jump ship to Linux or Mac. If you're reading this guide then you're probably new to Ruby/Rails, so also included is more general beginner advice to help you get going.

Personal Side Note

Before you follow this guide, I strongly recommend you consider using Linux or Mac OS X for Ruby Development instead. Looking to prove a point as a challenge, I ignored this strongly given advice while learning Ruby/Rails. While I eventually did succeed in getting Ruby on Rails to work in Windows, it was not easy, and I easily lost 40+ hours on StackOverFlow to Windows/Ruby configuration issues--time I could have devoted to learning more about th

def defer(&block)
def block.each ; yield call ; end
block
end
app =
lambda do |env|
status = 200
headers = { 'Last-Modified' => exec_sql('SELECT MAX(updated_at) FROM foos').httpdate }
task :deploy => ['deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
task :migrations => [:push, :off, :migrate, :restart, :on, :tag]
task :rollback => [:off, :push_previous, :restart, :on]
task :push do
puts 'Deploying site to Heroku ...'
puts `git push heroku`
end
@KelseyDH
KelseyDH / -
Created November 9, 2015 22:15 — forked from anonymous/-
gicof() {
git co $( (git branch -r | sed 's/origin\///'; git branch) | sort | uniq | fzf --query="$1" --select-1 --exit-0 )
}
gimf() {
git merge $( (git branch -r | sed 's/origin\///'; git branch) | sort | uniq | fzf --query="$1" --select-1 --exit-0 )
}
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@KelseyDH
KelseyDH / see_all_instance_variables.rb
Created June 24, 2017 06:45
Examine all ruby instance variables within current context
class A
attr_accessor :foo, :bar
def context
self.instance_variables.map do |attribute|
{ attribute => self.instance_variable_get(attribute) }
end
end
end
@KelseyDH
KelseyDH / thread_safe.rb
Created July 18, 2017 22:30 — forked from mikbe/thread_safe.rb
Stops collisions but it's ugly
require 'thread'
module ThreadSafe
def self.included(base)
base.extend(ThreadSafeClassMethods)
base.threadsafe_class_mutex = Mutex.new
end
module ThreadSafeClassMethods
@KelseyDH
KelseyDH / service_object.rb
Created January 27, 2018 08:26
How to write a Rails Service Object with logging
# # A Plain Old Ruby Object (poro) with Rails logger support:
class ServiceObject
def initialize(foo)
@logger = Logger.new(STDOUT)
@foo = foo
end
def call
do_something
end
@KelseyDH
KelseyDH / null_object_example.rb
Created August 23, 2019 09:59
Using Null Object pattern in Ruby on Rails apps
# E.g. for a banking app where users might not have bank accounts yet.
# Not having accounts could mean lots of code like this:
if user.savings_account.present?
user.savings_account.available_balance_cents
end
# But with the NullObject pattern I can confidently call:
user.savings_account.available_balance_cents
# .present?
if user.savings_account.present?
user.savings_account.available_balance_cents
else
0
end
# .try
user.try(:savings_account).(:available_balance_cents) || 0