This file contains hidden or 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
| # 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 |
This file contains hidden or 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 Person | |
| attr_accessor :name | |
| def initialize(name) | |
| @name = name | |
| end | |
| end | |
| people = {} | |
| person_1 = Person.new("Saul") | |
| person_2 = Person.new("John") |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| require 'test_helper' | |
| require 'models' | |
| class BelongsToProxyTest < Test::Unit::TestCase | |
| def setup | |
| clear_all_collections | |
| end | |
| should "default to nil" do | |
| status = Status.new |
This file contains hidden or 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 Comment < ActiveRecord::Base | |
| belongs_to :post | |
| end |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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) |