Skip to content

Instantly share code, notes, and snippets.

@ak47
ak47 / databases.rake
Created July 28, 2011 18:56
Monkey patch activerecord-3.0.9/lib/active_record/railties/databases.rake enables parallel_tests to work on my PG Jenkins CI
# #{Rails.root}/lib/tasks/databases.rake
=begin
Monkey Patch
activerecord-3.0.9/lib/active_record/railties/databases.rake
clears obstinate stale PG session to get parallel_tests working
also, PG user must be superuser to use these low level PG functions
=end
def drop_database(config)
case config['adapter']
when /mysql/
@ak47
ak47 / gist:1152763
Created August 17, 2011 22:07
jenkins output
Cleared workspace.
Note: .repository direcotry in workspace (if exists) is skipped ...
Using remote perforce client: jenkins_test_cores-110152493
[test-cores] $ /usr/bin/p4 workspace -o jenkins_test_cores-110152493
Saving modified client jenkins_test_cores-110152493
[test-cores] $ /usr/bin/p4 -s client -i
Last build changeset: 214959
[test-cores] $ /usr/bin/p4 counter change
Sync'ing workspace to changelist 214959 (forcing sync of unchanged files).
[test-cores] $ /usr/bin/p4 -s sync -f //jenkins_test_cores-110152493/...@214959
@ak47
ak47 / gist:1238735
Created September 23, 2011 23:49
multi-process, multi-pipes
require 'awesome_print'
read_pipes = Array.new
3.times do |index|
parent_read, child_write = IO.pipe
read_pipes << parent_read
fork do
begin
@ak47
ak47 / gist:1259787
Created October 3, 2011 18:03
CSV stream with compression
def new
returned_data = Report.get_report
respond_to do |format|
format.csv{
filename = "#{Report.get_name[params[:id]]}_#{Time.now.strftime("%Y_%m_%d_%H_%M")}_#{branch]}.csv"
temp = Tempfile.new(filename)
temp << FasterCSV.generate(:force_quotes => true){ |csv| csv << returned_data[:headers]; returned_data[:data].map { |x| csv << x }; }
temp.close
`pigz #{temp.path}`
@ak47
ak47 / gist:1278823
Created October 11, 2011 17:46
How to load RVM in Ruby Net::SSH session
Net::SSH.start('<server>','<user_name>',:password => '<secret>') do |ssh|
ssh.exec!(". $HOME/.rvm/scripts/rvm; ruby -v")
end
@ak47
ak47 / gist:1469862
Created December 13, 2011 00:45
cap-mailer error
/my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:65:in `protected_instance_variables': undefined method `protected_instance_variables' for #<Hash:0x00000102286768> (NoMethodError)
from /my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:134:in `view_assigns'
from /my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:87:in `view_context'
from /my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:120:in `_render_template'
from /my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:114:in `render_to_body'
from /my_gems/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:99:in `render'
from /my_gems/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:718:in `block in collect_responses_and_parts_order'
from /my_gems/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:729:in `each'
from /my_gems/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:729:in `each_template'
from /my_gems/gems/actionmailer-3.1.3/lib/action_mailer/base.r
module ActsAsCatchall
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
class << self; attr_accessor :catchall end
def acts_as_catchall(options = {})
# db_field, klass, use_method_missing = false
module B
def self.included(base)
class << base
attr_accessor :catch
def acts_as_catchall(hsh)
self.catch = hsh
end
end
end
module B
def self.included(base)
class << base
attr_accessor :catch
def acts_as_catchall(hsh)
@catch = hsh
end
def inherited(subclass)
subclass.catch = subclass.superclass.catch
[vagrant@localhost ~]$ yum list freetds
Loaded plugins: fastestmirror, security
Determining fastest mirrors
* base: mirrors.seas.harvard.edu
* epel: linux.mirrors.es.net
* extras: centos.mirror.netriplex.com
* updates: mirror.pac-12.org
Installed Packages
freetds.x86_64 0.91-2.el6 @epel
Available Packages