Skip to content

Instantly share code, notes, and snippets.

View wuputah's full-sized avatar
🐘

Jonathan Dance (JD) wuputah

🐘
View GitHub Profile
@wuputah
wuputah / has_fields.rb
Created October 1, 2008 01:12
has_fields plugin
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
#!/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
#!/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
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql'
require 'highline'
require 'optparse'
class CopyDatabase
def initialize(options = {})
# 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
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] } }
#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.
#
# 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
// 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);
}
})
}
/*
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;