Skip to content

Instantly share code, notes, and snippets.

View joshnesbitt's full-sized avatar

Josh Nesbitt joshnesbitt

View GitHub Profile

It's a little known fact that you can easily substitute the default Rails HTML error pages with something more pleasant. You may have noticed the 404.html, 422.html and 500.html files that are generated with every new Rails project and wondered if there's a clean way to style them like the rest of your application. There is, and it's surprisingly simple.

Basic Implementation

The default status code templates are served by a Rack exception application. You can override this to be any Rack compatible app, including your applications router:

# config/application.rb
config.exceptions_app = self.routes
@joshnesbitt
joshnesbitt / readme.md
Last active May 16, 2016 10:28
A simple script to get you on the Mondo beta.

Mondo Referral Bump

Thanks to @cbarratt for writing this. Tested on Ruby 2.2.2.

Installation

Install the dependencies:

gem install capybara ffaker poltergeist selenium-webdriver chromedriver-helper
@joshnesbitt
joshnesbitt / pub_sub.rb
Last active September 16, 2015 15:42
A very simple pub sub implementation.
class Hub
class << self
NAMESPACE_SEPARATOR = ':'
def publish(event, payload = {})
handlers[event].each do |handler|
handler.call(payload)
end
end
@joshnesbitt
joshnesbitt / template.rb
Created August 20, 2015 14:51
Example of a simple templating language written in Ruby.
class VariableLang
def initialize(path)
@path = path
@content = File.read(path)
end
def render(locals = {})
locals.inject(@content.dup) do |buffer, vars|
key = vars.first
price_list = "orange = 10p apple = 20p bread = £1.10 tomato = 25p cereal = £2.34"
list = <<-LIST
list
orange
apple
apple
orange
tomato
cereal
bread
class MyClass
def one_method
puts "Hey!"
end
end
class MyClass
@joshnesbitt
joshnesbitt / metaclass.rb
Last active August 29, 2015 14:26
How well do you know Ruby? Can you explain what's going on here? What is MyClass.metaclass returning?
class MyClass
def self.metaclass
class << self; self; end
end
end
puts MyClass.metaclass.inspect
class Company
TooManyManagingDirectorsError = Class.new(Exception)
class Department
attr_reader :company,
:name,
:employees
def initialize(company, name, &block)
@company = company
module BannedWordFilter
class Filter
class << self
BANNED_WORDS = %w(
fuck
shit
banned
)
function code_highlight(){
style=${1:-zmrok}
pbpaste | highlight --syntax=rb --style=$style -O rtf | pbcopy
}