Skip to content

Instantly share code, notes, and snippets.

@christophergregory
christophergregory / callback.js
Created October 16, 2012 17:15
Callback function example
function callCallbackFunction (callback) {
callback(); // all this does is call the function that is passed in as a parameter
};
callCallbackFunction(function(){
alert('this is inside the callback function');
});
// Here is another way to do basically the same thing
@christophergregory
christophergregory / gist:3900778
Created October 16, 2012 17:39
CSS: Inputs as same height
span, input {
margin: 0;
padding: 0;
}
span {
display: inline-block;
border: 1px solid black;
height: 25px;
overflow: hidden;
}
@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 = {},
@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;
{% 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 / 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();
}
});
@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 / 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 / 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: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 {