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 ApplicationController < ActionController::Base | |
rescue_from PermissionDenied { |e| http_status_code(:forbidden, e) } | |
rescue_from AccountExpired { |e| http_status_code(:payment_required, e) } | |
def http_status_code(status, exception) | |
respond_to do |format| | |
self.response.headers["X-Exception"] = @exception = exception | |
format.html { render :template => "shared/status_#{status.to_s}", :status => status } | |
format.any { head status } |
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 | |
# | |
# How to properly extend String and abstract in new functionality using the Proxy Pattern | |
# without overriding native Ruby primitives. | |
# | |
# [og](http://www.fngtps.com/2006/09/the-proxy-pattern-in-ruby) | |
# | |
require 'rubygems' | |
require 'bacon' |
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
begin | |
require 'capistrano_colors' | |
rescue LoadError | |
puts "Cannot load Capistrano Colors gem" | |
end | |
set :rails_env, ENV['rails_env'] || ENV['RAILS_ENV'] || 'beta' | |
set :extra_deploys, 'config/deployments/' | |
set :application, 'appname' |
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
require "benchmark" | |
Benchmark.bm(7) do |x| | |
x.report("#any?") { (0...1_000_000_000_000).any? {|n| break true if n > 999_999} } | |
x.report("#map") { (0...1_000_000_000_000).map {|n| break true if n > 999_999}.is_a?(TrueClass) } | |
x.report("#each") { (0...1_000_000_000_000).each {|n| break true if n > 999_999} } | |
end | |
user system total real | |
#any? 9.210000 3.300000 12.510000 ( 12.554455) | |
#map 9.290000 3.320000 12.610000 ( 12.672998) |
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 Class | |
def attr_reader(name) | |
meth = Rubinius::AccessVariable.get_ivar name | |
@method_table[name] = meth | |
return nil | |
end | |
def attr_writer(name) | |
meth = Rubinius::AccessVariable.set_ivar name | |
@method_table["#{name}=".to_sym] = meth |
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
if ($.browser.msie) { | |
var minWidth = parseInt($("div#main").css("min-width").replace(/px/, "")); | |
$(window).resize(function(e) { | |
if ($(this).width() <= minWidth) { | |
$("div#main").width(minWidth); | |
} else { | |
$("div#main").css({ | |
width: "" | |
}); | |
} |
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
Note to Self: When encoding email from a web service, include attachments as raw data up to a certain size limitation. Majority of SMTP clients encode email as Base64/UUencode/String#unpack("m"). That's completely portable for web accessible content types, JSON, XML, RDF, 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
# | |
# haml helpers for rendering jQuery tab's - | |
# GPL3 license (any copy), copyright (c) 2009 cheapRoc aka Justin Reagor | |
# | |
module TabHelper | |
# | |
# Builds a list of tab menu link id's to iterate over as well as build tab content | |
# area div's, without the need to pass anything but the name of the link and a second | |
# call for the content block. |
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
jQuery(function($) { | |
if (typeof $.keys != 'function') { | |
$.extend({ | |
keys: function(obj) { | |
var a = []; | |
$.each(obj, function(k){ a.push(k) }); | |
return a; | |
} | |
}); | |
} |
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
// An attempt at recreating the same button style, cross browser... | |
// add the gradient image yoself foo | |
.btn | |
:display inline-block | |
:background none | |
:margin 0 | |
:padding 3px 0 | |
:border-width 0 |
OlderNewer