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 HasFields | |
def has_any?(*fields) | |
fields.each { |f| return true unless self.send(f).blank? } | |
false | |
end | |
def has_all?(*fields) | |
fields.each { |f| return false if self.send(f).blank? } | |
true | |
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
#!/usr/bin/env ruby | |
`find /var/www/vhosts/santosdumont.com/web_users/ -type f`.split("\n").each do |file| | |
basename = File.basename(file) | |
system("mv", file, "/var/www/vhosts/santosdumont.com/httpdocs/Resource/" + basename) | |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mysql' | |
from_database = 'something_production' | |
to_database = 'something_development' | |
connection = Mysql.connect('localhost', 'username', 'password', from_database) | |
connection.query_with_result = false |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mysql' | |
require 'highline' | |
require 'optparse' | |
class CopyDatabase | |
def initialize(options = {}) |
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
# Challenge: | |
# change foo(bar) into bar.foo | |
# | |
# Why this is hard: | |
# method foo is a method of self, which we wouldnt | |
# have access to from within any method we create | |
class Object |
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
named_scope :has_commissions, lambda { |amount| { :conditions => ["id IN (SELECT user_id FROM (SELECT user_id, SUM(amount) AS amount FROM commissions GROUP BY user_id HAVING amount > ?) AS a)", amount] } } |
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
#BEGIN CONFIG INFO | |
#DESCR: 4GB RAM, InnoDB only, ACID, few connections, heavy queries | |
#TYPE: SYSTEM | |
#END CONFIG INFO | |
# | |
# This is a MySQL example config file for systems with 4GB of memory | |
# running mostly MySQL using InnoDB only tables and performing complex | |
# queries with few connections. | |
# |
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
# All the places I used !! in a very sizable project | |
# (4 cases in 7600 LOC, about 40% of which is specs) | |
# ActiveRecord callback - writing to a DB: | |
def update_has_emailable_accounts! | |
# !! replaces "condition ? true : false" | |
self.update_attribute(:has_emailable_accounts, !!accounts.detect { |account| account.emailable? }) | |
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
// invokes +callback+ on elements found by +selector+ that have an href property value | |
// equal to the current page (pathname). It is recommended to use a selector that selects | |
// anchor (a) elements. | |
function currentPage(selector, callback) { | |
$$(selector).each(function(e) { | |
if (e.href == document.URL) { | |
callback.call(null, e); | |
} | |
}) | |
} |
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
/* | |
The shuttle is a 1-5 paged slideshow of elements with pagination and small dots | |
to indicate what page you are on. The slideshow auto-advances when you're not | |
using it, and a few other minor features. | |
Implemented with Prototype and Low Pro. | |
*/ | |
Shuttle = {}; | |
Shuttle.CurrentPage = 1; | |
Shuttle.AutoAdvanceTime = 0; |