Skip to content

Instantly share code, notes, and snippets.

View workmad3's full-sized avatar

David Workman workmad3

View GitHub Profile
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]
>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++
.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
module Kernel
def scoped_extend(obj, method_name, method_body, &blk)
stored_method = nil
if (obj.respond_to? method_name)
stored_method = obj.method(method_name)
end
eigenclass = class << obj
self
end
eigenclass.send(:define_method, method_name, &method_body)
#currently you are doing this (effectively)
a = {:action => "list", :notice => "yay"}
redirect_to a
#you want to be doing this
a = {:action => "list"}
b = {:notice => "yay"}
redirect_to a, b
#which you can do by explicitly adding the braces around the URL stuff, like so
redirect_to {:action => "list"}, :notice => "yay"
def get_ij(m, n)
(m*n).times do |i|
i,j = i.divmod(n)
if test(i,j)
yield i,j and return
end
end
end
class Class
def self.attr_accessor_defaults(attrs)
attrs.each do |k, v|
attr_writer(k)
define_method(k) { instance_variable_defined?("@#{k}") ? instance_variable_get("@#{k}") : v }
end
end
end
module Kernel
attr_accessor :__defaults
def attr_accessor_defaults(attributes)
attr_accessor(*attributes.keys)
@__defaults ||= {}
@__defaults.merge!(attributes)
end
private :attr_accessor_defaults
def is_url(str)
u = URI.parse(str)
u.class == URI::HTTP || u.class == URI::HTTPS
rescue URI::InvalidURIError
false
end
@workmad3
workmad3 / plural
Created December 2, 2010 10:40
singular
resource :account do
resource :table do
collection do
get 'projects'
end
end
end
Easygram::Application.routes.draw do
resources :templates
resources :clients do
resources :users
member do
get "templates" => "clients#templates"
post "templates" => "clients#templates_save"
end
end
resources :telegrams, :controller => :messages, :only => [:index, :new]
include ActionView::Helpers::FormOptionsHelper
include ActionView::Helpers::TagHelper
counties = [["England", ["Bedfordshire", "Berkshire", "Bristol", "Buckinghamshire", "Cambridgeshire", "Cheshire", "Cornwall", "Cumbria", "Derbyshire", "Devon", "Dorset", "Durham", "East Yorkshire", "East Sussex", "Essex", "Gloucestershire", "Greater Manchester", "Hampshire", "Herefordshire", "Isle of Wight", "Kent", "Lancashire", "Leicestershire", "Lincolnshire", "London", "Merseyside", "Norfolk", "North Yorkshire", "Northamptonshire", "Northumberland", "Nottinghamshire", "Oxfordshire", "Rutland", "Shropshire", "Somerset", "South Yorkshire", "Staffordshire", "Suffolk", "Surrey", "Tyne & Wear", "Warwickshire", "West Midlands", "West Sussex", "West Yorkshire", "Wiltshire", "Worcester"]], ["Northern Ireland", ["County Antrim", "County Armagh", "County Down", "County Fermanagh", "County Londonderry", "County Tyrone"]], ["Scotland", ["Aberdeenshire", "Angus", "Argyll & Bute", "Clackmannanshire", "Dumfries & Galloway", "Dundee", "