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
namespace :db do | |
namespace :schema do | |
task :load => :alias_create_table | |
task :alias_create_table do | |
# WTF! | |
if /_test$/ === ActiveRecord::Base.connection.instance_variable_get('@connection_options')[3] | |
max_heap_table_size = 180 # Mb | |
ActiveRecord::Base.connection.execute("SET max_heap_table_size = #{max_heap_table_size} * 1024 * 1024") | |
module ActiveRecord::ConnectionAdapters::SchemaStatements |
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
class Article < ActiveRecord::Base | |
named_scope :with_total_articles_published, | |
:select => 'articles.*, COUNT(*) AS total_articles_published', | |
:group => 'user_id' | |
end | |
Article.with_total_articles_published.each do |aggregate_article| | |
puts "User #{aggregate_article.user_id} has published" \ | |
" #{pluralize(aggregate_article.total_articles_published, 'article')}" | |
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
module InsertOnDuplicateKeyUpdate | |
def self.included(model) | |
model.class_attribute :insert_max_rows | |
model.insert_max_rows = 1_000 | |
model.extend ClassMethods | |
end | |
module ClassMethods | |
def insert_on_duplicate_key_update(rows, on_duplicate = nil) | |
return insert_on_duplicate_key_update([rows], on_duplicate) unless rows.kind_of?(Array) |
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
sudo env ARCHFLAGS='-arch i386' gem install cairo |
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
class Tag < ActiveRecord::Base | |
has_many :taggings | |
end | |
class Tagging < ActiveRecord::Base | |
set_inheritance_column nil | |
belongs_to :tag | |
belongs_to :posts | |
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
<html> | |
<head> | |
<title>Form Submit Test</title> | |
<script src="http://www.google.com/jsapi"></script> | |
<script> | |
// Load prototype | |
google.load("prototype", "1.6.0.3"); | |
google.setOnLoadCallback(function() { | |
var form = $('myform'), |
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
/* | |
Buffer up calls to groups of functions, unwind stack when precondition is met. | |
Calls to a buffered function prior to its preconditions being met are queued | |
and are later played back to the function when the precondition is met. | |
Groups of functions can share a common call stack by sharing a precondition object, | |
which is a simple function reference. | |
For simple control over how calls are played back, provide a tag with each buffered |
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
Array.prototype.binarySearch = function binarySearch(find, comparator, insert) { | |
if (!comparator) { | |
comparator = function(a,b) { | |
return ((a == b) ? 0 : ((a < b) ? -1 : 1)); }; | |
} | |
var low = 0; | |
var high = this.length - 1; | |
var i, comparison; | |
while (low <= high) { | |
i = parseInt((low + high) / 2, 10); |
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
(function() { | |
var s = "prefix arg1\narg2", | |
expected_capture = "arg1\narg2", | |
regexps = [ | |
/prefix\s+(.*)$/, // base | |
/prefix\s+(.*)$/m, /prefix\s+(.*)$/g, /prefix\s+(.*)$/mg, | |
/prefix\s([\s\S]*)$/, // base | |
/prefix\s([\s\S]*)$/m, /prefix\s([\s\S]*)$/g, /prefix\s([\s\S]*)$/mg | |
]; |
OlderNewer