<commit_before>require 'rubygems'
require 'sinatra'
require 'net/http'
require 'json'

configure do
  require 'memcached'
  CACHE = Memcached.new
end

helpers do
  def avatar_valid?(url)
    uri = URI.parse(url)
    http = Net::HTTP.new(uri.host)
    http.request_head(uri.path).code == "200"
  end

  def grab_avatar_for(user)
    user_info = Net::HTTP.get(URI.parse("http://twitter.com/users/#{user}.json"))
    avatar_url = JSON.parse(user_info)["profile_image_url"]
    avatar_url ||= "http://static.twitter.com/images/default_profile_bigger.png"
  end
end

get '/status' do
  status = Net::HTTP.get(URI.parse("http://api.twitter.com/1/account/rate_limit_status.json"))
  "Remaining hits today: #{JSON.parse(status)['remaining_hits']}"
end

get '/:user' do
  user = params[:user]
  begin
    avatar_url = CACHE.get(user)
    raise Memcached::NotFound unless avatar_valid?(avatar_url)
  rescue Memcached::NotFound
    avatar_url = grab_avatar_for(user)
    CACHE.set(user, avatar_url)
  end
  redirect avatar_url
end
<commit_msg>Don't route to favicon.ico<commit_after>require 'rubygems'
require 'sinatra'
require 'net/http'
require 'json'

configure do
  require 'memcached'
  CACHE = Memcached.new
end

helpers do
  def avatar_valid?(url)
    uri = URI.parse(url)
    http = Net::HTTP.new(uri.host)
    http.request_head(uri.path).code == "200"
  end

  def grab_avatar_for(user)
    user_info = Net::HTTP.get(URI.parse("http://twitter.com/users/#{user}.json"))
    avatar_url = JSON.parse(user_info)["profile_image_url"]
    avatar_url ||= "http://static.twitter.com/images/default_profile_bigger.png"
  end
end

get '/status' do
  status = Net::HTTP.get(URI.parse("http://api.twitter.com/1/account/rate_limit_status.json"))
  "Remaining hits today: #{JSON.parse(status)['remaining_hits']}"
end

get '/favicon.ico' do
  status 404
end

get '/:user' do
  user = params[:user]
  begin
    avatar_url = CACHE.get(user)
    raise Memcached::NotFound unless avatar_valid?(avatar_url)
  rescue Memcached::NotFound
    avatar_url = grab_avatar_for(user)
    CACHE.set(user, avatar_url)
  end
  redirect avatar_url
end

{'fraction_non_alphanumeric': 0.13982050070854984, 'fraction_numerical': 0.0051960321209258385, 'mean_word_length': 4.375634517766497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677423', 'n_tokens_mistral': 785, 'n_tokens_neox': 769, 'n_words': 145}