Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
Created July 9, 2012 02:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joeyAghion/3073907 to your computer and use it in GitHub Desktop.
Save joeyAghion/3073907 to your computer and use it in GitHub Desktop.
Example files implementing the log-driven slideshow described in "Spend time with your site" post (http://artsy.github.io/blog/2012/07/05/spend-time-with-your-site/).
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
require 'rubygems'
require 'sinatra'
require File.dirname(__FILE__) + "/app.rb"
run Sinatra::Application
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment