Skip to content

Instantly share code, notes, and snippets.

View dtipson's full-sized avatar

Drew dtipson

View GitHub Profile
@dtipson
dtipson / 0_reuse_code.js
Created August 6, 2014 16:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dtipson
dtipson / dabblet.css
Created September 10, 2014 15:45 — forked from LeaVerou/dabblet.css
Switch-style checkboxes.
/**
* Switch-style checkboxes.
* Inspired by Espresso’s “Tools” switch
*/
input[type="checkbox"]:not(:checked),
input[type="checkbox"]:checked { /* :checked here acting as a filter for older browsers */
position: absolute;
opacity: 0;
}
@dtipson
dtipson / gist:7ba94242aed044febf98
Last active August 29, 2015 14:10
Fullscreen an iframe of CNN _on_ cnn.com and surf silently in Safari
jQuery('html').empty().html('<iframe src="http://cnn.com" style="position:absolute;top:0;left:0;width:100%;height:100%;border:0"></iframe>');
@dtipson
dtipson / gist:c1d01bac35d8baca25e3
Last active August 29, 2015 14:14
micro-plugin that allows you to one-line callbacks and chain compose jQuery operations
(function($){
/*define the function */
function use(method /*args*/){
return use.fn.init.apply({},[Array.prototype.slice.call(arguments)]);
}
/*define the underlying prototype*/
use.fn = use.prototype = {
init: function(initStack,oldstack){
$ = jQuery;
function hardWidth($el){
$el.css({width:$el.width()});
}
function hardSize($el){
$el.css({height:$el.height(),width:$el.width()});
}
@dtipson
dtipson / gist:a392eb4c5c7a5a51c047
Last active August 29, 2015 14:24
Boilerplate example of how to "trap" tab events inside a modal so users can't tab to elements outside it while it's active
var keydownTabString = 'keydown.tabnamespace';//string of the custom event using a custom namespace
function getInputs($modalOuter){
return $modalOuter.find('select, input, textarea, button, a[href], [tabindex]').filter(':visible');
}
function switchTabFocusTarget($switchFocusTo, noshift){
return function(e){
if ((e.which === 9 && (noshift?!e.shiftKey:e.shiftKey))) {
stopEvent(e);
function addOne(n){ return n+1; }
function logger(){ console.log.apply(console,arguments); return }
//Promise unit
function unit(n){ return $.Deferred().resolve(n); }
//make a simple function into a function that returns a Promise
function lift(fn){
function unit(x) {
return Promise.resolve(x);
}
function bind(input, f) {
return input.then(function(x){
return f(x);
});
}
@dtipson
dtipson / promises-and-lenses.js
Created August 9, 2015 20:15
Some functional javascript fun with promises and something sort of like Haskellish lenses
/*unit */
//Promise.right*/
function resolve(x) {
return Promise.resolve(x);
}
/*Promise.left*/
function reject(x) {
return Promise.reject(x);
/*Some basic units: values wrapped in a Promise */
//Promise.right*/
function resolve(x) {
return Promise.resolve(x);
}
/*Promise.left*/
function reject(x) {
return Promise.reject(x);