Skip to content

Instantly share code, notes, and snippets.

Merb::CustomFormats.add(:iphone) do
mime_type "application/xhtml+xml"
selector do |request, params|
request.user_agent && request.user_agent =~ /iPhone/i
end
end
@hassox
hassox / gist:36127
Created December 15, 2008 22:38 — forked from shingara/gist:36126
#Controller
before :ensure_authenticated, :exclude => [:index, :show]
def new(project_id)
only_provides :html
@ticket = Ticket.new(:project_id => project_id)
display @ticket
end
# RSPEC
class Array
def uniq_by(method)
results = []
self.map do |e|
result = e.send(method)
results.include?(result) ? nil : (results << result; e)
end.compact
end
end
Transfigr.add(:textile) do
after_activation do
require 'redcloth'
end
def format!
RedCloth.new(target).to_html
end
end
#!/usr/bin/env ruby
module FooVersions
module Version_0_1_0
def self.foo
:foo
end
module Constant1
def self.foo
class Exceptions < Merb::Controller
# handle NotFound exceptions (404)
def not_found
render :format => :html
end
# handle NotAcceptable exceptions (406)
def not_acceptable
render :format => :html
@hassox
hassox / thing.rb
Created February 24, 2009 05:10 — forked from jsmestad/thing.rb
def display
result = open(gist_url).read
out = result.scan(/document.write\('(.*|\s*)'\)/)[1]
out.nil? ? "Not Found" : out[0]
end
def f(ra,n)
ra.inject(0){ |c, x| x.include? n ? c + 1 : c }
end
@hassox
hassox / gist:70633
Created February 26, 2009 03:36 — forked from DylanFM/gist:70625
def f(ra,n)
ra.inject(0) { |r,x| r += 1 if x.include? n; r }
end
@hassox
hassox / gist:70634
Created February 26, 2009 03:36 — forked from DylanFM/gist:70625
def f(ra,n)
ra.inject(0) { |r,x| r += 1 if x.include? n; r }
end