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 Object | |
def new_with &block | |
self.new.instance_eval { | |
yield | |
} | |
end | |
end | |
$logger = Object.new_with { | |
define_method :foo do |
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
# Original from Mitchell | |
def self.first_uninteresting | |
all_numbers = Number.find(:all).map { |entry| entry.number }.sort | |
last = 0 | |
all_numbers.each do |number| | |
if number != last + 1 | |
return last + 1 | |
end | |
last = 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
#Ruby assignment option to assign unless nil | |
replacement_content = page_contents.content_label_find(item) | |
########################################################## | |
# The following is wrong, see http://gist.github.com/68772 | |
########################################################## | |
# This | |
element.inner_html = replacement_content if replacement_content |
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 Array | |
def count_if | |
inject(0) {|acc, i| acc + (yield(i) ? 1 : 0) } | |
end | |
end | |
def f(ra,n) | |
ra.count_if {|x| x.include? n } | |
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
%a{{:href => name},{:class => ('selected' if @category == name)}} | |
%span= name |
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
________ __ ___ __ __ | |
/ ____/ /__ ____ / |/ /___ _____/ /___/ /__ _________ | |
/ / __/ / _ \/ __ \ / /|_/ / __ `/ __ / __ / _ \/ ___/ __ \ | |
/ /_/ / / __/ / / / / / / / /_/ / /_/ / /_/ / __/ / / / / / | |
\____/_/\___/_/ /_/ /_/ /_/\__,_/\__,_/\__,_/\___/_/ /_/ /_/ | |
__ __ __ __ __ | |
/ \ |__| _) _) /| /| (__) | / \ | | |
\__/ | /__ __) | | (__) |___ \__/ |___ |
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
def value_for_label object, method | |
(object && object.send(method)) || "-" | |
end | |
def conditions_map_for conditions | |
{ | |
:dp_c => 'Dew point', | |
:rh => 'Relative humidity', | |
:feels_like_c => 'feels like', | |
:wind_dir_and_speed => 'Wind', |
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
git config --global alias.lg "log --graph --since='1 week ago' --pretty=format:'%Cblue%h%Creset %cr %Cgreen%an%Creset %s'" |
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
# dynamic removal of a dep requirement, | |
# based on a condition evaluated after previous requires have been processed | |
dep 'site' do | |
requires [ | |
'system', | |
'account', | |
'site dir', | |
'site options' | |
] |
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
# One thing to add: | |
# * action_has_layout? method (if you have one, combine them) | |
# | |
class ApplicationController < ActionController::Base | |
# ... | |
private | |
def action_has_layout? | |
!request.xhr? && super |
OlderNewer