<commit_before>#!/usr/bin/env ruby -rubygems

require 'sinatra'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-migrations'
require 'htmlentities'
require 'newrelic_rpm'

dev_prefix = ENV['RACK_ENV'] == 'development' ? File.expand_path(File.dirname(__FILE__))+'/' : ''
ENV['DATABASE_URL'] ||= "sqlite3://#{dev_prefix}randomtyper.sqlite3"
DataMapper.setup(:default, ENV['DATABASE_URL'])

class Snippet
  include DataMapper::Resource

  property :id,         Serial
  property :body,       Text, :required => true, :length => 1..255
  property :created_at, DateTime
  property :updated_at, DateTime

  def formatted_body
    @@coder ||= HTMLEntities.new
    return @@coder.encode(body, :named)
  end
end

DataMapper.auto_upgrade!

# new
get '/' do
  @snippets = Snippet.all(:order => [:created_at.desc], :limit => 50)
  erb :new
end

# create<commit_msg>allow newlines, but a max of two in a row (e.g. paragraphs)<commit_after>#!/usr/bin/env ruby -rubygems

require 'sinatra'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-migrations'
require 'htmlentities'
require 'newrelic_rpm'

dev_prefix = ENV['RACK_ENV'] == 'development' ? File.expand_path(File.dirname(__FILE__))+'/' : ''
ENV['DATABASE_URL'] ||= "sqlite3://#{dev_prefix}database.sqlite3"
DataMapper.setup(:default, ENV['DATABASE_URL'])

class Snippet
  include DataMapper::Resource

  property :id,         Serial
  property :body,       Text, :required => true, :length => 1..255
  property :created_at, DateTime
  property :updated_at, DateTime

  def formatted_body
    @@coder ||= HTMLEntities.new
    encoded = @@coder.encode(body, :named) # ecscape all special chars
    newline = "\r\n" # inconsistent between systems :(
    encoded.gsub!(/(#{newline}#{newline})+/, newline) # replace >2 newlines in a row with just 1 (allow paragraphs)
    encoded.gsub!(newline, "<br />") # then turn newlines into HTML
    puts encoded.inspect
    return encoded
  end
end

DataMapper.auto_upgrade!

# new
get '/' do
  @snippets = Snippet.all(:order => [:created_at.desc], :limit => 50)
  erb :new
end

# create
{'fraction_non_alphanumeric': 0.14649081488459728, 'fraction_numerical': 0.008478568064060292, 'mean_word_length': 4.488372093023256, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, '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': '3571770', 'n_tokens_mistral': 762, 'n_tokens_neox': 735, 'n_words': 177}