Skip to content

Instantly share code, notes, and snippets.

View AllThingsSmitty's full-sized avatar

Matt Smith AllThingsSmitty

View GitHub Profile
@AllThingsSmitty
AllThingsSmitty / functions.js
Last active August 29, 2015 14:15
Simplifying JS functions with Lo-Dash
// Get a simple array of objects
var drinks = [
{ 'name': 'Coke', 'quantity': 2 },
{ 'name': 'Red Bull', 'quantity': 6 }
];
// Get all the drink names using the _.pluck() function
var currentDrinks = _.pluck(drinks, 'name');
console.log(currentDrinks);
// → ['Coke', 'Red Bull']
@AllThingsSmitty
AllThingsSmitty / wat.js
Last active August 29, 2015 14:15
JS variables in Unicode
(function () {
'use strict';
var Λ_Λ = console.log,
ಠ_ಠ = "feeling happy",
ↂ = "look mom no hands",
iǃ = Infinity,
Θ_Θ = "hey buddy",
Ψ = function(e){throw e;};
@AllThingsSmitty
AllThingsSmitty / apple-mq.css
Last active June 23, 2022 19:56
iPhone 6/6 Plus and Apple Watch CSS media queries
/* iPhone 6 landscape */
@media only screen and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 portrait */
@media only screen
and (min-device-width: 375px)
@AllThingsSmitty
AllThingsSmitty / run-sync.js
Last active August 29, 2015 14:16
Sync Gulp tasks with run-sequence
var runSequence = require('run-sequence'); // https://www.npmjs.com/package/run-sequence
//Each successive argument waits for the previous task(s) to finish
gulp.task('some-task', function () {
runSequence(
['task-1', 'task-2', 'task-3'], // These 3 can be done in parallel
'task-4', // ...then just do this
['task-5', 'task-5'], // ...then do these things in parallel
'task-6', // ...then do this
// ...
@AllThingsSmitty
AllThingsSmitty / feature-query.css
Created February 27, 2015 22:13
CSS feature detection using feature queries
/*
@supports(test condition) {
apply rules
}
@supports not(test condition) {
apply rules
}
*/
/* use CSS variable */
@supports (background-color: var(--bg-color)) { /* support: http://caniuse.com/#feat=css-variables */
@AllThingsSmitty
AllThingsSmitty / nested.scss
Last active August 29, 2015 14:16
Nested @​keyframe rules
/* old Sass 3.3 */
/* nest keyframe rules inside their modules with `@at-root` */
.bunny {
animation: hop 2s ease-in-out infinite,
move 6s ease-out forwards;
@at-root {
@keyframes hop {
50% { transform: translateY(40px); }
}
@AllThingsSmitty
AllThingsSmitty / mustard.js
Last active April 13, 2016 14:02
Revised cut-the-mustard browser feature detection
// Streamlined CTM method using Page Visibility API (http://caniuse.com/#feat=pagevisibility)
if ('visibilityState' in document) {
// Modern browser, add JS functionality
}
// Previous CTM method based on which DOM features are present
if('querySelector' in document
&& 'localStorage' in window
&& 'addEventListener' in window) {
// Modern browser, add JS functionality
@AllThingsSmitty
AllThingsSmitty / proxy.js
Last active August 29, 2015 14:17
Feature detection for proxy browsers that lie about their capabilities
// localStorage example
var hasStorage = (function () {
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch (exception) {
return false;
}
}());
@AllThingsSmitty
AllThingsSmitty / url.js
Created March 28, 2015 14:46
Get an absolute URL with JavaScript
var getAbsoluteUrl = (function () {
var a;
return function (url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();