Skip to content

Instantly share code, notes, and snippets.

View DriesS's full-sized avatar

Dries Steenhouwer DriesS

View GitHub Profile
require 'mysql'
class Mysql::Result
def encode(value, encoding = "utf-8")
String === value ? value.force_encoding(encoding) : value
end
def each_utf8(&block)
each_orig do |row|
yield row.map {|col| encode(col) }
search.id_does_not_equal(@product.inventory_items.collect(&:size_id) ) if @product && !@product.inventory_items.empty?
xml.Cell do
xml.Data number_with_precision( product.sales_per_day(product.sales.last.start_date.to_date), :precision => 3 ) unless product.sales.last.nil? rescue 'N/A', 'ss:Type' => 'Number'
end
@DriesS
DriesS / gist:1010053
Created June 6, 2011 10:35
Problem with group by on interval
## Output Stock transactions
id source_id inventory_item_id quantity comment author_id created_at updated_at source_type cause
549133 189953 149193 1 55291 "2010-12-16 12:59:23" "2010-12-16 12:59:23" PurchaseItem PURCHASE
586203 203443 149193 11 55291 "2010-12-24 10:15:30" "2010-12-24 10:15:30" PurchaseItem PURCHASE
586413 195123 149193 10 55291 "2010-12-24 10:15:31" "2010-12-24 10:15:31" PurchaseItem PURCHASE
669023 1159453 149193 -1 2943951 "2011-01-13 10:41:42" "2011-01-13 10:41:42" LineItem SALE
765663 1286113 149193 -1 1951411 "2011-02-02 15:21:14" "2011-02-02 15:21:14" LineItem SALE
850583 1388293 149193 -1 4869271 "2011-03-07 08:08:11" "2011-03-07 08:08:11" LineItem SALE
def ship_mondial_relay_orders
tracking_numbers = []
Order.transaction do
Order.processing.mondial_relay.each do |order|
tracking_number = MondialRelay.create_mondial_relais_expedition(order)
order.shipments.create( {:tracking_number => tracking_number, :author => @current_user} )
tracking_numbers << tracking_number
if order.processing?
order.ship_order!
begin
@DriesS
DriesS / Log.log
Created August 17, 2011 16:55
Problem vanity
Showing /Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_ab_test.erb where line #1 raised:
Vanity::Adapters::ActiveRecordAdapter is not missing constant VanityConversion!
Extracted source (around line #1):
1: <% score = experiment.score %>
2: <table>
3: <caption>
4: <%= experiment.conclusion(score).join(" ") %></caption>
Trace of template inclusion: /Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_experiment.erb, /Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_experiments.erb, /Users/dries/.rvm/gems/ruby-1.8.7-p302/gems/vanity-1.5.3/lib/vanity/templates/_report.erb
@DriesS
DriesS / error.log
Created August 18, 2011 13:18
Error with vanity
uninitialized constant Vanity::Rails
@DriesS
DriesS / code.rb
Created August 19, 2011 10:32
Vanity rails problem
module Vanity
module Rails #:nodoc:
def self.load!
Vanity.playground.load_path = ::Rails.root + Vanity.playground.load_path
Vanity.playground.logger ||= ::Rails.logger
# Do this at the very end of initialization, allowing you to change
# connection adapter, turn collection on/off, etc.
::Rails.configuration.after_initialize do
Vanity.playground.load!
include_recipe "deploy"
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
unless application.match(/_stats$/)
execute "restart Rails app #{application}" do
cwd deploy[:current_path]
command node[:scalarium][:rails_stack][:restart_command]
action :nothing
@DriesS
DriesS / configure_vanity.rb
Created August 23, 2011 08:42
Vanity scalarium
include_recipe "deploy"
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
unless application.match(/_stats$/)
execute "restart Rails app #{application}" do
cwd deploy[:current_path]
command node[:scalarium][:rails_stack][:restart_command]
action :nothing