So I thought I was being clever, writing my Rails controller actions like this:
def create
set_post_from_post_id
set_comment_as_new
respond_to do |format|
comment.save
require 'benchmark' | |
class MyClassWithStuff | |
DEFAULT_VALS = { one: '1' } | |
def memoized_fetch | |
@value ||= DEFAULT_VALS[:one] | |
end |
# Bad: | |
class OrdersController | |
exposes :orders | |
def index | |
@orders = Order.complete | |
end | |
def pending |
class OrdersController | |
def index | |
end | |
def pending | |
end | |
private | |
class Array | |
# Inserts an object to the Array if condition is true | |
# | |
# object - The object to insert. | |
# condition - The condition to evaluate. | |
# | |
# Example: | |
# | |
# = content_tag(:div, class: ["user-username"].insert_if("active", @user.active)) do |
[diff] | |
tool = diff | |
algorythm = minimal | |
[color] | |
branch = auto | |
diff = auto | |
status = auto | |
interactive = auto | |
ui = true | |
pager = true |
require 'time' | |
require 'date' | |
class Invitee | |
end | |
class Event | |
attr_accessor :name | |
attr_accessor :date | |
attr_accessor :starts_at |
def should_nest_multiple_conditionals? | |
x = rand(10).to_i | |
if Time.now.strftime("%A") != "Friday" | |
if current_client.is_large_faceless_conglomerate? | |
return true | |
elsif Time.now.strftime("%A") == "Friday" | |
return true | |
end | |
elsif LocalWeather.new("Edinburgh").sunny? |
require 'benchmark' | |
TIMES = 1000000 | |
STRING = "this is a long and bad-ass string" | |
Benchmark.bmbm do |test| | |
test.report("Index") do | |
TIMES.times { STRING.index("this is") } |
/* ================================================================== */ | |
/* = Reset and some HTML 5 styles in case the browser aint so sharp = */ | |
/* ================================================================== */ | |
html,body,div,span,object,iframe, | |
h1,h2,h3,h4,h5,h6,p,blockquote,pre, | |
abbr,address,cite,code, | |
del,dfn,em,img,ins,kbd,q,samp, | |
small,strong,sub,sup,var, | |
a,b,i, | |
dl,dt,dd,ol,ul,li, |