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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Bootstrap 101 Template</title> | |
<!-- Bootstrap --> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> |
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
def foo(x: wtf) | |
end | |
puts "wtf did not get called when the method was defined" | |
foo x: 1 | |
puts "wtf did not get called when we passed a value for x" | |
begin |
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 Foo | |
instance_eval <<-end_eval, __FILE__, __LINE__ | |
def bar | |
"class method" | |
end | |
end_eval | |
class_eval <<-end_eval, __FILE__, __LINE__ | |
def bar | |
"instance method" |
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 'json' | |
run -> (env) { | |
body = JSON.pretty_generate(env) + "\n" | |
puts body | |
[ 200, { 'Content-Type' => 'application/json', | |
'Content-Length' => body.length.to_s }, [body] ] | |
} |
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 "benchmark" | |
test = "hi man" | |
m = test.method(:length) | |
n = 100000 | |
Benchmark.bmbm {|x| | |
x.report("meth") { n.times { test.length } } | |
x.report("call") { n.times { m.call } } | |
x.report("send") { n.times { test.send(:length) } } | |
x.report("eval") { n.times { eval "test.length" } } | |
} |
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
$ cat ~/.irbrc | |
cat: /Users/pbarry/.irbrc: No such file or directory | |
$ rails c | |
Loading development environment (Rails 4.0.0) | |
irb(main):001:0> Subscription.first | |
Subscription Load (2.5ms) SELECT "subscriptions".* FROM "subscriptions" ORDER BY "subscriptions"."id" ASC LIMIT 1 | |
=> nil | |
irb(main):002:0> puts ENV.keys.sort | |
Apple_PubSub_Socket_Render | |
Apple_Ubiquity_Message |
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
<html> | |
<body> | |
<div style="text-decoration: underline; font-weight: bold"> | |
I am underlined | |
<div style="text-decoration: none; font-weight: normal"> | |
I am not | |
</div> | |
</div> | |
</body> | |
</html> |
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
# The inner Hash.new(0) will now be the object that returned | |
# when you try to fetch the value for a key that doesn't exist | |
>> h = Hash.new(Hash.new(0)) | |
=> {} | |
# When you do this, you are mutating the object that is the default value | |
# of the Hash and not changing the Hash itself | |
>> h[:foo][10] += 1 | |
=> 1 |
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 Query | |
def initialize | |
@hash = {} | |
end | |
def method_missing(name, *args) | |
value = args.length > 0 ? args.first : true | |
@hash.merge!(name => value) | |
self | |
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
# Why do I have to have two levels of blocks? | |
FactoryGirl.define do | |
factory :user do | |
name "test" | |
end | |
end | |
# Why can't I just do something like this? | |
FactoryGirl.factory(:user) do | |
name "test" |