Skip to content

Instantly share code, notes, and snippets.

View djsun's full-sized avatar

David James djsun

View GitHub Profile
@djsun
djsun / gist:289815
Created January 29, 2010 15:37
sorted_yaml_hash.rb
# Based on http://snippets.dzone.com/posts/show/5811
#
# Differences over snippet above:
# * will sort hashes with keys that are symbols
# * different usage style (see below)
require 'yaml'
module SortedYamlHash
class Person
attr_accessor :name
def initialize(name)
@name = name
end
end
people = {}
person_1 = Person.new("Saul")
person_2 = Person.new("John")
require 'rubygems'
require 'datacatalog'
DataCatalog.base_uri = "http://localhost:3000"
DataCatalog.api_key = "CHANGE_THIS"
# r = DataCatalog::About.get
# puts r
r = DataCatalog::User.all
module Utility
# ActiveSupport 2.3.5 adds @_rails_html_safe aggressively.
# This method removes it so you can output clean YAML.
def self.plain_string(s)
if s.instance_variable_defined?(:@_rails_html_safe)
s.send(:remove_instance_variable, :@_rails_html_safe)
end
s
end
require 'rubygems'
require 'feedzirra'
# gem install feedzirra
url = "http://sunlightlabs.com/blog/feeds/tag/datacatalog/"
feed = Feedzirra::Feed.fetch_and_parse(url)
puts feed.title
puts feed.url
puts feed.feed_url
module Helper
def self.parent(scope)
chain = scope.name.split("::")[0 ... -1]
chain.reduce(Object) { |m, o| m.const_get(o) }
end
end
module Family
def sibling(string)
Helper.parent(self).const_get(string)
require 'test_helper'
require 'models'
class BelongsToProxyTest < Test::Unit::TestCase
def setup
clear_all_collections
end
should "default to nil" do
status = Status.new
class Comment < ActiveRecord::Base
belongs_to :post
end
should "set updated_at on document update but leave created_at alone" do
doc = @document.create(:first_name => 'John', :age => 27)
old_created_at = doc.created_at
old_updated_at = doc.updated_at
sleep 1
@document.update(doc._id, { :first_name => 'Johnny' })
from_db = @document.find(doc.id)
from_db.created_at.to_i.should == old_created_at.to_i
from_db.updated_at.to_i.should_not == old_updated_at.to_i
end
In response to:
http://github.com/jnunemaker/mongomapper/issues/#issue/46
My setup:
* MongoDB nightly OSX 32 bit build.
* mongomapper
* pulled from git://github.com/jnunemaker/mongomapper.git
* Gems (installed via 'sudo gem install ...')
* mongodb-mongo (0.10.1)
* mongodb-mongo_ext (0.4.1)