This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"quality": "high", | |
"rationale": { | |
"quality": { "value": "rationale for quality", "publisher_id": "7" } | |
} | |
"score": { | |
"quality": "55" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
OlderNewer