Skip to content
Create a gist now

Instantly share code, notes, and snippets.

anonymous /Gemfile secret

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
A simple sinatra app which serves a /num_calls route returning the number of calls in queue, and some CoffeeScript which polls for this information and updates a span with the result every 5 seconds.
jQuery ->
updateNumCalls() # You should call this function when the user navigates
# to the queue page.
updateNumCalls = ->
# Get the number of calls.
$.getJSON('/num_calls').then (result) ->
$num_calls = $('#num_calls') # Fetch the element that contains the number.
if $num_calls.length # Make sure it still exists on the page.
$num_calls.html(result.num_calls) # And if so, update the element,
setTimeout updateNumCalls, 5000 # and queue up another query in 5 secs.
require 'sinatra/base'
require 'json'
class CallCentre < Sinatra::Base
set :views, settings.root
get '/' do
erb :index
get '/num_calls' do
content_type :json
{ "num_calls" => rand(1..100) }.to_json
get '/call_centre.js' do
coffee :call_centre
gem 'sinatra'
gem 'coffee-script'
<!DOCTYPE html>
<html lang="en">
There are currently
<span id="num_calls">(Loading...)</span>
calls in the queue.
<script src=""></script>
<script src="/call_centre.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.