Skip to content

Instantly share code, notes, and snippets.

View dfadler's full-sized avatar

Dustin Fadler dfadler

View GitHub Profile
@dfadler
dfadler / loaded-module-example.js
Created September 18, 2013 01:28
Require Example
// Using Example A or B
require(['scripts/mousetrap'], function(Mousetrap) {
// Mousetrap is not returned from a module its actually a reference to window.Mousetrap
});
// Using Example C or D
require.config({
baseUrl: 'scripts',
paths: {
mousetrap: 'script/mousetrap'
@dfadler
dfadler / email_obfuscation.php
Created May 16, 2012 15:42 — forked from ivuorinen/email_obfuscation.php
Email Obfuscation Shortcode for WordPress
<?php
/*
Plugin Name: Email Obfuscation Shortcode
Plugin URI: https://gist.github.com/1424515
Description: Shortcode for including emails into content and keeping spambots clueless. [obf email="email@example.com" noscript="what's shown to bots/people without javascript"]
Version: 0.1
Author: Ismo Vuorinen
Author URI: http://github.com/ivuorinen
*/
@dfadler
dfadler / tooltip-d3.js
Created June 13, 2020 05:48
tooltip function d3
function onMouseMove() {
const mousePosition = d3.mouse(this)
const hoveredDate = xScale.invert(mousePosition[0])
const getDistanceFromHoveredDate = d => Math.abs(xAccessor(d) - hoveredDate)
const closestIndex = d3.scan(dataset, (a, b) => (
getDistanceFromHoveredDate(a) - getDistanceFromHoveredDate(b)
))
const closestDataPoint = dataset[closestIndex]
@dfadler
dfadler / youtube-controls.js
Created May 8, 2012 19:03
Iframed YouTube Javascript Controls
//http://jsfiddle.net/vYb72/1/
/*
* @param String frame_id The id of the div containing the frame
* @param String func Desired function to call, eg. "playVideo"
* @param Array args (optional) List of arguments to pass to function func*/
function callPlayer(frame_id, func, args){
/*func: playVideo, pauseVideo, stopVideo, ... Full list at:
* http://code.google.com/apis/youtube/js_api_reference.html#Overview */
if(!document.getElementById(frame_id)) return;
args = args || [];
'use strict';
//
// # Option
//
// Option a = Some a + None
//
// The option type encodes the presence and absence of a value. The
// `Some` constructor represents a value and `None` represents the
// absence.
@dfadler
dfadler / get-sprite.sass
Created July 13, 2012 15:05
A SASS mixin for generating a sprite declaration block that will work with media queries
// http://compass-style.org/reference/compass/helpers/sprites/
@mixin get-sprite($map, $sprite, $repeat: no-repeat, $height: true, $width: true)
//http://compass-style.org/reference/compass/helpers/sprites/#sprite-file
$sprite-image: sprite-file($map, $sprite)
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-url
$sprite-map: sprite-url($map)
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-position
// Backbone.Events
// ---------------
// A module that can be mixed in to *any object* in order to provide it with
// custom events. You may bind with `on` or remove with `off` callback
// functions to an event; `trigger`-ing an event fires all callbacks in
// succession.
//
// var object = {};
// _.extend(object, Backbone.Events);
function Animation( elem, properties, options ) {
var result,
stopped,
index = 0,
length = animationPrefilters.length,
deferred = jQuery.Deferred().always( function() {
// don't match elem in the :animated selector
delete tick.elem;
}),
tick = function() {
@dfadler
dfadler / backbone-router.js
Created January 13, 2014 14:33
Backbone Router
// Backbone.Router
// ---------------
// Routers map faux-URLs to actions, and fire events when routes are
// matched. Creating a new one sets its `routes` hash, if not set statically.
var Router = Backbone.Router = function(options) {
options || (options = {});
if (options.routes) this.routes = options.routes;
this._bindRoutes();
this.initialize.apply(this, arguments);
@dfadler
dfadler / backbone-history.js
Last active January 3, 2016 03:19
Backbone History
define(['lib/namespace', 'lib/extend'], function(namespace, extend) {
'use strict';
var breaker = {};
var // Keep the identity function around for default iterators.
identity = function(value) {
return value;
},