Skip to content

Instantly share code, notes, and snippets.

Avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
@saturnflyer
saturnflyer / gist:10140954
Created Apr 8, 2014
overriding presenter with
View gist:10140954
def with_conditions(method_name, computed_value)
if method_name.to_s == 'address' && !computed_value.nil?
address.renderable?
else
super
end
end
View meta.rb
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
View gist:2ead89f0cb8b5b1f1d41
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
View gist:a11515249e8d49c9bc38
<div rel="warning-record">
<p>Warning text... <span rel="which-field">1</span> of 3</p>
</div>
View gist:37d892231b1e89516257
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
View model_feature.rb
# 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
View radiant census
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
View Fisher-Yates Javascript shuffle
// 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;};
View Basic Radiant CMS Navigation
<ul><r:find url="/">
<r:children:each><li><r:link /></li>
</r:children:each></r:find></ul>
View css grid lists in sass
.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