Skip to content

Instantly share code, notes, and snippets.

0xeb0fa78cfe43d30a61de0aacea86452ae537fe3a
@sturob
sturob / wait-defered.js
Created June 26, 2013 14:26
Timeouts using jquery promises
$.wait = function(time) {
var id;
var def = $.Deferred(function(dfd) {
id = setTimeout(dfd.resolve, time);
});
def.cancel = function() {
clearTimeout(id);
def.reject();
}
return def;
@sturob
sturob / dabblet.css
Created June 25, 2013 21:17
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
html {
font-family: Helvetica;
background: #f06;
background: linear-gradient(23deg, #f06, yellow);
min-height: 100%;
}
@sturob
sturob / dabblet.css
Created June 23, 2013 17:05
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
html {
font-family: Helvetica;
background: #f06;
background: linear-gradient(23deg, #f06, yellow);
min-height: 100%;
}
@sturob
sturob / lazyeach
Last active December 18, 2015 02:59
demo of some Lazy with callback completion
// see http://mistakes.io/#5714973 with console visible
require('https://raw.github.com/dtao/lazy.js/master/lazy.min.js');
require('http://documentcloud.github.io/underscore/underscore-min.js');
var n = 10;
var log = function(msg) { console.log(msg) },
done = function() { log('DONE') },
doneAfterN = _.after(n, done),
@sturob
sturob / gist:2360182
Created April 11, 2012 15:51
base64 encode an png to the OSX clipboard
base64 /path/to/image.png | pbcopy
@sturob
sturob / html2less.js
Created January 31, 2012 12:49
generate nested less from the DOM
// adapted www.jameswiseman.com/blog/2010/08/24/manually-traverse-a-dom-tree-using-jquery/
// requires jquery
function html2less($item, pass) {
var tmp = {};
$item = $item ? $item : $('body');
pass = pass ? pass : { max: 50, count: 0, less: "" };
$item.each(function(n, v) {
@sturob
sturob / local-jquery-fallback.js
Created February 8, 2011 11:55
load own jquery if CDN fails
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.5.0.js"%3E%3C/script%3E'))</script>
// old and busted - don't do this
setInterval(function(){
$.ajax({
url: 'foo.htm',
success: function( response ){
// do something with the response
}
});
}, 5000);
@sturob
sturob / safe-less-loader.js
Created January 11, 2011 17:40
use less for dev + css for live
if (window.location.hostname == 'localhost') {
var l = document.getElementById('main_styles');
l.rel = 'stylesheet/less';
l.href = 'less/main.less';
}