60% of the time it works EVERY time!
gem 'ny_address', git: 'git://gist.github.com/1672379.git'
... | |
<aside id="right"> | |
<nav id="tag_cloud"> | |
<h3>Browse by topic:</h3> | |
<% tag_cloud(tags, %w(tag1 tag2 tag3 tag4 tag5 tag6)) do |tag, tag_class| %> | |
<%= link_to tag.name, tagged_blog_posts_path(tag: tag.name), :class => "tag #{tag_class}" %> | |
<% end %> | |
</nav> | |
</aside> |
class UsersController < ApplicationController | |
# This can be moved to ApplicationController if | |
# every action within the application should respond to these MIME Types | |
respond_to :html, :json, :xml | |
def index | |
respond_with users | |
end |
string = ["b", "c", "d"].inject("a") { |result, element| result + element } | |
puts string |
module ApplicationHelper | |
# call this method in the view | |
# name should be a unique ID for this page, condition should be either truthy or falsey | |
def show_dialog_if(name, condition) | |
if condition | |
content = | |
link_to("click", "##{name}", | |
id: "#{name}_popup", class: "hidden", | |
data: {rel: "dialog", theme: "a"}) |
body{ | |
/* styles that apply globally go here */ | |
.hidden{ | |
display: none; | |
visibility: hidden; | |
} | |
} | |
body.blog{ | |
/* styles that only apply to blog pages go here |
# here's option one - standard way to add class methods and instance methods from a module into a class | |
module MyParent | |
# callback which is called on inclusion | |
def self.included(klass) | |
klass.extend(ClassMethods) | |
klass.send(:include, InstanceMethods) | |
end | |
# These are class methods added to klass |
// sum an array, optionally providing a function to call on each element of the | |
// array to retrieve the value to sum | |
Array.prototype.sum = function(fn) { | |
return this.reduce(function(accum, elem) { | |
return accum + (fn ? fn(elem) : elem); | |
}, 0); | |
}; | |
// flatten an array | |
// [1,2,[3,4]] -> [1,2,3,4] |
# Taking on the Binary Search challenge | |
# http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
class Array | |
# Binary search; assumes array is sorted | |
# If value is found in the array, it returns an index where it can be found. | |
# If the value occurs multiple times in the array, it will just return the | |
# first place it is found (not necessarily the first occurrence in the array). | |
# If the value is not found, it returns nil. | |
def bsearch(value) |