Skip to content

Instantly share code, notes, and snippets.

View tamouse's full-sized avatar
🏠
Retired from Work

Tamara Temple tamouse

🏠
Retired from Work
View GitHub Profile
@tamouse
tamouse / compare.rb
Created March 21, 2014 20:28
Methods a, b, and c return truthy or falsy. Which of these is better approach?
method_a(data) && method_b(data) && method_c(data)
# or
if method_a(data)
if method_b(data)
method_c(data
end
end
@tamouse
tamouse / notes.md
Last active March 25, 2017 05:40
A few notes on tonite's RailsMN presentation
@tamouse
tamouse / Guardfile
Last active August 29, 2015 13:57
Using thor to generate a new ruby project.
guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end
guard :rspec, :cmd => "bundle exec rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
@tamouse
tamouse / hash_walk.rb
Created March 2, 2014 16:00
walking a complex data structure (deep hash)
# An attempt to build a method that will deep walk a hash in order to
# convert it to something else, possibly an ostruct
class Hash
def walk(&b)
each do |k,v|
case v
when Hash
@tamouse
tamouse / README.md
Created February 25, 2014 09:13
demo assignment methods

WARNING Setter methods don’t return what you might think. When you use the syntactic sugar that lets you make calls to = methods look like assignments, Ruby takes the assignment semantics seriously. Assignments (like x=1) evaluate to whatever’s on their right-hand side. Methods usually return the value of the last expression evaluated during execution. But = method calls behave like assignments: the value of the expression ticket.price = 63.00 is 63.00, even if the ticket= method returns the string “Ha ha!” The idea is to keep the semantics consistent. Under the hood, it’s a method call; but it looks like an assignment and behaves like an assignment with respect to its value as an expression.

@tamouse
tamouse / pyramid.out
Last active August 29, 2015 13:56
Pyramid scheme
[6] pry(main)> load 'pyramid.rb'
=> true
[7] pry(main)> pyr1 = Pyramid.new(5)
=> #<Pyramid:0x007fb08e74a9a0
@pyramid=[[1], [2, 1], [3, 2, 1], [4, 3, 2, 1], [5, 4, 3, 2, 1]],
@size=5>
[8] pry(main)> print pyr1
1
2 1
3 2 1
@tamouse
tamouse / log
Created February 23, 2014 15:54
parameters from submitting a recipe to https://github.com/tamouse/test_nested_attributes
Processing by RecipesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NPBI20K5lMJHxZGw8Y2FtDLy7KvRr4We2bFHYc3JWlE=", "recipe"=>{"name"=>"omelette", "ingredients_attributes"=>{"0"=>{"quantity"=>"2", "measure"=>"", "name"=>"eggs", "_destroy"=>"false"}, "1"=>{"quantity"=>"1", "measure"=>"oz", "name"=>"shredded cheese", "_destroy"=>"false"}, "2"=>{"quantity"=>"", "measure"=>"", "name"=>"salt & pepper to taste", "_destroy"=>"false"}, "1393170715291"=>{"quantity"=>"1", "measure"=>"tblsp", "name"=>"butter", "_destroy"=>"false"}}, "directions_attributes"=>{"0"=>{"step"=>"warm up pan with butter", "_destroy"=>"false"}, "1"=>{"step"=>"crack egg into bowl, whisk thoroughly", "_destroy"=>"false"}, "2"=>{"step"=>"when pan is hot, pour in egg", "_destroy"=>"false"}, "1393170756671"=>{"step"=>"let egg cook until bottom is settled. sprinkle in cheese. fold and remove from heat", "_destroy"=>"false"}, "1393170794649"=>{"step"=>"let omelette set for 1 minute", "_destroy"=>"false"}}, "notes"=>""}, "c
@tamouse
tamouse / SubscriptionForm.rb
Created February 21, 2014 00:09
Problem with reform from_hash method missing for a nested model.
class SubscriptionForm < Reform::Form
property :extra_user_information do
property :first_name, :on => :extra_user_information
property :last_name, :on => :extra_user_information
property :email, :on => :extra_user_information
property :phone, :on => :extra_user_information
property :fax, :on => :extra_user_information
property :website, :on => :extra_user_information
property :company, :on => :extra_user_information
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
Python 2.7.5
javac 1.6.0_65
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
@tamouse
tamouse / Property.rb
Last active August 29, 2015 13:55 — forked from anonymous/Property.rb
class Property < ActiveRecord::Base
belongs_to :detail
end