Created
July 9, 2012 02:40
-
-
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/).
This file contains 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 characters
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 |
This file contains 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 characters
require 'rubygems' | |
require 'sinatra' | |
require File.dirname(__FILE__) + "/app.rb" | |
run Sinatra::Application |
This file contains 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 characters
<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