-
-
Save rkh/1476182 to your computer and use it in GitHub Desktop.
Revisions
-
rkh revised this gist
Dec 14, 2011 . 2 changed files with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,10 @@ end get '/bottles' do content_type "text/event-stream" stream do |out| 1000.times do |i| out << "data: #{i} bottle(s) on a wall...\n\n" sleep 0.5 end 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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,8 @@ <h1>Welcome to this Sinatra Streaming example!</h1> </pre> <script> $("#bottles-button").click(function() { var src = new EventSource('/bottles'); src.onmessage = function(e) { $('#bottles-output').append("\n" + e.data) }; }); </script> </body> -
blambeau revised this gist
Dec 14, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ A server-side service outputs a long response using Sinatra's streaming API. How can the javascript client process this long response as a stream and refresh a pre in the HTML page until the whole response has been received? To run it: -
blambeau revised this gist
Dec 14, 2011 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ # jQuery + Sinatra + Streaming A server-side service outputs a long response using Sinatra's streaming API. How can the javascript client process this long response as a stream and refresh a <code><pre></pre></code> in the HTML page? To run it: bundle install -
blambeau revised this gist
Dec 14, 2011 . 1 changed file with 0 additions and 24 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ -
blambeau revised this gist
Dec 14, 2011 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # jQuery + Sinatra + Streaming To run it: bundle install bundle exec ruby app.rb Then, try to implement the requested feature. See index.html -
blambeau revised this gist
Dec 14, 2011 . 4 changed files with 63 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,3 @@ source "http://rubygems.org/" gem "sinatra", "~> 1.3.0" gem "thin" 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ GEM remote: http://rubygems.org/ specs: daemons (1.1.4) eventmachine (0.12.10) rack (1.3.5) rack-protection (1.1.4) rack sinatra (1.3.1) rack (~> 1.3, >= 1.3.4) rack-protection (~> 1.1, >= 1.1.2) tilt (~> 1.3, >= 1.3.3) thin (1.3.1) daemons (>= 1.0.9) eventmachine (>= 0.12.6) rack (>= 1.0.0) tilt (1.3.3) PLATFORMS ruby DEPENDENCIES sinatra (~> 1.3.0) thin 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ require 'sinatra' set :server, :thin get '/' do send_file "index.html" end get '/bottles' do stream do |out| 1000.times do |i| out << "#{i} bottle(s) on a wall...\n" sleep 0.5 end end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <!DOCTYPE html> <html lang="fr"> <head> <title>Sinatra streaming example</title> <meta charset="utf-8" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <body> <h1>Welcome to this Sinatra Streaming example!</h1> <input id="bottles-button" type="button" value="Bottles!"/> <pre id="bottles-output"> </pre> <script> $("#bottles-button").click(function() { // please code the streaming functionnality here }); </script> </body> </html> -
blambeau created this gist
Dec 14, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ source "http://rubygems.org/" gem "sinatra", "~> 1.3.0" gem "thin"