Skip to content

Instantly share code, notes, and snippets.

@greypants
greypants / uri.js
Created May 25, 2012 17:43 — forked from jlong/uri.js
JS: URI and Query String Parsing
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
# Creates a bzip2 file (smaller than tarball)
tar -cjf backup.tar.bz2 directory
# which can be decompressed using...
tar -xjf backup.tar.bz2
# remove directory
rm -r -f YourDirectory
@greypants
greypants / rAF.js
Created August 2, 2012 14:59 — forked from paulirish/rAF.js
JS: requestAnimationFrame polyfill (Irish-Moller )
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@greypants
greypants / gist:3306778
Created August 9, 2012 18:21 — forked from davist11/gist:2702312
JS: jQuery Plugin Pattern
/*
* 'Highly configurable' mutable plugin boilerplate
* Author: @markdalgleish
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
// Note that with this pattern, as per Alex Sexton's, the plugin logic
// hasn't been nested in a jQuery plugin. Instead, we just use
// jQuery for its instantiation.
@greypants
greypants / utils.captureMouse.js
Created October 1, 2012 18:06
JS: Capture Mouse / Capture Touch
/* Object that contains our utility functions.
* Attached to the window object which acts as the global namespace.
*/
window.utils = {};
/**
* Keeps track of the current mouse position, relative to an element.
* @param {HTMLElement} element
* @return {object} Contains properties: x, y, event
*/
@greypants
greypants / respond-to.scss
Created October 5, 2012 19:56
SCSS: respond-to($query) mixin
@mixin respond-to($query) {
@media only screen and #{$query} {
@content
}
}
//Responsive Sizes
$small: '(max-width: 480px)';
$medium: '(max-width: 480px) and (max-width: 640px)';
@greypants
greypants / no-js.js
Created October 15, 2012 20:27
JS: no-js
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
@greypants
greypants / barebones.html
Created October 16, 2012 00:34
HTML: Barebones
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="no-js ie ie6 lte6 lte7 lte8 lte9"><![endif]-->
<!--[if IE 7 ]><html class="no-js ie ie7 lte7 lte8 lte9"> <![endif]-->
<!--[if IE 8 ]><html class="no-js ie ie8 lte8 lte9"><![endif]-->
<!--[if IE 9 ]><html class="no-js ie ie9 lte9"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@greypants
greypants / conditional.html
Created October 16, 2012 00:35
HTML: IE <html> tag IE conditional tags + no-js
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="no-js ie ie6 lte6 lte7 lte8 lte9"><![endif]-->
<!--[if IE 7 ]><html class="no-js ie ie7 lte7 lte8 lte9"> <![endif]-->
<!--[if IE 8 ]><html class="no-js ie ie8 lte8 lte9"><![endif]-->
<!--[if IE 9 ]><html class="no-js ie ie9 lte9"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js"><!--<![endif]-->
@greypants
greypants / touchDesktop.js
Created October 22, 2012 19:27
JS: Touch/Desktop Event Pattern
var supports_touch = 'ontouchend' in document;
var events = {
desktop: {
start : 'mousedown',
stop : 'mouseup',
move : 'mousemove',
leave : 'mouseleave',
resize : 'resize'
},