This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#jruby hacks | |
jps -ml #show java processes running | |
jstack <pid> #get a jvm stack info | |
jruby -J-Djruby.reify.classes=true # a flag that tell jruby to compile ruby classes to real (matching) java classes | |
jvisualvm #great profiling tool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you set has_and_belongs_to_many on one side only, then you need to | |
set :inverse_of to nil. For example: | |
class A | |
include Mongoid::Document | |
has_and_belongs_to_many :bs, :inverse_of => nil | |
end | |
class B | |
include Mongoid::Document | |
end | |
That should work with no trouble. Since you do not have the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def character_occurance | |
result = {} | |
each_char do |character| | |
result[character] = 0 if result[character] == nil | |
result[character] += 1 | |
end | |
result | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def html_safe? | |
true | |
end | |
end | |
class String | |
def html_safe? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What is the best way to model user/follower (twitter style) relationships with mongo? Most prominent solution is to embed an array of followers ids in every user object. I'm an idealist, and believe that if we are modeling twitter, we eventually will run into a situation when a user has millions of followers which will blow. The relational many_to_many is not easy to model with mongo, mongo_id tries to offer some implementation of basic associations, but the many_no_many, or has_many through is not there yet and I doubt it ever will be. | |
My solution is a compromise between relational normalization and "embed everything in one document". | |
class User | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
# user will have many followerships, each will embedd a follower user, | |
# the user_id is stored on the followership object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm install 1.9.2 | |
rvm use 1.9.2 | |
gem list | |
gem install rails | |
gem list | |
rails new blog | |
cd blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveResource::Connection | |
# Creates new Net::HTTP instance for communication with | |
# remote service and resources. | |
def http | |
http = Net::HTTP.new(@site.host, @site.port) | |
http.use_ssl = @site.is_a?(URI::HTTPS) | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl | |
http.read_timeout = @timeout if @timeout | |
#Here's the addition that allows you to see the output | |
http.set_debug_output $stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample data | |
{ "_id" : ObjectId("4caf19200d282159bf000001"), "date" : "2010-10-06", "seq" : "00:00:00,000", "method" : "getUserByScbeId", "duration" : 3 } | |
{ "_id" : ObjectId("4caf19200d282159bf000002"), "date" : "2010-10-06", "seq" : "00:00:00,116", "method" : "createTicket", "duration" : 116 } | |
{ "_id" : ObjectId("4caf19200d282159bf000003"), "date" : "2010-10-06", "seq" : "00:00:00,131", "method" : "getCollectionMetadata", "duration" : 11 } | |
{ "_id" : ObjectId("4caf19200d282159bf000004"), "date" : "2010-10-06", "seq" : "00:00:00,137", "method" : "getParticipation", "duration" : 6 } | |
{ "_id" : ObjectId("4caf19200d282159bf000005"), "date" : "2010-10-06", "seq" : "00:00:00,139", "method" : "updateSocialObjectModified", "duration" : 371 } | |
{ "_id" : ObjectId("4caf19200d282159bf000006"), "date" : "2010-10-06", "seq" : "00:00:00,143", "method" : "getUserByScbeId", "duration" : 4 } | |