Skip to content

Instantly share code, notes, and snippets.

@smtalim
smtalim / sinatra01.rb
Created September 19, 2011 04:36
Sinatra app
# sinatra01.rb
require 'sinatra'
get '/' do
"Welcome from RubyLearning!"
end
@smtalim
smtalim / sinatragplus.rb
Created September 19, 2011 11:18
Sinatra Google+ app
# sinatragplus.rb
require 'sinatra'
get '/' do
"Coming soon..."
end
@smtalim
smtalim / index.erb
Created September 19, 2011 11:31
Sinatra erb file
get '/' do
erb :index
end
@smtalim
smtalim / layout.erb
Created September 20, 2011 00:50
Sinatra Layout sample
<html>
<head>..</head>
<body>
<%= yield %>
</body>
</html>
@smtalim
smtalim / 404.erb
Created September 20, 2011 05:01
Sinatra app's layout.erb, style.css
<div>
<h1>A Sinatra app to access Google+</h1>
<p>I'm sorry but the "The Sinatra app to access Google+" Web Service is not accessible from the folder you typed in.</p>
<p>The correct URL is: <a href="http://sinatragplus.heroku.com/">http://sinatragplus.heroku.com/</a></p>
<p><a href="/">Back</a></p>
</div>
<div id="footer">
<p><b>A Fun Sinatra App for Google+ by RubyLearning 20 Sept. 2011</b>.</p>
</div>
@smtalim
smtalim / style.css
Created September 20, 2011 05:06
Sinatra app stylesheet
body
{
line-height: 1.6em;
}
h1 {
color: #2A1959;
border-bottom: 2px solid #2A1959;
}
@smtalim
smtalim / grade_service.rb
Created September 22, 2011 01:15
JRuby GradeService example
class GradeService
def initialize(url)
@url = url
end
def submit(answer)
# do web request here
end
def status
@smtalim
smtalim / display.rb
Created September 22, 2011 06:01
Git Branching examples
class Display < MotorCycle
def dispAttr
'Color of MotorCycle is ' + @color
'Make of MotorCycle is ' + @make
end
end
@smtalim
smtalim / string_encode.rb
Created September 26, 2011 01:35
Ruby code for encoding
# encoding: utf-8
# λ is the Greek character Lambda here
puts "λ".length # => 1
puts "λ".bytesize # => 2
puts "λ".encoding # => UTF-8
@smtalim
smtalim / Blah.java
Created September 27, 2011 05:35
Sample Java Source file
package java.blah;
import java.blah.blahdy.BlahBlah;
/**
* Class description goes here.
*
* @version 1.10 27 Sept 2011
* @author Firstname Lastname
*/