Skip to content

Instantly share code, notes, and snippets.

<!-- It is probably easier to read if you initialize item_images to be an empty hash -->
<% @item.item_images ||= Hash.new %>
<% @item.item_images.each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
<% end %>
<!-- Or return a default value for when it is nil -->
<% (@item.item_images || Hash.new).each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
require 'isaac'
configure do |c|
c.nick = "ButtBot"
c.server = "irc.freenode.net"
# c.port = 6667
end
on :connect do
join "#wsu-acm"
class PrimeFactor
attr_accessor :all_factors
def largest_divisor_less_than(number)
divisor = 2
while divisor <= Math.sqrt(number)
return number / divisor if number % divisor == 0
divisor = divisor + 1
end
return 1
@JoshCheek
JoshCheek / review.md
Last active August 29, 2015 14:16 — forked from anonymous/review.md
Review of the second half of Philip Roberts' talk "What the heck is the event loop, anyway?"
# ===== Environment (MRI 2.1.1) =====
RUBY_VERSION # => "2.1.1"
RUBY_PLATFORM # => "x86_64-darwin13.0"
RbConfig.ruby # => "/Users/josh/.rubies/ruby-2.1.1/bin/ruby"
`#{RbConfig.ruby} -v` # => "ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]\n"
# ===== The Hypothesis =====
# A recursive method can call itself about 5000 times before it overflows.
# ===== Test #1 =====

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

Looked at the winning Dispatcher. Yours is better, b/c you can take it all by itself. Here are some examples of totally reasonable requirements that would feasibly be required of this application, in the real world. The winning one can't handle them without a refactoring like what we did:

Speed up the algorithm

require 'rspec/autorun'
gem 'minitest', '~> 5.6' # might work w/ older vers, I didn't check
require 'minitest'
class WhateverTest < Minitest::Test
def setup
@setup_value = true
end
def test_it_passes
This is a comment.
# The goal of this problem is to extract headers from a block of text,
# and arrange them hierarchically.
#
# See the specs for more detail on the output
require 'net/http'
require 'nokogiri'
def header_hierarchy(html)
# https://www.w3.org/MarkUp/html3/headings.html