Skip to content

Instantly share code, notes, and snippets.

JD wuputah

Block or report user

Report or block wuputah

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:6804
# e is for efficient. There's not really a way to eager load associations yourself
# without AR thinking you're trying to assign or create something.
attr_accessor :echildren
def self.find_all_efficiently
categories = find(:all, :order => 'position ASC, name ASC').inject( do |h, c|
h[c.parent_id] ||= []
h[c.parent_id] << c
wuputah / s3-copy-bucket.rb
Created Sep 29, 2008
Copies contents of S3 bucket
View s3-copy-bucket.rb
require 'rubygems'
require 'right_aws'
access_key = 'abc'
secret = 'xyz'
src = 'src'
dest = 'dest'
wuputah / grant-public-read-to-bucket.rb
Created Sep 29, 2008
Grants public read to an S3 bucket
View grant-public-read-to-bucket.rb
require 'rubygems'
require 'aws/s3'
include AWS::S3
:access_key_id => 'abc',
:secret_access_key => '123'
View has_fields.rb
module HasFields
def has_any?(*fields)
fields.each { |f| return true unless self.send(f).blank? }
def has_all?(*fields)
fields.each { |f| return false if self.send(f).blank? }
View gist:15387
#!/usr/bin/env ruby
`find /var/www/vhosts/ -type f`.split("\n").each do |file|
basename = File.basename(file)
system("mv", file, "/var/www/vhosts/" + basename)
View mysql-copydb.rb
#!/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
View mysql-copydb.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql'
require 'highline'
require 'optparse'
class CopyDatabase
def initialize(options = {})
View object-invoke.rb
# Challenge:
# change foo(bar) into
# 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
View awful-named-scope.rb
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] } }
View gist:34948
#DESCR: 4GB RAM, InnoDB only, ACID, few connections, heavy queries
# 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.
You can’t perform that action at this time.