Skip to content

Instantly share code, notes, and snippets.

set :slice3, '72.46.232.204:7005'
set :slice1, '72.46.232.204:7009'
set :slice2, '72.46.232.204:7012'
set :slice4, '72.46.232.204:7002'
set :slice5, '72.46.232.204:7003'
set :slice6, '72.46.232.204:7004'
set :slice7, '72.46.232.204:7006'
set :slice8, '72.46.232.204:7010'
set :slice9, '72.46.232.204:7013'
set :slice10, '72.46.232.204:7007'
class Hash
def without *args
reject { |key, val| args.include? key }
end
end
h = { :one => 1, :two => 2, :three => 3 }
h.without :one
#=> { :two => 2, :three => 3 }
module App::Controllers::MobileSupport
def self.included(base)
base.send :before_filter, :redirect_to_appropriate_site
base.send :helper_method, :iphone_request?
base.send :helper_method, :touch_request?
end
def redirect_to_appropriate_site
if on_touch_site? and requesting_full_site?
#!/usr/bin/ruby
#
# I deliberately didn't DRY /usr/local references into a variable as this
# script will not "just work" if you change the destination directory. However
# please feel free to fork it and make that possible.
#
# If you do fork, please ensure you add a comment here that explains what the
# changes are intended to do and how well you tested them.
#
# 30th March 2010:
@mattpuchlerz
mattpuchlerz / gist:297635
Created February 7, 2010 19:46
Simple bash script to zoom OS X applications and open up a project full-screen in TextMate.
zoom() {
if [ -z $1 ]; then
echo "usage: $FUNCNAME ApplicationName"
else
osascript -e "tell application \"$1\" to set zoomed of window 1 to not (zoomed of window 1)" 2>&1 >/dev/null
fi
}
alias mysite="cd ~/Sites/mysite.com && mate app/ config/ features/ public/ spec/ && zoom TextMate"
Date.prototype.beginningOfWeek = function (startOfWeek) {
startOfWeek = startOfWeek || 0;
return new Date( this - ( (this.getDay() - startOfWeek) * 86400000) );
}
@mattpuchlerz
mattpuchlerz / Hash#map_values.rb
Created March 24, 2009 20:07
A mapping method for Hash whose behavior is much more in line with Array#map, in that it applies the passed block only to the hash's values, otherwise returning the hash in its original form.
class Hash
def map_values(&block)
Hash[*self.map{ |i| i[1] = yield(i[1]); i }.flatten]
end
end
[ 'asdf', 'qwer' ].map{ |val| val * 2 }
# => [ 'asdfasdf', 'qwerqwer' ]
{ :one => 'asdf', :two => 'qwer' }.map{ |val| val * 2 }