Skip to content

Instantly share code, notes, and snippets.

View dylanjhunt's full-sized avatar

Dylan Hunt dylanjhunt

View GitHub Profile
@dylanjhunt
dylanjhunt / gist:6453373
Last active December 22, 2015 09:39
Shopify
I started at Shopify on Tuesday, September 3rd, 2013.
self.per_page = 15
gem 'stripe'
rails g controller charges
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
bin/rails generate migration NameOfMigration
class NameOfMigration < ActiveRecord::Migration[5.0]
def change
end
end
@dylanjhunt
dylanjhunt / Rare Subscribe form
Last active April 3, 2017 13:53
Rare.io Subscribe form including firstname
<!-- rare.io subscription form -->
<style type="text/css">
.rare-signup-form{background:#fff;clear:left;font:14px Helvetica,Arial,sans-serif;color: #545454;}
.rare-signup-form label,.rare-signup-form input{display:block;margin-top:10px}
.rare-signup-form label{font-weight:700}
.rare-signup-form input[type="text"]{width:100%;padding:8px 16px;font-size:16px;height:auto;border-width:2px;width:100%;height:34px;padding:6px 12px;border:1px solid #ccc;border-radius:4px;line-height:1.42857143;color:#555}
.rare-signup-form input[type="submit"]{background:#19A0CF;color:#fff;display:inline-block;border:0;-webkit-border-radius:5px;border-radius:5px;text-decoration:none;font-size:15px;font-weight:400;line-height:1em;padding:12px 25px}
</style>
<div class="rare-signup-form">
<form method="POST" action="https://api4.rarelogic.com/shop/rarelogic/subscribe">
@dylanjhunt
dylanjhunt / Shopify Script - $5 Discount on Products with a certain tag
Created November 2, 2016 16:58
This will give a $5 discount on any product that has the tag identified in this Gist with MyTag
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.tags.include?('MyTag')
line_item.change_line_price(line_item.line_price - Money.new(cents: 500), message: "$5 Off")
end
Output.cart = Input.cart
@dylanjhunt
dylanjhunt / Shopify Script - Buy 1 Get 1 for X% off
Created November 2, 2016 17:01
This will give a Buy 1 Get 1 discount percentage for the product ID marked on line 63 with the discount outlined on line 30
PAID_ITEM_COUNT = 1
DISCOUNTED_ITEM_COUNT = 1
# Returns the integer amount of items that must be discounted next
# given the amount of items seen
#
def discounted_items_to_find(total_items_seen, discounted_items_seen)
Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen
end