This file contains 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 Ruby... | |
# | |
# 1) Sum up 1 to 100 | |
# sum = (1..100).inject(0){|cummulative,n| cummulative+n} | |
# puts sum | |
# | |
# 2) Using TestUnit, test #1 | |
# Please see this Gist: git://gist.github.com/1120032.git | |
# | |
# 3) What's the difference between including a module & extending a module? |
This file contains 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
short_enum = (1..26).to_enum | |
long_enum = ('a'..'z').to_enum | |
loop do | |
print "letter #{short_enum.next} is #{long_enum.next}, " | |
end |
This file contains 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
short_enum = (1..26).to_enum | |
long_enum = ('a'..'z').to_enum | |
loop do | |
puts "letter #{short_enum.next} is #{long_enum.next}" | |
end |
This file contains 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> | |
<head> | |
<style>p { background:yellow; margin:6px 0; } p.off { background: black; }</style> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
</head> | |
<body> | |
<p>Hello!</p> | |
Good to see you. | |
<p>Want to try some links?</p><br><br> |
This file contains 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
sum = (1..100).inject(0){|cummulative,n| cummulative+n} | |
puts sum |
This file contains 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/unit' | |
class MathTester < Test::Unit::TestCase | |
def test_addition | |
assert_equal( 3, 1+2 ) | |
assert_equal( 5, 2+3 ) | |
end | |
def test_subtraction |
This file contains 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
(function ($) { | |
var script, css, html, offset, options; | |
script = $('script[src$="network.js"]'); | |
// Set options. | |
options = { | |
style: 'dark' | |
}; | |
if (script.data('style')) { |
This file contains 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
* Blocks are simply Procs that can not be saved. | |
* Blocks should be used as a one-time solution. If 2 or more closures are being passed, use a Proc. | |
Use case examples: | |
1.) Block: method is breaking an object down into smaller pieces, and I want to let my users interact with these pieces. | |
2.) Block: I want to run multiple expressions atomically, eg: a database migration. | |
3.) Proc: I want to reuse a block of code multiple times. |
This file contains 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
get "/user/profile" do | |
haml :profile | |
end | |
get "/user/profile/change" do | |
haml :change_profile | |
end | |
post "/user/profile" do | |
# unless @user.create(:nickname => params[:nickname], |
This file contains 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 'ruby-debug'; debugger; | |
gem 'rest-client', '=1.6.1' | |
%w(./config haml sinatra digest/md5 rack rack-flash json rest-client ./models).each { |lib| require lib} | |
set :sessions, true | |
set :show_exceptions, true | |
set :environment, :development | |
use Rack::Flash | |
get "/" do |