Skip to content

Instantly share code, notes, and snippets.

View resistorsoftware's full-sized avatar

David Lazar resistorsoftware

View GitHub Profile
delete '/destroy' do
authorize!
@product = ShopifyAPI::Product.find(params[:id])
unless @product.metafields.empty?
@product.metafields.each do |mf|
if mf.key = 'monkey_bile'
ShopifyAPI::Metafield.delete(mf.id)
end
end
end
#
# Create a new repo on Github and directly push your initial commit with this shell script
#
url=https://github.com/api/v2/json/repos/create
username=$(git config github.user)
token=$(git config github.token)
name=${1-$(basename $(pwd))}
curl -F login=$username -F token=$token $url -F name=$name -F public=1 1>/dev/null
@resistorsoftware
resistorsoftware / Order Total
Created December 1, 2010 20:06
sum up orders for Shopify
sum = 0.0
page = 1
start_date = "2010-11-11"
end_date = "2010-12-11"
count = ShopifyAPI::Order.count({:fulfillment_status => 'unshipped', :created_at_max => "#{end_date} 23:59", :created_at_min => "#{start_date} 00:00"})
if count > 0
page += count.divmod(250).first
while page > 0
orders = ShopifyAPI::Order.find(:all, :params => {:page => page, :fulfillment_status => 'unshipped', :limit => 250, :created_at_max => "#{end_date} 23:59", :created_at_min => "#{start_date} 00:00", :financial_status => 'paid'})
orders.each do |order|
@resistorsoftware
resistorsoftware / Unlock Shopify with Magic
Created December 4, 2010 16:10
Ever wanted to open the door by rubbing your magic lamp
post '/signup' do
if params[:code_text] == 'baba_black_sheep'
a = Mechanize.new
a.get('http://private.myshopifysite.com/') do |page|
logged_in = page.form_with(:action => '/password') do |f|
f.password = 'knock_knock'
end.submit
end
c = a.cookies.collect {|c| {:name => c.name, :value => c.value}}
c.each do |cc|
@resistorsoftware
resistorsoftware / OpenID
Created December 8, 2010 14:33
WHat happens on authenticate
Started GET "/server?openid.assoc_handle=%7BHMAC-SHA1%7D%7B4cfd44f7%7D%7BN2m%2BzA%3D%3D%7D&openid.identity=http%3A%2F%2Flocalhost%3A3000%2Fdlazar&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%3A3001%2Fconsumer%2Fcomplete%3Fopenid1_claimed_id%3Dhttp%253A%252F%252Flocalhost%253A3000%252Fdlazar%26rp_nonce%3D2010-12-08T14%253A32%253A35Zx92dI4&openid.trust_root=http%3A%2F%2Flocalhost%3A3001%2Fconsumer" for 127.0.0.1 at Wed Dec 08 09:32:35 -0500 2010
Processing by ServerController#index as HTML
Parameters: {"openid.return_to"=>"http://localhost:3001/consumer/complete?openid1_claimed_id=http%3A%2F%2Flocalhost%3A3000%2Fdlazar&rp_nonce=2010-12-08T14%3A32%3A35Zx92dI4", "openid.mode"=>"checkid_setup", "action"=>"index", "openid.identity"=>"http://localhost:3000/dlazar", "openid.trust_root"=>"http://localhost:3001/consumer", "openid.assoc_handle"=>"{HMAC-SHA1}{4cfd44f7}{N2m+zA==}", "controller"=>"server"}
SQL (0.7ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnu
@resistorsoftware
resistorsoftware / Grape
Created December 15, 2010 02:45
Simple grape eg
require 'grape'
class Foo < Grape::API
version '1'
resource :services do
get :language_detector do
["english", "french"]
end
end
end
run Foo
@resistorsoftware
resistorsoftware / Liquid snippet for theme.liquid
Created February 25, 2011 13:55
How to add Meta Descriptions to a Product
{% if template == 'product' %}
{% assign mf = product.metafields.meta_description %}
{% unless mf == empty %}
{% for mf in product.metafields.meta_description %}
<meta name="Fubar2 Ronnie James Dio" content="{{mf.last}}" />
{% endfor %}
{% endunless %}
{% endif %}
// ---------------------------------------------------------
// POST to cart/update.js returns the cart in JSON.
// To clear a particular attribute, set its value to an empty string.
// Receives attributes as a hash or array. Look at comments below.
// ---------------------------------------------------------
Shopify.updateCartAttributes = function(attributes, callback) {
var data = '';
// If attributes is an array of the form:
// [ { key: 'my key', value: 'my value' }, ... ]
if (jQuery.isArray(attributes)) {
@resistorsoftware
resistorsoftware / config.ru
Created April 12, 2011 12:38
My initial Rackup file
use Rack::Session::Cookie, :secret => 'whatever'
use Rack::Flash
use Rack::MethodOverride
use Warden::Manager do |manager|
manager.default_scope = :user
manager.scope_defaults :user, :strategies => [:password]
manager.scope_defaults :admin, :store => true, :strategies => [:admin]
manager.failure_app = Main::App
end
@resistorsoftware
resistorsoftware / ShopifyAPICallLimit.rb
Created May 14, 2011 16:01 — forked from christocracy/ShopifyAPICallLimit.rb
Hacking ActiveResource::Connection for Shopify API in order to read HTTP response header 'http_x_shopify_api_call_limit'. Simply require this code after your gems have been loaded.
class ActiveResource::Connection
# HACK 1: Add an attr_reader for response
attr_reader :response
def request(method, path, *arguments)
result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
payload[:method] = method
payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
payload[:result] = http.send(method, path, *arguments)
end