Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2012 02:40
What would you like to do?
Example files implementing the log-driven slideshow described in "Spend time with your site" post (
require 'rubygems'
require 'sinatra'
require 'json'
get '/latest' do
# This is where the [ugly] magic happens. Grep an appropriate path from the _end_ of the incoming log file,
# excluding office IP range and paying special attention to escaping...
line = `tac /var/log/heroku.log | grep ".*GET [^\?]*/home\/[^/ \\"]*" | grep -v "controls\\|pending\\|99\\.99\\." -m 1`
if match = line.match(/\/home\/([a-z0-9\-]*)/i)
return match[1].to_json
return nil
require 'rubygems'
require 'sinatra'
require File.dirname(__FILE__) + "/app.rb"
run Sinatra::Application
<script src=""></script>
<script type="text/javascript">
$(function() {
window.lastPath = ''; // useful to avoid reloading identical page
var loadNext = function() {
$.getJSON('/latest', function(path) {
if (path && !window.lastPath.match(path)) {
window.frames[0].location.href = "" + path;
window.lastPath = path;
setInterval(function() {
}, 20000);
<body style="margin:0;overflow:hidden;">
<iframe height="100%" width="100%"></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment