Skip to content

Instantly share code, notes, and snippets.

View benhoskings's full-sized avatar

Ben Hoskings benhoskings

View GitHub Profile
class Object
def new_with &block
self.new.instance_eval {
yield
}
end
end
$logger = Object.new_with {
define_method :foo do
# 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
#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
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
%a{{:href => name},{:class => ('selected' if @category == name)}}
%span= name
________ __ ___ __ __
/ ____/ /__ ____ / |/ /___ _____/ /___/ /__ _________
/ / __/ / _ \/ __ \ / /|_/ / __ `/ __ / __ / _ \/ ___/ __ \
/ /_/ / / __/ / / / / / / / /_/ / /_/ / /_/ / __/ / / / / /
\____/_/\___/_/ /_/ /_/ /_/\__,_/\__,_/\__,_/\___/_/ /_/ /_/
__ __ __ __ __
/ \ |__| _) _) /| /| (__) | / \ |
\__/ | /__ __) | | (__) |___ \__/ |___
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',
git config --global alias.lg "log --graph --since='1 week ago' --pretty=format:'%Cblue%h%Creset %cr %Cgreen%an%Creset %s'"
# 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'
]
# 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