<commit_before>require 'rack/contrib/jsonp'
require 'redis'

use Rack::JSONP

before do
  content_type :json
end

SERVICES = []

def services(*args)
  SERVICES.concat args
  args.each { |arg| require "./services/#{arg}" }
end

def subdomain(host)
  condition do
    host == request.env['HTTP_HOST'].split('.').first
  end
end

def cache
  host = request.host
  path = request.path_info
  key = [:v1, :request, host, path, :json].join(":")
  Cache.fetch(key) { yield }
end

$redis = Redis.connect url: ENV["REDIS_URL"]

class CachedValue
  attr_reader :value, :expiry

  def initialize(value = nil, expiry = Time.now.utc)
    @value = value
    @expiry = case expiry
              when Time then expiry
              when String then Time.parse(expiry)
              end
    @expiry ||= Time.now.utc
  end
<commit_msg>Let's support open redis's env var<commit_after>require 'rack/contrib/jsonp'
require 'redis'

use Rack::JSONP

before do
  content_type :json
end

SERVICES = []

def services(*args)
  SERVICES.concat args
  args.each { |arg| require "./services/#{arg}" }
end

def subdomain(host)
  condition do
    host == request.env['HTTP_HOST'].split('.').first
  end
end

def cache
  host = request.host
  path = request.path_info
  key = [:v1, :request, host, path, :json].join(":")
  Cache.fetch(key) { yield }
end

$redis = Redis.connect url: ENV["REDIS_URL"] || ENV["OPENREDIS_URL"]

class CachedValue
  attr_reader :value, :expiry

  def initialize(value = nil, expiry = Time.now.utc)
    @value = value
    @expiry = case expiry
              when Time then expiry
              when String then Time.parse(expiry)
              end
    @expiry ||= Time.now.utc
  end

{'fraction_non_alphanumeric': 0.12864800476474092, 'fraction_numerical': 0.0011911852293031567, 'mean_word_length': 3.0579710144927534, 'pattern_counts': {'":': 2, '<': 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': '6555210', 'n_tokens_mistral': 609, 'n_tokens_neox': 584, 'n_words': 156}