Skip to content

Instantly share code, notes, and snippets.

context "when adding a nested doc and updating existing doc's attributes" do
let(:person) { Person.new }
before do
person.addresses << Address.new({ "street" => "Folsom", "city" => "San Francisco" })
person.save!
@attributes = {
"0" => { "street" => "New Street" },
"1" => { "street" => "5th Street", "city" => "Boston" },
context "when deleting 2 nested docs" do
let(:person) { Person.new }
before do
person.favorites.build(:title => "Johnny")
person.favorites.build(:title => "Ice cream")
person.favorites.build(:title => "Coke")
person.favorites.build(:title => "Sugar")
person.save!
# Switch to Ruby 1.8.7
rvm use 1.8.7
# Print out the ruby version
ruby -v
# But the output of this is:
#
# $ ./tryrvm
# <i> Now using ruby 1.8.7 p249 </i>
#!/usr/bin/env ruby
# encoding: utf-8
require 'net/scp'
require 'net/ssh'
app = 'his'
lang = 'en'
host = 'zoidberg.blueberry.cz'
# encoding: utf-8
require 'mongoid_typecast_attributes'
module Mongoid
module Document
include MongoidTypecastAttributes
end
end
@jzajpt
jzajpt / observe_status.js
Created May 17, 2011 06:57
Mixin for status observing - on records, record arrays etc.
// ==========================================================================
// Project: Billapp.ObserveStatus
// Copyright: ©2011 Blueberry.cz Apps s.r.o.
// ==========================================================================
/*globals Billapp */
/** @namespace
@version 0.1
*/
@jzajpt
jzajpt / accommodation.rb
Created August 5, 2011 09:23
Mongoid bug
class Accommodation
include Mongoid::Document
references_many :reservations
end
@jzajpt
jzajpt / google_translate.rb
Created September 2, 2011 08:48
Google Translate Ruby API
# encoding: utf-8
class GoogleTranslate
BASE_URL = 'https://www.googleapis.com/language/translate/v2'
URL_OPTIONS = [ :key, :target, :source, :q, :format ]
include HTTParty
format :json
@jzajpt
jzajpt / object_id_encode.js
Created February 2, 2012 20:00
Encode & decode BSON::ObjectId into more friendly format (base64-like)
class ObjectIdEncoder
attr_accessor :id
def initialize(id)
@id = id.to_a
raise "invalid ID!" unless @id.size == 12
end
def encode
result = []
@jzajpt
jzajpt / gist:1826036
Created February 14, 2012 11:33 — forked from zachy/gist:1825836
require 'imgkit'
class InvalidInputFileError < Exception; end
class Converter
def initialize(input, output = nil)
raise InvalidInputFileError unless html_file?(input)
@input = input
if @output
@ouput = output