This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# block: 0.052654 | |
# yield: 0.015362 | |
def with_block(&block) | |
block.call | |
end | |
def with_yield | |
yield | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Erector Page base class. | |
# | |
# Allows for accumulation of script and style tags (see example below) with either | |
# external or inline content. External references are 'uniq'd, so it's a good idea to declare | |
# a js script in all widgets that use it, so you don't accidentally lose the script if you remove | |
# the one widget that happened to declare it. | |
# | |
# At minimum, child classes must override #body_content. You can also get a "quick and dirty" | |
# page by passing a block to Page.new but that doesn't really buy you much. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby implementation of Smalltalk's "if" construction. See also | |
# http://pozorvlak.livejournal.com/94558.html | |
# | |
# Note that since I can't cleanly pass in more than one anonymous block to a | |
# method in Ruby, I have to implement it as two methods rather than | |
# Smalltalk's cleaner "ifTrue:ifElse:" single method. This means that in order | |
# to get the syntax for chaining, I lose Ruby's ability to return a value from | |
# "if", which is pretty cool in itself. | |
# | |
class TrueClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# COMMUNITY CHALLENGE | |
# | |
# How would you test this Quiz#problem method? Only two rules: | |
# | |
# 1. The tests should fail if any part of the application breaks. | |
# For example: If "gets" is moved before "puts" then the tests should | |
# fail since that breaks the application. | |
# | |
# 2. You cannot change the Quiz class. But you can use whatever framework | |
# and tools you want for the tests. (RSpec, Cucumber, etc.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# likewise require | |
# by Pat Nakajima | |
# because I've been drinking more than Jack Barnette | |
# and | |
# to annoy John Susser and Aaron Peterson | |
# | |
# use to require files relative to the current file: | |
# | |
# likewise do | |
# require "foo" # require current-dir/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Alex's changes: | |
# * erector and erector_mixin | |
# * each template now includes a loop and a variable (this affects HAML quite a lot) | |
# * automated comparison and benchmarking | |
# * make sure variable is truly being interpolated | |
# # of iterations = 10000 | |
# user system total real |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from: http://pivotallabs.com/users/alex/blog/articles/865-monkey-patch-du-jour | |
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractAdapter | |
def log_info(sql, name, ms) | |
if @logger && @logger.debug? | |
@logger.debug("#{sql}, #{name}, #{ms}") | |
c = caller.detect{|line| line !~ /(activerecord|active_support|__DELEGATION__|\/lib\/|\/vendor\/plugins|\/vendor\/gems)/i} | |
c.gsub!("#{File.expand_path(File.dirname(RAILS_ROOT))}/", '') if defined?(RAILS_ROOT) | |
name = '%s (%.1fms) %s' % [name || 'SQL', ms, c] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Failure: | |
test_logout(AppTest) [/Users/chaffee/dev/sessiontest/gist-131374/login_app_test.rb:33]: | |
<"logged out barack"> expected but was | |
<"logged out ">. | |
2) Failure: | |
test_main_page(AppTest) [/Users/chaffee/dev/sessiontest/gist-131374/login_app_test.rb:48]: | |
please log in: <form action='/login' method='get'><input name='username'><input type='submit'></form>. | |
<nil> is not true. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A group of actions and related helper methods dealing with login/logout. | |
# These are loaded from my main Sinatra app via "register Actions::Login". | |
# I put this file in a subdirectory called "actions". | |
module Actions | |
module Login | |
module Helpers | |
def logged_in? | |
if session[:user_id] | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Temperature | |
def ftoc(f) | |
(f-32) * (5.0/9.0) | |
end | |
def ctof(c) | |
c * (9.0/5.0) + 32 | |
end | |
end |
OlderNewer