Example files implementing the log-driven slideshow described in "Spend time with your site" post (http://artsy.github.com/blog/2012/07/05/spend-time-with-your-site/).
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></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 = "http://example.com" + path;
window.lastPath = path;
}
});
};
loadNext();
setInterval(function() {
loadNext();
}, 20000);
});
</script>
</head>
<body style="margin:0;overflow:hidden;">
<iframe height="100%" width="100%"></iframe>
</body>
</html>
require 'rubygems'
require 'sinatra'
require File.dirname(__FILE__) + "/app.rb"
run Sinatra::Application
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
end
return nil
end