Skip to content

Instantly share code, notes, and snippets.

def login_required
authorized? || access_denied
end
def access_denied
respond_to do |format|
format.html do
store_location
redirect_to new_session_path
end
def login_required
authorized? || access_denied
end
def access_denied
respond_to do |format|
format.html do
store_location
redirect_to new_session_path
end
def to_html
rows = data.map{|row| " <tr>#{row.map{|d| "<td>#{d}</td>"}.join}</tr>"}
"<table>\n#{rows.join("\n")}\n</table>"
end
>> phrases = ["Mr. Gregory Browne", "Mr. Gregory Brown is cool",
"Gregory Brown is cool", "Gregory Brown"]
>> phrases.grep /\AGregory Brown\b/
=> ["Gregory Brown is cool", "Gregory Brown"]
>> phrases.grep /\bGregory Brown\b/
=> ["Mr. Gregory Brown is cool", "Gregory Brown is cool", "Gregory Brown"]
>> phrases.grep /\AGregory Brown\z/
def set_my_ivar
@my_ivar = 'set'
end
class A
attr_reader :my_ivar
def test_the_setting
set_my_ivar
end
@bradediger
bradediger / gist:86215
Created March 26, 2009 17:38
Please don't do this.
def Service(name)
Class.new(ActiveResource::Base) do
self.site = ServiceLocator[name]
self.user = 'api'
self.password = 'ooga-booga'
def self.-@
self
end
end
module Madriska
module Prawn
module ColumnLayout
def columns(column_spec)
@columns = distribute_columns(column_spec, bounds.width)
@column_x = 0
@column_lowest_y = @y
yield
@columns = nil
shaver_triton=# select a.state, a.name, st_distance(a.the_geom, il.the_geom) from states_provinces a, states_provinces il where a.state != il.state and il.name = 'Illinois' order by st_distance(a.the_geom, il.the_geom) asc;
state | name | st_distance
-------+----------------------+-------------------
21 | Kentucky | 0
19 | Iowa | 0
55 | Wisconsin | 0
18 | Indiana | 0
29 | Missouri | 0
47 | Tennessee | 0.465497409498616
26 | Michigan | 0.700251907865309
class FancyString < String
attr_accessor :bling
end
blingful_string = FancyString.new
blingful_string.bling = true
h = { blingful_string => 1 }
puts h.keys.first.bling.inspect # => nil