Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sinatra: The Classiest of Prototypes

Sinatra: The Classiest of Prototypes

Design Miami, March 9, 2011

Bryce "BonzoESC" Kerley

January 12, 2012
Tweet

More Decks by Bryce "BonzoESC" Kerley

Other Decks in Programming

Transcript

  1. Saturday, March 12, 2011 Napoleon Bonaparte, Emperor of France about

    two hundred years ago LOOOOOVED metric Meters, GRAMS, Seconds is the metric system today
  2. Saturday, March 12, 2011 He wanted ten hour days, and

    hours divided into decihours, centihours, and millihours
  3. Saturday, March 12, 2011 About a hundred eighty five years

    later, a Swiss company made their own decimal time system, where the Napoleonic millihour was called a “Swatch Internet Beat”
  4. Saturday, March 12, 2011 They made watches with internet beats

    You can see it here, below the actual time that normal people used back then and still use today
  5. Saturday, March 12, 2011 They made watches with internet beats

    You can see it here, below the actual time that normal people used back then and still use today
  6. Saturday, March 12, 2011 Swatch Internet Beats were universal; even

    in Miami, you were using the standard time in Switzerland
  7. Miami Internet Beats • Based on Miami time (including DST)

    • Also compatible with: • New York City • Washington DC • Boston Saturday, March 12, 2011
  8. Miami Internet Beats • Based on Miami time (including DST)

    • Also compatible with: • New York City • Washington DC • Boston • Easy-to-use website Saturday, March 12, 2011
  9. Installing • Mac OS X: 1. gem install sinatra •

    Windows: 1. Install ruby from http://rubyinstaller.org 2. gem install sinatra Saturday, March 12, 2011
  10. Getting Started 1. Save as “hello.rb” 2. ruby -rubygems hello.rb

    3. Visit http://localhost:4567/hi require 'sinatra' get '/hi' do "Hello World!" end Saturday, March 12, 2011
  11. Time Feed require 'sinatra' require 'tzinfo' mt = TZInfo::Timezone.get('America/New_York') get

    '/time' do mt.now.strftime "%D %T" end Saturday, March 12, 2011
  12. Beats Feed get '/beats' do now = mt.now midnight =

    now.beginning_of_day tomorrow = now.end_of_day seconds = now - midnight total_seconds = tomorrow - midnight beats = (seconds / total_seconds) * 1000 beats.to_s end Saturday, March 12, 2011
  13. Quick HAML Review !!! 5 %html %head %title MIAMI %body

    %h1 INTERNET .description :markdown BEATS is the new time standard. <!DOCTYPE html> <html> <head> <title>MIAMI</title> </head> <body> <h1>INTERNET</h1> <div class='description'> <p>BEATS is the new time standard.</p> </div> </body> </html> Saturday, March 12, 2011
  14. HAML in Sinatra get '/' do haml :index end !!!

    5 %html %head %title MIAMI INTERNET BEATS %body %h1 MIAMI INTERNET BEATS .description :markdown MIAMI INTERNET BEATS is the new time standard. views/index.haml Saturday, March 12, 2011
  15. Helpers #beats=current_beats.round helpers do def current_beats now = miami_time.now seconds

    = now - now.beginning_of_day total_seconds = now.end_of_day - now.beginning_of_day (seconds / total_seconds) * 1000 end end Saturday, March 12, 2011
  16. !!! 5 %html %head %title MIAMI INTERNET BEATS %body .rotationPart

    %h1 MIAMI INTERNET BEATS .bars #beats=current_beats.round #beatBar.bar #fractionalBeats=(current_beats - current_beats.floor).round(2) #fractionBar.bar #date #dateBar.bar #stopButton stop .description :markdown MIAMI INTERNET BEATS is the new time standard… Saturday, March 12, 2011
  17. !!! 5 %html %head %title MIAMI INTERNET BEATS %body .rotationPart

    %h1 MIAMI INTERNET BEATS .bars #beats=current_beats.round #beatBar.bar #fractionalBeats=(current_beats - current_beats.floor).round(2) #fractionBar.bar #date #dateBar.bar #stopButton stop .description :markdown MIAMI INTERNET BEATS is the new time standard… Saturday, March 12, 2011
  18. SASS in Sinatra a:link, a:visited :color #f0f :text-decoration none get

    '/miamibeats.css' do sass :miamibeats end views/miamibeats.sass Saturday, March 12, 2011
  19. CSS in Sinatra body a:link, body a:visited { color: fuchsia;

    text-decoration: none; } public/miamibeats.sass Saturday, March 12, 2011
  20. JavaScript in Sinatra document.observe('dom:loaded', function() { var beats; beats =

    new MiamiBeats(); return $('stopButton').on('click', function(ev, el) { beats.halt = 1; return el.hide(); }); }); public/miamibeats.js Saturday, March 12, 2011
  21. Saturday, March 12, 2011 If you’re interested in learning more

    about Ruby on Rails (Sinatra’s big brother,) I’ll be speaking at Hack Miami this Saturday out in Weston.
  22. http://bit.ly/hack-miami-march Saturday, March 12, 2011 If you’re interested in learning

    more about Ruby on Rails (Sinatra’s big brother,) I’ll be speaking at Hack Miami this Saturday out in Weston.