Skip to content

Instantly share code, notes, and snippets.

@christophergregory
christophergregory / shopify_wholesale.liquid
Last active January 3, 2016 09:59
Shopify wholesale product snippet
{% comment %}
Tag customers and products with "wholesale" tags.
{% endcomment %}
{% assign isWholesaleCustomer = false %}
{% if customer and customer.tags contains 'wholesale' %}
{% assign isWholesaleCustomer = true %}
{% endif %}
@christophergregory
christophergregory / center.js
Created May 7, 2013 15:36
Center image within parent element
(function($) {
$.fn.centerWithinParent = function() {
return this.each(function(){
var $this = $(this),
parentPosition = $this.parent().css('position');
if (parentPosition !== "absolute" || parentPosition !== "relative") {
$this.parent().css('position', 'relative');
@christophergregory
christophergregory / gist:5398359
Created April 16, 2013 18:33
Keep IE from caching ajax call
function getCart(callback) {
var rnum = Math.floor((Math.random()*1000000000)+1),
rand_url = '/cart.js?' + rnum;
jQuery.getJSON(rand_url, function (cart, textStatus) {
if ((typeof callback) === 'function') {
callback(cart);
}
else {
@christophergregory
christophergregory / date.py
Created March 18, 2013 15:06
Checks to see if date is within a range
import datetime
# Checks too see if date is within a range
def is_within_date(date, min_date, max_date):
# Convert MM/DD/YYYY string format to datetime date
def convert_string_to_date(date_string):
month,day,year = date_string.split("/")
return datetime.date(int(year), int(month), int(day))
day = convert_string_to_date(date)
day_min = convert_string_to_date(min_date)
@christophergregory
christophergregory / gist:4269413
Created December 12, 2012 16:49
Shopify: Array loop divider
<div id="looper">
{% assign range = 5 %}
{% assign min = 0 %}
{% assign max = range %}
{% assign iter = 0 %}
{% assign arr = 'asdfasdf,asdfasf,aafa,asdfas,asass,asdsd,asdads,asdfasf,asdadss,aflkjlfakl,asldf,asldkfjasl,aslas,asldkfjasldkfjasdkf,lskl,asdlfjadslkf,asdfasfs,asdflkjasdl,asdlfkjaslf,asdfas,asdlfkjasdfl,asdfalda' | split: "," %}
@christophergregory
christophergregory / gist:4195957
Created December 3, 2012 16:05
Shopify:Remove old attributes from the cart
function getCartData(callback) {
Shopify.getCart(function(cart){
callback(cart);
});
}
function updateCartAttributes(data, callback) {
var params = {
type: 'POST',
url: '/cart/update.js',
@christophergregory
christophergregory / jquery.waitForImages.js
Created November 13, 2012 21:13
jQuery:waitForImages(selector, callback)
function waitForImages(selector, callback) {
var loaded = 0;
$(selector).load(function()
{
loaded++;
if (loaded == $(selector).length)
{
callback();
}
});
{% for product in collections.All.products %}
<div class="img-wrapper">
<img src="{{ product.images | first | product_img_url: 'medium' }}" alt="{{ product.title | escape }}">
</div>
{% endfor %}
@christophergregory
christophergregory / _mixins.scss
Created October 18, 2012 19:10
SASS: mixins
@mixin bgSprite($left: 0, $top: 0, $width: auto, $height: auto, $img: $sprite, $repeat: no-repeat) {
overflow: hidden;
width: $width;
height: $height;
background: transparent $img (0 - $left) (0 - $top) $repeat;
}
@mixin roundEachCorner($tl: 0, $tr: 0, $br: 0, $bl: 0) {
-webkit-border-top-left-radius: $tl;
-webkit-border-top-right-radius: $tr;
@christophergregory
christophergregory / jquery.okv-wrapper.js
Created October 17, 2012 13:05
JavaScript: OpenKeyVal Wrapper
/*
OpenKeyVal Wrapper
Author: Chris Gregory (chris@sinelabs.com)
Description: Obscures openkeyvalue variable names for added protection against variable name overwrites
*/
var OKV = (function($, sudoKey) {
var okv = {},