<commit_before># encoding: utf-8
module Thumbnails
  extend ActiveSupport::Concern

  included do
    serialize :thumbnail_sizes, Hash
    dragonfly_accessor :photo
    before_validation :reset_thumbnails
  end

  # User w_x_h = 400x250# or similar
  #
  def thumb(w_x_h)
    if thumbnail_sizes[w_x_h]
      ret = OpenStruct.new(thumbnail_sizes[w_x_h])
      ret.url = Dragonfly.app.remote_url_for(ret.uid)
      ret
    else
      GenerateThumbnailJob.perform_later(self, w_x_h)
      sizes = w_x_h.split('x')
      OpenStruct.new(
        uid: nil,
        signature: nil,
        url: "http://dummyimage.com/#{w_x_h}/FFF/000.png&text=Generating…",
        width: sizes[0].to_i,
        height: sizes[1].to_i
      )
    end
  end

  def landscape?
    photo.present? && photo.width >= photo.height
  end

  private

  def reset_thumbnails
    self.thumbnail_sizes = {} if photo_uid_changed?
  end

  def compute_sizes(size)
    thumbnail = photo.thumb(size, format: :jpg).encode('jpg', '-quality 85')
    {
      uid: thumbnail.store,
      signature: thumbnail.signature,
      url: thumbnail.url,
      width: thumbnail.width,
      height: thumbnail.height
    }
  end
end
<commit_msg>jpg better quality<commit_after># encoding: utf-8
module Thumbnails
  extend ActiveSupport::Concern

  included do
    serialize :thumbnail_sizes, Hash
    dragonfly_accessor :photo
    before_validation :reset_thumbnails
  end

  # User w_x_h = 400x250# or similar
  #
  def thumb(w_x_h)
    if thumbnail_sizes[w_x_h]
      ret = OpenStruct.new(thumbnail_sizes[w_x_h])
      ret.url = Dragonfly.app.remote_url_for(ret.uid)
      ret
    else
      GenerateThumbnailJob.perform_later(self, w_x_h)
      sizes = w_x_h.split('x')
      OpenStruct.new(
        uid: nil,
        signature: nil,
        url: "http://dummyimage.com/#{w_x_h}/FFF/000.png&text=Generating…",
        width: sizes[0].to_i,
        height: sizes[1].to_i
      )
    end
  end

  def landscape?
    photo.present? && photo.width >= photo.height
  end

  private

  def reset_thumbnails
    self.thumbnail_sizes = {} if photo_uid_changed?
  end

  def compute_sizes(size)
    thumbnail = photo.thumb(size, format: :jpg).encode('jpg', '-quality 90')
    {
      uid: thumbnail.store,
      signature: thumbnail.signature,
      url: thumbnail.url,
      width: thumbnail.width,
      height: thumbnail.height
    }
  end
end

{'fraction_non_alphanumeric': 0.10473397570171764, 'fraction_numerical': 0.011730205278592375, 'mean_word_length': 2.7606299212598424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6982352', 'n_tokens_mistral': 879, 'n_tokens_neox': 844, 'n_words': 166}