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
module InsertWithUpdate | |
# INSERT INTO .. ON DUPLICATE KEY UPDATE .. | |
def insert_with_update(attributes, update_sql) | |
columns = [] | |
values = [] | |
attributes.each_pair do |attr, value| | |
columns << connection.quote_column_name(attr) | |
values << connection.quote(value) | |
end | |
connection.insert "INSERT INTO #{quoted_table_name} (#{columns.join(',')}) VALUES (#{values.join(',')}) ON DUPLICATE KEY UPDATE #{update_sql}" |
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
module MultiInsert | |
# This method almost like sequels dataset.import() | |
# | |
# Inserts multiple records into the associated table. | |
# | |
# This method is called with a columns array and an array of value arrays: | |
# | |
# Model.mass_insert(['x', 'y'], [[1, 2], [3, 4]]) | |
# | |
def multi_insert(columns, values) |
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
javascript:(function(){ var css = '.entry-row.expanded {font-size: 130% !important;} .entry {padding-left: 30px;}';var sn = document.createElement("style"); sn.setAttribute("type", "text/css");sn.setAttribute("media", "screen"); sn.appendChild(document.createTextNode(css));document.getElementsByTagName("head")[0].appendChild(sn);})() |
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
require 'bundler/capistrano' | |
set :application, "APPNAME" | |
set :domain, "mydomain.com" | |
set :user, "deployer" | |
set :password, "" | |
set :runner, user | |
default_run_options[:pty] = true # Must be set for the password prompt from git to work |
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
silence_warnings do | |
ActionDispatch::Request::LOCALHOST = (ActionDispatch::Request::LOCALHOST + ['192.168.0.1']).freeze | |
end | |
ActionController::Base.module_eval do | |
def show_detailed_exceptions? | |
request.local? | |
end | |
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
# Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler | |
if defined?(::Bundler) | |
$LOAD_PATH.concat Dir.glob("#{ENV['rvm_path']}/gems/#{ENV['rvm_ruby_string']}@global/gems/*/lib") | |
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
require 'irb/completion' | |
require 'pp' | |
require 'rubygems' | |
# Automatic Indentation | |
IRB.conf[:AUTO_INDENT] = true | |
# Remove the annoying irb(main):001:0 and replace with >> | |
IRB.conf[:PROMPT_MODE] = :SIMPLE | |
# Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler |
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
# 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 |
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
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 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 |