This file contains hidden or 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
curl -silent http://checkip.dyndns.org | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | pbcopy |
This file contains hidden or 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
# same as redirect_to(:back) but works even if no referer (e.g. via direct url) | |
# include this module to ApplicationController | |
module BackDefaultRedirect | |
protected | |
# use as redirect_to back_or_default(root_url) | |
def back_or_default(default = '/') | |
referer = request.env['HTTP_REFERER'] | |
# if has HTTP_REFERER and it not equals current url | |
if referer && !referer.include?(request.request_uri) |
This file contains hidden or 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
desc "Shortcut for functional tests" | |
task :f => "test:functionals" | |
desc "Shortcut for unit tests" | |
task :u => "test:units" | |
desc "Shortcut for integration tests" | |
task :i => "test:integration" | |
desc "Run unit and functional tests" |
This file contains hidden or 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
if Rails.logger.level = Logger::DEBUG | |
ActiveRecord::Base.module_eval do | |
class << self | |
def find_by_sql_with_instantiate_logging(sql) | |
message = connection.send(:format_log_entry, "#{name} Load+Instantiate") | |
ActiveRecord::Base.benchmark(message, Logger::DEBUG, false) do | |
find_by_sql_without_instantiate_logging(sql) | |
end | |
end |
This file contains hidden or 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
server { | |
listen 80; | |
server_name APP.com; | |
rewrite ^/(.*) http://www.APP.com/$1 permanent; | |
} | |
server { | |
listen 80; | |
server_name www.APP.com; | |
root /home/USER/sites/APP/current/public; |
This file contains hidden or 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
module ActiveRecordSelectAttributesExtension | |
def select_id(field = 'id') | |
select_values(field) | |
end | |
def select_values(field = nil) | |
scope = field ? self.scoped.select(field) : self.scoped | |
connection.select_values(scope.to_sql) | |
end |
This file contains hidden or 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
require 'json' | |
require 'open-uri' | |
gists = JSON.parse(open("http://gist.github.com/api/v1/json/gists/#{ENV['GIST_USER']}").read)['gists'] | |
repos = gists.map{|g| g['repo']} | |
existing, new = repos.partition{|r| File.exists?(r)} | |
new.each do |r| | |
puts "clone new #{r} gist" | |
`git clone git://gist.github.com/#{r}.git` |
This file contains hidden or 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
# more simple version of https://github.com/itkin/respond_to_parent.git without dirty hacks that works good in rails3 | |
# usage: | |
# in controller#create append render :layout => false | |
# in create.html.erb | |
# <%= eval_javascript_in_parent(<<EOF | |
# $('#entries-list').prepend('#{escape_javascript(render @entry)}'); | |
# EOF | |
# ) %> | |
# | |
# most source from https://github.com/itkin/respond_to_parent/blob/master/lib/responds_to_parent.rb |