<commit_before>require 'json'
require 'json/add/rails'

def slug_character
  characters = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
  characters[ rand(characters.size) ]
end

def random_slug
  slug_character + slug_character + slug_character + slug_character
end

def build_item( params = {} )
  params = {
    :type => 'image',
    :public_slug => random_slug
  }.merge(params)
  {
    "href"=>"http://my.cl.ly/items/1234",
    "content_url"=>"http://cl.ly/#{params[:public_slug]}/content",
    "redirect_url" => params[:type] == 'bookmark' ? "http://cloudapp.com" : nil,
    "public_slug" => params[:public_slug],
    "private"=>false,
    "deleted_at"=>nil,
    "url"=>"http://cl.ly/#{params[:public_slug]}",
    "remote_url" => params[:type] != 'bookmark' ? "http://f.cl.ly/items/1d1a7310f29c96/Item_Name.png" : nil,
    "last_viewed"=>nil,
    "icon"=>"http://my.cl.ly/images/item_types/#{params[:type]}.png",
    "item_type" => params[:type]
  }
end

def ok_response
  { :status => ["200", "OK"] }
end

def auth_response
  { :status => ["401", "Unauthorized"] }
end

def not_found_response
  { :status => ["404", "Not Found"] }
end

def json_response
  {:content_type => "application/json; charset=utf-8"}.merge(ok_response)
end

def item_listing_response
  {
    :body => [build_item, build_item, build_item(:type=>'bookmark')].to_json
  }.merge(json_response)
end

def get_item_response
  {
    :body => build_item.to_json
  }.merge(json_response)
end

def new_item_response
  {
    :body => {
      "url" =>"http://f.cl.ly",
      "params" => {
        "success_action_redirect" => "http://my.cl.ly/items/s3",
        "acl" => "public-read",
        "AWSAccessKeyId" => "<KEY>",
        "key" => "items/dcb0aa186du4450478f0/${filename}",
        "signature" => "Cm5S8VMo8fcyi4heVXqRqpYj6sE=",
        "policy" => "<KEY>
      }
    }.to_json
  }.merge(json_response)
end

def new_bookmark_response
  {
    :body => build_item(:type => 'bookmark' ).to_json
  }.merge(json_response)
end<commit_msg>A little bit of code cleanup.<commit_after>require 'json'
require 'json/add/rails'

def slug_character
  characters = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
  characters[ rand(characters.size) ]
end

def random_slug
  slug_character + slug_character + slug_character + slug_character
end

def build_item( params = {} )
  params = {
    :type => 'image',
    :public_slug => random_slug
  }.merge(params)
  {
    "href"          => "http://my.cl.ly/items/1234",
    "content_url"   => "http://cl.ly/#{params[:public_slug]}/content",
    "redirect_url"  => params[:type] == 'bookmark' ? "http://cloudapp.com" : nil,
    "public_slug"   => params[:public_slug],
    "private"       => false,
    "deleted_at"    => nil,
    "url"           => "http://cl.ly/#{params[:public_slug]}",
    "remote_url"    => params[:type] != 'bookmark' ? "http://f.cl.ly/items/1d1a7310f29c96/Item_Name.png" : nil,
    "last_viewed"   => nil,
    "icon"          => "http://my.cl.ly/images/item_types/#{params[:type]}.png",
    "item_type"     => params[:type]
  }
end

def ok_response
  { :status => ["200", "OK"] }
end

def auth_response
  { :status => ["401", "Unauthorized"] }
end

def not_found_response
  { :status => ["404", "Not Found"] }
end

def json_response
  {:content_type => "application/json; charset=utf-8"}.merge(ok_response)
end

def item_listing_response
  {
    :body => [build_item, build_item, build_item(:type=>'bookmark')].to_json
  }.merge(json_response)
end

def get_item_response
  {
    :body => build_item.to_json
  }.merge(json_response)
end

def new_item_response
  {
    :body => {
      "url" =>"http://f.cl.ly",
      "params" => {
        "success_action_redirect" => "http://my.cl.ly/items/s3",
        "acl"                     => "public-read",
        "AWSAccessKeyId"          => "<KEY>",
        "key"                     => "items/dcb0aa186du4450478f0/${filename}",
        "signature"               => "Cm5S8VMo8fcyi4heVXqRqpYj6sE=",
        "policy"                  => "<KEY>
      }
    }.to_json
  }.merge(json_response)
end

def new_bookmark_response
  {
    :body => build_item(:type => 'bookmark' ).to_json
  }.merge(json_response)
end
{'fraction_non_alphanumeric': 0.19064662371748986, 'fraction_numerical': 0.02099737532808399, 'mean_word_length': 3.1341222879684416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 69, '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': '3270637', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1595, 'n_words': 249}