Skip to content

Instantly share code, notes, and snippets.

ActiveRecord::Base.transaction do
Category.all.each do |c|
ordered_configs = c.search_attribute_configs.
joins(:search_attribute).
order("cnet_search_attributes.name").
select("DISTINCT search_attribute_configs.id, cnet_search_attributes.name")
ordered_configs.each_with_index do |sa_config, index|
sa_config = SearchAttribute::Config.find(sa_config.id)
sa_config.update_attribute(:position, index + 1)
application@rommulus:~/projects/heute_kaufen/production/current$ RAILS_ENV=production bundle exec rake "cnet:update[false]" --trace
** Invoke cnet:update (first_time)
** Invoke cnet:config/application.yml (first_time)
** Execute cnet:config/application.yml
** Invoke environment (first_time)
** Execute environment
** Execute cnet:update
Downloading CNet data to /home/application/projects/heute_kaufen/production/current/tmp
rake aborted!
undefined method `log' for #<Rails::Paths::Root:0x00000005652a20>
@detomastah
detomastah / gist:4071304
Created November 14, 2012 10:01
Recreate versions
Image.all.each do |img|
begin
img.file.recreate_versions!
rescue
puts "Cannot recreate version for Image with ID: #{img.id}"
end
end
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@detomastah
detomastah / gist:3958841
Created October 26, 2012 13:31
Benchmark
rake 0.400000 0.030000 0.430000 ( 0.422317)
gem-patching 0.010000 0.000000 0.010000 ( 0.009515)
simple_form 0.020000 0.000000 0.020000 ( 0.030241)
kronn-has_many_polymo 0.010000 0.010000 0.020000 ( 0.014797)
i18n-missing_translat 0.030000 0.000000 0.030000 ( 0.021213)
test-unit 0.000000 0.000000 0.000000 ( 0.000027)
devise 0.400000 0.030000 0.430000 ( 0.444638)
delocalize 0.060000 0.010000 0.070000 ( 0.060652)
activeadmin 2.860000 0.290000 3.150000 ( 3.165178)
meta_search 0.000000 0.000000 0.000000 ( 0.001347)
begin
$counter = 0
def update_positions(scope, start)
scope.each_with_index do |ia, index|
ia.update_attribute(:position, start + index)
$counter += 1
end
end
Product.all.each do |p|
ia = p.image_assignments.where("position IS NOT NULL").order("position DESC").first
@detomastah
detomastah / gist:3892576
Created October 15, 2012 13:55
Updated timestamps for invoices
$affected = []
$not_updated = []
def update_timestamp(invoice, created_at)
if created_at.blank?
$not_updated << invoice
else
created_at = created_at.in_time_zone - 30.minutes
puts "#{invoice.id} #{invoice.created_at} -> #{created_at}"