Skip to content

Instantly share code, notes, and snippets.

View brennandunn's full-sized avatar

Brennan Dunn brennandunn

View GitHub Profile
def children(options = {})
options.merge!({ :order => 'updated_at desc' })
options # => {:limit=>3, :order=>"updated_at desc"}
found = articles.find(:all, options)
options # => {:conditions=>"`articles`.section_id = 2", :readonly=>nil, :select=>nil, :group=>nil, :offset=>nil, :limit=>3, :include=>:_route, :joins=>nil, :order=>"updated_at desc, created_at desc"}
found += pages.find(:all, options)
found.sort! { |x, y| y.updated_at <=> x.updated_at }
options[:limit] ? found[0, options[:limit]] : found
end
def yui_js(arr)
defaults = [ 'yahoo-dom-event/yahoo-dom-event' ]
base = 'http://yui.yahooapis.com/combo?'
prefix = '2.5.2/build/'
src = base + (defaults + arr).uniq.map { |s| prefix + s }.join('&') + '.js'
%|<script type="text/javascript" src="#{src}"></script>|
end
#!/usr/bin/env ruby
Locations = {
'vatican' => 'home',
'dbstation' => 'remote'
}
Dotfile = ENV['RUN_AS'] ? File.expand_path("/Users/#{ENV['RUN_AS']}/.location") : File.expand_path('~/.location')
# ensure dotfile exists
<p:find title="Services">
<!-- set the current scope to the 'services' page -->
<p:children:each>
<!-- iterate over each child of services, which are the 'sections' -->
<h2><p:title/></h2> <!-- print out the section title -->
<ul>
<p:children:each>
<!-- now that we're in a 'section', iterate over each sub page -->
<li><p:link/></li> <!-- create a link to this sub page -->
</p:children:each>
if [[ -x `which git` ]]; then
function git-branch-name () {
git branch 2> /dev/null | grep ^\* | sed s/^\*\ //
}
function git-dirty () {
git status | grep "nothing to commit (working directory clean)"
echo $?
}
function gsrb () {
branch=$(git-branch-name)
class String
def method_missing(method, *args, &block)
if method.to_s =~ /is_(.*?)\?/
self.downcase == $1
else
raise NoMethodError, "Undefined method '#{method}' for #{self.inspect}"
end
end
end
%r{<#{@tag_prefix}:([\w:]+?)(\s+(?:\w+\s*=\s*(?:"[^"]*?"|'[^']*?')\s*)*|)>|</#{@tag_prefix}:([\w:]+?)\s*>}
<a href="javascript:void(0)" onclick="window.open('URL GOES HERE', 'keyword_here', 'fullscreen=yes,scrollbars=yes')">Click here for a new window</a>
module James
def movie ; "The Big Lebowski #{@special}" ; end
end
module Bob
def movie ; "Spiderman #{@special}" ; end
end
module Jane
def movie ; "Raiders of the Lost Ark #{@special}" ; end
module UserConcerns
module ControllerMethods ; end
module ModelMethods
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end