Skip to content

Instantly share code, notes, and snippets.

View dustintheweb's full-sized avatar
🎯
Focusing

Dustin Hoffmann dustintheweb

🎯
Focusing
View GitHub Profile
@dustintheweb
dustintheweb / switch-statement-example-syntax.js
Last active August 29, 2015 13:57
Switch Statement Example / Syntax
var yourFunction = function(id) {
var _somePath,
_img,
conditionA = !! (window.someGlobalVar === 5), // if you need internal ternary conditions (path switching for example)
conditionB = !! (window.someGlobalVar === 10),
conditionC = !! (window.someGlobalVar === 15);
switch (id) {
case 'some-id-name-1':
// do something
@dustintheweb
dustintheweb / javascript-outside-click-examples.js
Last active August 29, 2015 13:57
If you click outside of a specific div, do something
$('body').on('touchstart click', $staticSection, function(e) {
var $target = $(e.target);
if(!$target.closest($someSection).length) {
// do something... ex: $someSection.removeClass('open');
}
});
// conditional example
$('body').on('touchstart click', $staticSection, function(e) {
@dustintheweb
dustintheweb / clean-nav-bubble-promise-trigger.js
Created April 1, 2014 22:53
Event Bubbling, Promises & Triggers - for a clean navigation structure
// in something.html
// <div>
// <a href="" data-page-state="isAbout">lorem ipsum</a>
// </div>
//promises
$('body').on('isAbout', function(){
// do something
});
$('body').on('isNews', function(){
@dustintheweb
dustintheweb / modernizr-cdn-fallback.js
Last active August 29, 2015 14:01
Modernizr load CDN script with local fallback
Modernizr.load([{
load: [
'//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'
],
complete: function() {
if (!window.jQuery) {
console.log('## CDN Failed - Loading local version of jQuery.');
Modernizr.load('/js/jquery.min.js');
};
}
@dustintheweb
dustintheweb / self-clearing-settimeout.js
Last active August 29, 2015 14:01
Self Clearing setTimeout
var timer = setTimeout(function() {
// code stuffs
clearTimeout(timer);
}, 500);
@dustintheweb
dustintheweb / guide-grunt-workflow
Last active August 29, 2015 14:03
Guide: OSX Grunt Setup & Basic Workflow
## First Run:
-----------------------
/// Add Project Dependencies
Homebrew
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Success?
@dustintheweb
dustintheweb / app.yaml
Last active August 29, 2015 14:03
Create a simple CDN with Google App Engine
application: your-app-cdn
version: 1
api_version: 1
runtime: python27
threadsafe: true
handlers:
# web files
- url: /(.*\.css)
mime_type: text/css
@dustintheweb
dustintheweb / show-namespace-global-variables
Created August 15, 2014 20:18
Javascript - Show All Global Variables Assigned to a Specific Namespace
for(var g in window) {
if(window.hasOwnProperty(g)) console.log(g);
}
// replace window with custom namespace if needed
@dustintheweb
dustintheweb / self-hosted-font-face-stack-android-stock-browser-fix.css
Last active August 29, 2015 14:06
Self Hosted @font-face Webfont Stack With Stock Android Browser Fix
@font-face {
font-family:"FontName";
src:url("fonts/fontname.eot");
src:url("fonts/fontname.eot?#iefix") format("eot"),url("fonts/fontname.woff") format("woff"),url("fonts/fontname.ttf") format("truetype"),url("fonts/fontname.svg#fontname") format("svg");
font-weight: 400;
font-style: normal;
}
@media screen and (-webkit-min-device-pixel-ratio:0) { // android fix
@font-face {
font-family:"FontName";
Verifying that +dustintheweb is my openname (Bitcoin username). https://onename.io/dustintheweb