Skip to content

Instantly share code, notes, and snippets.

@pjhyett
Created May 20, 2009 18:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjhyett/114994 to your computer and use it in GitHub Desktop.
Save pjhyett/114994 to your computer and use it in GitHub Desktop.
Experiment to create a read-only version of GitHub during migrations and what not. Doesn't work because Google throttles hits to their cache to prevent people from doing exactly what this does.
require 'rubygems'
require 'sinatra'
require 'open-uri'
def strip_header(text)
prefix = %{
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="http://github.com/"<div style="width"<!DOCTYPE
}
text.sub(/.+<!DOCTYPE/m, prefix)
end
get '/*' do
response = open("http://www.google.com/search?q=cache:github.com/#{params[:splat].join('/')}").read
@output = strip_header(response)
erb :index
end
use_in_file_templates!
__END__
@@ index
<div style="width:98%; font-size:1em; background:#ffffcc; padding:1em; font-weight:bold; border-bottom:1px solid #ccc;">
<span style="font-size:1.2em">You're viewing a read-only version of GitHub.</span><br />
The content may be slightly out of date as we're reading it from Google's cache until we're able to bring the site back up.
</div>
<%= @output %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment