Skip to content

Instantly share code, notes, and snippets.

View alto's full-sized avatar

Thorsten Böttger alto

View GitHub Profile

Keybase proof

I hereby claim:

  • I am alto on github.
  • I am alto (https://keybase.io/alto) on keybase.
  • I have a public key whose fingerprint is C0DC 3131 6C29 B56A FD32 9F87 C8BE F36F FC44 C1BB

To claim this, I am signing this object:

require 'rubygems'
require 'yaml'
# A demonstration of YAML anchors, references and handling of nested values
# For more info, see:
# http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/
stooges = YAML::load( File.read('stooges.yml') )
# => {
# "default" => {
# your_object.rb
class YourObject < ActiveRecord::Base
def your_method
self.your_association << TestObject.new
end
end
# your_object_spec.rb
it "should test your_method" do
lambda { your_object.your_method }.should change(your_object.your_association, :size) # => no change, test fails....
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2009 Aslak Hellesøy
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
class MyClass
class << self
def class; class << self; self; end; end
end
end
@alto
alto / place_matches
Created March 30, 2011 12:00
Analyse me...
Started GET "/place_matches" for 77.6.249.160 at Wed Mar 30 11:07:48 +0000 2011
Processing by PlaceMatchesController#index as HTML
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 8 AND (users.deleted_at IS NULL) LIMIT 1
SQL (0.3ms) SELECT COUNT(*) FROM `questions`
SQL (12.7ms) SELECT COUNT(*) FROM `questions` INNER JOIN `answerings` ON `questions`.id = `answerings`.question_id WHERE ((`answerings`.user_facade_id = 8) AND (`answerings`.user_facade_type = 'User'))
TagAffinity Load (8.0ms) SELECT `tag_affinities`.* FROM `tag_affinities` WHERE (`tag_affinities`.affinityable_id = 8 AND `tag_affinities`.affinityable_type = 'User')
SQL (0.3ms) BEGIN
SQL (0.3ms) COMMIT
Answering Load (14.8ms) SELECT `answerings`.* FROM `answerings` WHERE (`answerings`.user_facade_id = 8 AND `answerings`.user_facade_type = 'User')
Answer Load (0.5ms) SELECT `answers`.* FROM `answers` WHERE `answers`.`id` = 12 LIMIT 1
class A
class << self
def class
class << self
self
end
end
end
end
object @place => :place
# this is a hack, but otherwise the partial mechanism doesn't work yet [thorsten, 2011-10-07]
@place = @_data.is_a?(Hash) ? @_data.keys.first : @_data
attributes :name, :city, :street, :slug, :zipcode, :phone, :number_of_beds, :number_of_bedrooms,
:currency, :lat, :lng, :scouts_approved_at, :district, :number_of_bathrooms, :cancellation_rules,
:charge_per_extra_person, :minimum_nights, :maximum_nights, :bed_type,
:size, :manual, :house_rules, :pets_around, :emergency_phone, :bathroom_type, :cleaning_fee,
:charge_per_extra_person_limit, :favorites_count, :state, :amenities_list
@alto
alto / gist:1322663
Created October 28, 2011 16:18
API DSL
# places/index.api
@places.each do |place|
template('places/show', :place => place) # user shall be available as @user in the template
end
# places/show.api
object(@place) do
:name, # plain attribute
:address => address_for(@user), # helper used
:location => { # hash