Skip to content

Instantly share code, notes, and snippets.

class Hash
def method_missing(name, *args)
key = name.to_s
return self[key[0..-2]] = args.first if key =~ /=$/
has_key?(key) ? self[key] : self.class.new
end
end
params = { 'user' => { 'name' => 'Chris' } }
module ValidAttributes
def valid_attributes?(*args)
attributes = [*args].flatten.map { |e| e.to_s }
valid? || (errors.keys & attributes).empty?
end
module Errors
delegate :keys, :to => '@errors'
end
end
action = ARGV.shift
cluster_count = 5
$cluster_port = 4000
def service_control(action, port)
puts " * #{action.to_s.capitalize}ing service on port #{port+$cluster_port}..."
%x{mongrel_rails.cmd service::#{action.to_s} -N slate#{port + $cluster_port}}
end
if action.nil?
# helpers/path_helper.rb
module PathHelper
def path_as_array
path = (request.path_info || '').gsub(/^#{Bones.base}/, '')
path = path.split('/').map {|e| e.empty? ? nil : e}.compact
end
def current_path(depth=-1)
File.join('/', *[path_as_array[0..depth]])
end
require 'erb'
@content_for_layout = "page content"
erb = ERB.new("<div><%= yield %></div>")
eval(erb.src) do |key|
key = :layout if key.nil?
instance_variable_get(:"@content_for_#{key}")
end
# config/locales/en.yml
en:
activerecord:
attributes:
customer:
email_primary: E-mail
screenname: Screen name
ct_password: Password
ct_password_confirmation: Password
phone_primary: Home phone number
# vendor/plugins/article-slate-plugin/init.rb
Slate::Plugin.install('article') do |plugin|
plugin.navigation do |tabs|
tabs.add 'Articles', space_articles_path(Space.active)
end
plugin.mount 'articles',
:name => 'Articles',
:template => 'blog.html.erb'
end
# Reset mysql root password
pkill mysqld
mysqld_safe --skip-grant-tables &
mysql -u root mysql
UPDATE user SET password=PASSWORD('') WHERE user="root";
FLUSH PRIVILEGES;
pkill mysqld_safe
/etc/init.d/mysqld start
{
"quality": "high",
"rationale": {
"quality": { "value": "rationale for quality", "publisher_id": "7" }
}
"score": {
"quality": "55"
}
jQuery.fn.or = function(expr) {
return (this.length > 0 ? this : jQuery(expr));
}
// Example: returns result for #wrap if result for #container
// is empty (0 elements)
$('#container').or('#wrap')
// Another example:
// Here, we want to grab the next sibling 'li' element,