Skip to content

Instantly share code, notes, and snippets.

@alexch
alexch / quiz.rb
Created May 15, 2009 22:19 — forked from ryanb/quiz.rb
# 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.)
# 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
@alexch
alexch / bench.rb
Created May 20, 2009 23:29 — forked from nex3/bench.rb
#!/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
# 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]
# 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
class Temperature
def ftoc(f)
(f-32) * (5.0/9.0)
end
def ctof(c)
c * (9.0/5.0) + 32
end
end
@alexch
alexch / index.html
Created August 26, 2011 01:02 — forked from nfiniteset/index.html
Pages that scale to fit window size
<!DOCTYPE html>
<html>
<head>
<title>Scaling preso</title>
<style>
html {
font-size: 7.68px
}
# encoding: utf-8
module Kernel
alias :λ :lambda
end
class Hash
alias :+ :merge
alias :<< :merge!
end