Skip to content

Instantly share code, notes, and snippets.

View nateware's full-sized avatar

Nate Wiger nateware

View GitHub Profile
@nateware
nateware / gist:216130
Created October 22, 2009 17:50
require 'mongo_mapper' causes exception in active_support
[nwiger@pdsd65-31-27:mongo]$ irb
irb(main):001:0> require 'mongo_mapper'
NameError: uninitialized constant MongoMapper::Associations::ManyDocumentsProxy::MongoMapper
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:105:in `rescue in const_missing'
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:94:in `const_missing'
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/mongo_mapper-0.5.5/lib/mongo_mapper/associations/many_documents_proxy.rb:7:in `<class:ManyDocumentsProxy>'
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/mongo_mapper-0.5.5/lib/mongo_mapper/associations/many_documents_proxy.rb:3:in `<module:Associations>'
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/mongo_mapper-0.5.5/lib/mongo_mapper/associations/many_documents_proxy.rb:2:in `<module:MongoMapper>'
from /usr/playerconnect-stack-2009e/lib/ruby/gems/1.9.1/gems/mongo_mappe
@nateware
nateware / patch to fix mongo_mapper require issue
Created October 22, 2009 17:57
patch to fix mongo_mapper require issue
--- mongo_mapper-0.5.5/lib/mongo_mapper/associations/many_documents_proxy.rb.orig 2009-10-22 10:55:04.000000000 -0700
+++ mongo_mapper-0.5.5/lib/mongo_mapper/associations/many_documents_proxy.rb 2009-10-22 10:54:26.000000000 -0700
@@ -4,7 +4,7 @@
delegate :klass, :to => :@association
delegate :collection, :to => :klass
- include MongoMapper::Finders
+ include ::MongoMapper::Finders
def find(*args)
@nateware
nateware / wordpress_bulk_comments
Created November 4, 2009 17:47
Bulk updating Wordpress comments
-- Bulk updating your pending Wordpress comments as spam when you have thousands of them.
mysql> select comment_approved, count(*) from wp_comments group by comment_approved;
+------------------+----------+
| comment_approved | count(*) |
+------------------+----------+
| 0 | 2052 |
| 1 | 3 |
| spam | 441 |
+------------------+----------+
@nateware
nateware / gist:249348
Created December 4, 2009 20:46
will_paginate row_start / row_end
diff --git a/lib/redis/text_search/collection.rb b/lib/redis/text_search/collection.rb
index 3e3afe8..fcec4d2 100644
--- a/lib/redis/text_search/collection.rb
+++ b/lib/redis/text_search/collection.rb
@@ -118,6 +118,19 @@ module Redis::TextSearch
@total_entries = number.to_i
@total_pages = (@total_entries / per_page.to_f).ceil
end
+
+ # returns the current start ordinal of the paginated collection
@nateware
nateware / Perl inline edit
Created December 14, 2009 22:30
Perl inline edit
perl -pi -e 's/CLAD/BKOC/g' test.txt
perl -pi.bak -e 's/CLAD/BKOC/g' test.txt
#!/usr/bin/env ruby
# Results (Mac laptop):
# user system total real
# effigy 1.100000 0.010000 1.110000 ( 1.166467)
# erubis 0.260000 0.000000 0.260000 ( 0.265821)
class Post < Struct.new(:id, :title, :body, :comments)
end
@nateware
nateware / middleware_dummycode.rb
Created February 12, 2010 19:16 — forked from mattetti/middleware_dummycode.rb
draft of Rack request verifier
require 'rubygems'
require 'rack'
class Rack
class PlayCo
class RequestValidator
# ==== Parameters
# app<Rack::Builder>:: The Rack builder which will use this middleware.
# path_opts<Hash>:: Path options used to identify path to validate.
#!/usr/bin/env ruby
require 'rubygems'
require 'redis/objects'
require 'benchmark'
$redis = Redis.new(:host => '127.0.0.1', :port => 6379, :thread_safe => true)
require 'redis/sorted_set'
lb = Redis::SortedSet.new('rank:overall:by_points')
@nateware
nateware / test.rb
Created April 15, 2010 00:37
Sequel vs Friendly benchmark
#!/usr/bin/env ruby
$:.unshift File.expand_path "#{File.dirname(__FILE__)}/../friendly/lib"
require 'mysqlplus'
require 'friendly'
require "rbench"
require 'uuid4r'
# Choose how many times you want to repeat each benchmark.
# Ruby 1.9 compat for FasterCSV (painful)
# http://matthewbass.com/2008/01/05/csv-transmogrifies-into-fastercsv-in-ruby-19/
require 'csv'
if CSV.const_defined? :Reader
require 'faster_csv' # For CSV data files
else
FasterCSV = CSV
end
namespace :db do