Skip to content

Instantly share code, notes, and snippets.

# helper method for cleaning taxons and properties
# if an artist changes the medium_taxon for a product
# some product propeties need to be normalized
def correct_properties
sculpture_id = Taxon.find_by_name('Sculpture').id
product_medium_taxon_id = params[:product][:medium_taxon_id]
debugger
# if artist updates product to a sculpture taxon
# make sure there isn't an associated surface property
@kshsieh
kshsieh / gist:5725732
Last active December 18, 2015 04:29
i'm oddly proud of this
desc "seperate medium and surface product properties"
task :seperate_medium_and_surface_properties => :environment do
medium_property_id = Property.find_by_name("Medium").id
if Property.find_by_name("Surface")
surface_property_id = Property.find_by_name("Surface").id
else
Property.create(name: "Surface", presentation: "Surface")
surface_property_id = Property.find_by_name("Surface").id
end
@kshsieh
kshsieh / gist:5725730
Created June 6, 2013 23:07
i'm oddly proud of this?
desc "seperate medium and surface product properties"
task :seperate_medium_and_surface_properties => :environment do
# create a new surface property
Property.create(name: "Surface", presentation: "Surface")
# assign property ids to an actionable variables to work with later
# don't assume that medium id is what it is in the database, so don't hardcode it
medium_property_id = Property.find_by_name("Medium").id
surface_property_id = Property.find_by_name("Surface").id
# create an array of all "Medium" ProductProperties
actionable_properties = ProductProperty.all.select { |pp| pp.property_id == medium_property_id }
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => CONFIG[:access_key_id],
:aws_secret_access_key => CONFIG[:secret_access_key]
})
bucket = connection.directories.get('artsicledev')
url = https://artsicledev.s3.amazonaws.com/
Image.all.each do |img|
@kshsieh
kshsieh / gist:5534202
Last active December 17, 2015 02:18
thoughts?
# note that these need to be viewable ids
vagrant_img_ids = []
# try setting attachment_meta to nil and set_metadata!
# if that doesn't work add it to a new array and check the bucket for duplicate original images
Image.where(:viewable_type => 'User::Info').each do |img|
if img.attachment.width(:fw_500) == nil
img.update_attribute(:attachment_meta, nil)
img.set_metadata!
# check again if it didn't work, well fuck, check the bucket
@kshsieh
kshsieh / gist:5436226
Last active December 16, 2015 12:39
can't start rails because of this?
NoMethodError: undefined method `spec' for nil:NilClass
An error occurred while installing paperclip-meta (0.4.3), and Bundler cannot continue.
Make sure that `gem install paperclip-meta -v '0.4.3'` succeeds before bundling.
[/home/ksh2115/.rvm/gems/ruby-1.9.3-p385@artsicle/specifications/paperclip-meta-0.4.3.gemspec] isn't a Gem::Specification (NilClass instead).
[/home/ksh2115/.rvm/gems/ruby-1.9.3-p385@artsicle/specifications/paperclip-meta-0.4.3.gemspec] isn't a Gem::Specification (NilClass instead).
ERROR: While executing gem ... (NoMethodError)
undefined method `spec' for nil:NilClass
@kshsieh
kshsieh / gist:5373546
Created April 12, 2013 17:09
thoughts?
namespace :artwork_stat do
desc "Checks for artwork stat for completed orders"
task :check_for_stat => :environment do
Order.all.each do |order|
if order.completed?
if order.line_items.length != 0 && order.artworks.length == 0
data_errors.create(message: "Order #{order.id} has line items but no artworks!")
elsif order.artworks.length != 0
order.artworks.each do |artwork|
if artwork.stats.length == 0
@kshsieh
kshsieh / gist:5303168
Created April 3, 2013 17:11
some code from checkout process using artwork credits
artwork_credit.rb
# credit flag for this model marks whether or not it is an active credit (can be applied)
# following two methods are used in checkout process to when artwork credits are used, turned into adjustments, and deactivated to make sure they can't be reused
def use_credit
self.update_column(:credit, false)
end
def restore_credit
self.update_column(:credit, true)
@kshsieh
kshsieh / gist:5295079
Created April 2, 2013 18:54
from for artwork credit show in summary and removal
<% elsif adjustment.label == "Artwork Credit" %>
<tr class="artwork-credit">
<td class="credit-name"><%= adjustment.label %>:</td>
<td class="align-right"><%= number_to_currency adjustment.amount %></td>
<td class="credit-form">
<%= form_for @order, url: update_cart_path, html: {class: 'remove-credit-form', id: "credit_#{adjustment.object_id}"} do |f| %>
<%= f.hidden_field :artwork_credit, value: '0' %>
<button type="button" class="close remove-artwork-credit" title="Remove Artwork Credit" rel="tooltip">×</button>
<% end %>
@kshsieh
kshsieh / gist:5094966
Created March 5, 2013 22:33
error with rubber
cap rubber:setup_security_groups
triggering load callbacks
* 2013-03-05 17:32:59 executing `rubber:init'
* 2013-03-05 17:33:00 executing `rubber:setup_security_groups'
* Security Group already in cloud, syncing rules: sampleapp_production_default
* Missing rule, creating: {"source_group_name"=>"sampleapp_production_default", "source_group_account"=>"artsicle", "protocol"=>"tcp", "from_port"=>"1", "to_port"=>"65535"}
/home/ksh2115/.rvm/gems/ruby-1.9.3-p385@rails3tutorial2ndEd/gems/excon-0.19.5/lib/excon/middlewares/expects.rb:10:in `response_call': Unable to find group 'sampleapp_production_default' (Fog::Compute::AWS::NotFound)
from /home/ksh2115/.rvm/gems/ruby-1.9.3-p385@rails3tutorial2ndEd/gems/excon-0.19.5/lib/excon/connection.rb:325:in `response'
from /home/ksh2115/.rvm/gems/ruby-1.9.3-p385@rails3tutorial2ndEd/gems/excon-0.19.5/lib/excon/connection.rb:230:in `request'
from /home/ksh2115/.rvm/gems/ruby-1.9.3-p385@rails3tutorial2ndEd/gems/excon-0.19.5/lib/excon/middlewares/idempotent.rb:11:in