Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
@saturnflyer
saturnflyer / gist:10140954
Created April 8, 2014 15:17
overriding presenter with
def with_conditions(method_name, computed_value)
if method_name.to_s == 'address' && !computed_value.nil?
address.renderable?
else
super
end
end
mod = Module.new
mod.module_eval %{
def fill_out_#{name}(value)
checkbox = find(:#{name})
if (#{name}_checked_values.include?(value) && !checkbox.selected?) ||
(#{name}_unchecked_values.include?(value) && checkbox.selected?)
checkbox.click
end
end
require 'resolv'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if Resolv::DNS.new.getresources(value.split("@").last, Resolv::DNS::Resource::IN::MX).empty?
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
rescue Resolv::ResolvError, Resolv::ResolvTimeout
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
<div rel="warning-record">
<p>Warning text... <span rel="which-field">1</span> of 3</p>
</div>
class Something
def self.protector(name, &block)
begin
call_mod = self.const_get(:ExternalSystemCalls, false)
rescue NameError
call_mod = Module.new
const_set(:ExternalSystemCalls, call_mod)
include call_mod
end
begin
# This is designed to be used in cell classes but will work with any class
# which has a 'model' method.
#
# Example:
#
# class UserCell < Cell::ViewModel
# extend ModelFeature
#
# model_feature :name
# end
task :census => ['census:snippets', 'census:layouts']
namespace :census do
desc "Show usage stats for Snippets"
task :snippets => :environment do
snippets, missing_snippets = snippet_usage
longest_name = snippets.keys.inject(0) do |max, name|
max = name.to_s.size > max ? name.to_s.size : max
// Fisher-Yates shuffle
function fyshuffle(a){ var t,i,l = a.length; if(l) while(--l){ i = Math.floor(Math.random() * (l + 1)); t = a[i]; a[i] = a[l]; a[l] = t; }; return a;};
<ul><r:find url="/">
<r:children:each><li><r:link /></li>
</r:children:each></r:find></ul>
.grid_list li
display: -moz-inline-box
-moz-box-orient: vertical
display: inline
display: inline-block
vertical-align: top
word-wrap: break-word
list-style: none
* html .grid_list li