Skip to content

Instantly share code, notes, and snippets.

View zbelzer's full-sized avatar

Zachary Belzer zbelzer

  • IntegraCredit
  • Chicago
View GitHub Profile
@zbelzer
zbelzer / lazy.rb
Created March 13, 2012 17:58
Lazy enumerable?
class Lazy
include Enumerable
def initialize(max_iterations=nil, &block)
@max_iterations = max_iterations
@iterations = 0
@block = block
end
def each
@zbelzer
zbelzer / sort.rb
Created August 10, 2011 02:37
Ruby's Non-stable sorting
Item = Struct.new(:name, :position)
main = [Item.new('a', 0), Item.new('b', 0), Item.new('c', 1)]
sorted = [Item.new('d', 1), Item.new('e', 1), Item.new('f', 2)]
(main + sorted).sort_by {|item| item.position}
# My console output. Expected a, b then d, e and f with c anywhere in between them. YMMV
# [#<struct Item name="a", position=0>, #<struct Item name="b", position=0>, #<struct Item name="c", position=1>, #<struct Item name="e", position=1>, #<struct Item name="d", position=1>, #<struct Item name="f", position=2>]
# Could be useful for configuration objects
double = Hash.new({})
double[:foo][:bar] = "baz"
# Something you should probably know about alias...
class Parent
def foo
"bar"
end
alias :also_foo :foo
end
Found 67 institutions
Created user
Found user zach
User has 4 accounts
User belongs to 1 institutions
Selecting Local Test XML
Created the accounts 6136-6557
Creating statement for account 6136-6557
Creating statement for account 6136-6557 using start_date 2010-01-01 and end_date 2011-01-01
Creating statement for account 6136-6557 including OFX data
# Ruby code snippet:
def self.find_available(worker_name, limit = 6, max_run_time = Worker.max_run_time)
right_now = db_time_now
conditions = {
:run_at => {"$lte" => right_now},
:limit => -limit, # In mongo, positive limits are 'soft' and negative are 'hard'
:failed_at => nil,
:sort => [['priority', 1], ['run_at', 1]]
Setting up libxml-commons-external-java (1.3.04-2ubuntu1) ...
Setting up solr-common (1.4.0+ds1-1) ...
Setting up solr-jetty (1.4.0+ds1-1) ...
* Not starting jetty - edit /etc/default/jetty and change NO_START to be 0 (or comment it out).
Setting up chef-solr (0.8.8-3) ...
Creating vhost "/chef" ...
...done.
Creating user "chef" ...
/var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant Delayed::Job (NameError)
from /var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'
from /var/www/project/.bundle/gems/ts-delayed-delta-1.0.4/lib/thinking_sphinx/deltas/delayed_delta/job.rb:7
from /var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from /var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from /var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /var/www/project/.bundle/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from /var/www/project/.bundle/gems/ts-delayed-delta-1.0.4/lib/thinking_sphinx/deltas/delayed_delta.rb:5
from /var/www/project/.bundle/environment.rb:251:in `require'
from /var/www/project/.bund
namespace :db do
desc 'Dumps your current schema and data from the database into a timestamped .sql dumpfile'
task :dump => :environment do
puts "Dumping schema and data from #{@data_reload_helper.db_name} to #{@data_reload_helper.dump_path}"
# -c Includes the column names in the insert statement. Important when rails reorders your columns on different machines
@data_reload_helper.mysqldump('--add-drop-table -c')
end
desc 'Dumps your current schema and data from the database into a timestamped, gzipped .sql dumpfile'
task :dump_deflated => ['dump', 'dump:deflate']
root@ip-10-245-142-226:/var/www# chef-client
[Tue, 23 Mar 2010 19:21:44 +0000] INFO: Starting Chef Run
[Tue, 23 Mar 2010 19:21:48 +0000] INFO: Storing updated cookbooks/likeassets/recipes/appserver.rb in the cache.
[Tue, 23 Mar 2010 19:21:49 +0000] WARN: Missing gem 'right_aws'
[Tue, 23 Mar 2010 19:21:50 +0000] INFO: Setting up Rails app likeassets git@github.com:moneypools/rails @staging
[Tue, 23 Mar 2010 19:21:51 +0000] INFO: Ran bash[create_temp_git_ssh_key] successfully
[Tue, 23 Mar 2010 19:22:06 +0000] INFO: Ran ruby[create-new-local-repo] successfully
[Tue, 23 Mar 2010 19:22:06 +0000] INFO: Ran bash[delete_temp_git_ssh_key] successfully
[Tue, 23 Mar 2010 19:22:06 +0000] INFO: Setting owner to 33 for directory[/var/www/likeassets]
[Tue, 23 Mar 2010 19:22:06 +0000] INFO: Setting group to 33 for directory[/var/www/likeassets]