Skip to content

Instantly share code, notes, and snippets.

View arthurnn's full-sized avatar
🟢
CI is passing

Arthur Nogueira Neves arthurnn

🟢
CI is passing
View GitHub Profile
@arthurnn
arthurnn / mongod_shell.js
Last active December 18, 2015 01:49
mongodb ordered sub-doc
use test
db.entities.drop()
db.entities.insert({_id: 1})
db.entities.update({ "_id": 1 }, {"$set": {"foo": "foo"} })
db.entities.update({ "_id": 1 }, {"$set": {"a": "a"} })
db.entities.update({ "_id": 1 }, {"$set": {"c": "c"} })
db.entities.update({ "_id": 1 }, {"$set": {"b": "b"} })
db.entities.find()
require 'benchmark'
class Coffee
def cost
2
end
def origin
"Colombia"
end
# encoding: utf-8
require "spec_helper"
class Person
include Mongoid::Document
has_many :pets
field :name
end
require 'oj'
require 'active_support/all'
require 'benchmark'
null = nil
hash = {
"photo"=> {
"id"=> 4928401,
"user_id"=> 164677,
require "spec_helper"
class Publication
include Mongoid::Document
embeds_many :issues
end
class Issue
include Mongoid::Document
require "spec_helper"
class User
include Mongoid::Document
has_and_belongs_to_many :cars, inverse_of: :users
has_one :favorite_car, class_name: 'Car', inverse_of: :person
before_validation :set_default_favorite_car, on: :create
module IdentityCache
BACKEND_KEY = 'idc:backend:key'
def with_memoization(&block)
Thread.current[IdentityCache::BACKEND_KEY] = MemoizedDecorator.new(IdentityCache.cache_backend)
yield
ensure
Thread.current[IdentityCache::BACKEND_KEY] = nil
end
diff --git a/lib/identity_cache/memcached_adapter.rb b/lib/identity_cache/memcached_adapter.rb
index 9aa9e56..c817dd8 100644
--- a/lib/identity_cache/memcached_adapter.rb
+++ b/lib/identity_cache/memcached_adapter.rb
@@ -17,14 +17,11 @@ module IdentityCache
super(servers, opts.merge(support_cas: true))
end
- %w{delete incr decr append prepend}.each do |meth|
- define_method(meth) do |*args|
class Ship
include Mongoid::Document
has_one :vehicle
end
class Vehicle
include Mongoid::Document
belongs_to :ship
end
irb(main):009:0> s = Ship.new
@arthurnn
arthurnn / cursor.rb
Last active December 24, 2015 02:59
class Cursor
include Enumerable
def each
p "cursor #{Thread.current.object_id}"
yield(1)
yield(2)
end
end