Skip to content

Instantly share code, notes, and snippets.

@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}"
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: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)
#!/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: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
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>
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)
# encoding: utf-8
Feature: Product cross selling
In order to maximize customer satisfaction (and our profit :])
As a potential customer
I want to see items related to product I am currently looking
Scenario: Product page should show cross sell items
Given the following products exists
| product | name | gross_price | available_amount | number | manufacturer_product_number |
| camera | Kamera | 1199 | 22 | HK029737 | 01G-P3-1556-KR |
ActiveRecord::Base.transaction do
orders_to_fix = Order.joins(:billing_address).where("orders.billing_address_id = addresses.id AND addresses.addressable_type = 'User'")
orders_to_fix.each do |order|
billing_address = order.build_billing_address order.billing_address.attributes_for_clone
billing_address.addressable = order
billing_address.save(:validate => false)
ActiveRecord::Base.connection.execute("UPDATE orders SET billing_address_id = #{billing_address.id} WHERE id = #{order.id}")
end
arr = (1..129).map{|a| a}
arr2 = (1001..1129).map{|a| a}
(0..ARGV[0].to_i).each do |a|
(0..128).each do |b|
if arr[b] % 2 == 0
arr[b] += arr2[b]
else
arr2[b] *= arr[b]
end