Skip to content

Instantly share code, notes, and snippets.

View ckhatton's full-sized avatar
💭
"A good cake, is a tasty cake."

Chris Hatton ckhatton

💭
"A good cake, is a tasty cake."
View GitHub Profile
# Use Gists to store entire functions
class QuickSort
def self.sort!(keys)
quick(keys,0,keys.size-1)
end
private
def self.quick(keys, left, right)
@ckhatton
ckhatton / 1_view_more.md
Last active August 29, 2015 14:11
View More - Graphical Effect

View More - Graphical Effect

Screenshot

To give a faded text look at the bottom of a long list, with gradient left and right borders (bottom to top) that act as a container.

.view-more and .accordion-toggle are separate divs that stack as siblings.

@ckhatton
ckhatton / change_text.js
Created December 8, 2014 23:04
Alternately change a snippet of text in the DOM.
var customInterval = null;
function changeText(elem, text) {
// 'text' is a array of strings
// For example: ['loading','.loading.','..loading..','...loading...']
var counter = 0;
customInterval = setInterval(change, 1000);
function change() {
elem.text(text[counter]);
counter++;
@ckhatton
ckhatton / query_parameter.js
Created December 8, 2014 23:07
Grab query parameters from the URL.
jQuery.extend({
getQueryParameters : function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
});
@ckhatton
ckhatton / scroll-to.js
Last active August 29, 2015 14:11
A scroll-to function. Detects if a manual scroll has occurred during the animation, and stops, to prevent a glitchy clash of actions.
function scrollTo(element, within) {
$(within).bind('mousedown DOMMouseScroll mousewheel', function(){
$(this).stop();
});
$(within).animate({
scrollTop: Math.ceil($(element).position().top)
}, 1500, "easeOutQuart", function(){
$(this).unbind('mousedown DOMMouseScroll mousewheel');
});
@ckhatton
ckhatton / shopify-helpers.js
Last active August 29, 2015 14:11
Shopify JS helpers; for adding 'error' class; formatting a string to an URL or from an URL, or to a Shopify URL.
function addError(element) { $(element).addClass('error'); }
function removeError(element) { $(element).removeClass('error'); }
function formatForUrl(str) {
return str
.replace(/ /g, '%20')
.replace(/:/g, '%20')
.replace(/\\/g, '-')
.replace(/\//g, '-')
@ckhatton
ckhatton / remove-from-array.js
Created December 9, 2014 00:19
Remove specific values from an array.
function removeFromArray(value, array) {
return $.grep(array, function(elem, index) {
return elem !== value;
});
}
@ckhatton
ckhatton / redirect-user.js
Last active August 29, 2015 14:11
Redirect the user to a mobile or desktop version of the page, by detecting the user agent. Also shows the desktop version if the user has clicked to view the desktop version only (the cookie lasts an hour). Make sure to include the 'jquery.cookie.js' file somewhere above the script.
$(document).ready(function(){
$('.view-desktop-version')
.click(function(){
var date = new Date();
date.setTime(date.getTime() + (60 * 60 * 1000));
$.cookie('page_ver', 'desktop', { expires: date, path: '/' });
window.location = '/desktop';
});
});
@ckhatton
ckhatton / set-viewport.html
Created December 9, 2014 20:33
Sets the viewport depending on the device.
<meta id="viewport" name='viewport'>
<script>
(function(doc) {
var viewport = document.getElementById('viewport');
if ( navigator.userAgent.match(/iPhone|iPod/i) || screen.width <= 640) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=0.3, maximum-scale=1.0, width=device-width");
} else if ( navigator.userAgent.match(/Android|webOS|iPad|BlackBerry|IEMobile|Opera Mini/i) || screen.width > 640 ) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=1.0, maximum-scale=1.0, width=device-width");
}
}(document));