<commit_before>require 'cuba'
require 'cuba/render'
require 'json'

Cuba.plugin Cuba::Render

Cuba.define do

  on get do
    on root do
      input = hash = ''
      on param('q') do | hash |
        input = hash
        old = hash[ /=>/ ]
        # hash = hash.to_s.stringify_keys
        # if old
          # hash = Hash[hash.to_s.gsub('{', '').gsub('}', '').split(",").collect{|x|
          #     x.gsub(/:| |\'/,'').gsub('nil', 'null').split("=>")
          # }]
          # p hash
          # hash = hash.stringify_keys
          # p hash
        # end
        json = if hash && old
          JSON.parse(hash.to_s.gsub('=>', ':')).to_json
        else
          hash
        end
        hash.gsub!('\\','')
        res.write render('templates/home.haml', hash: input , json: json)
      end
      res.write render('templates/home.haml', hash: '' , json: '')
    end
  end
end


# class Hash
#   def stringify_keys
#     t = self.dup
#     self.clear
#     t.each_pair{|k, v| self[k.to_s] = v}
#     self
#   end
# end<commit_msg>Support for new hash syntax<commit_after>require 'cuba'
require 'cuba/render'
require 'json'

Cuba.plugin Cuba::Render

Cuba.define do

  on get do
    on root do
      input = hash = ''
      on param('q') do | hash |
        input = hash
        old = hash[ /=>/ ]
        isjson = hash[/:{/]
        unless isjson
          hash = hash.to_s.gsub('{', '').gsub('}', '')
          if old
            hash = Hash[hash.split(",").collect{|x|
                x.gsub(/:| |\'/,'').gsub('nil', 'null').split("=>")
            }]
          else
            hash = Hash[hash.split(",").collect{|x|
                x.gsub('nil', 'null').split(': :')
            }]
          end
          hash = hash.stringify_keys
        end
        if hash
          json = JSON.parse(hash.to_s.gsub('=>', ':').gsub('\\','')).to_json
        end
        res.write render('templates/home.haml', hash: input , json: json)
      end
      res.write render('templates/home.haml', hash: '' , json: '')
    end
  end
end


class Hash
  def stringify_keys
    t = self.dup
    self.clear
    t.each_pair{|k, v|
      self[k.to_s.gsub(/^\"|\"$/, '')] = v.gsub(/^\"|\"$/, '')
    }
    self
  end
end
{'fraction_non_alphanumeric': 0.18684807256235827, 'fraction_numerical': 0.0, 'mean_word_length': 1.6902439024390243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6917068', 'n_tokens_mistral': 775, 'n_tokens_neox': 765, 'n_words': 168}