Skip to content

Instantly share code, notes, and snippets.

View wehrhaus's full-sized avatar

Justin Wehrman wehrhaus

View GitHub Profile
@wehrhaus
wehrhaus / index.js
Created September 18, 2015 05:04
Exercises from the book, Functional JavaScript
var _ = require('lodash');
// var _ = require('underscore');
function existy(x) {
return x !== undefined && x !== null;
}
function truthy(x) {
return x !== false && existy(x);
}
@wehrhaus
wehrhaus / _linearGradientToSVG.scss
Created June 5, 2015 06:39
linearGradientToSVG SCSS Mixin
//----------------------------------------------------------------------
// Create a 2 color, linear gradient SVG image - default of vertical
// @function linearGradientToSVG
// @param {rgba} $colorA first color (top/left) of the gradient
// @param {rgba} $colorB second color (bottom/right) of the gradient
// @param {string} $orientation expects vertical or horizontal
// @returns {url}
//----------------------------------------------------------------------
@function linearGradientToSVG($colorA, $colorB, $orientation: vertical) {
@if $orientation == vertical {
@wehrhaus
wehrhaus / _triangleGenerator.scss
Last active August 29, 2015 14:16
SCSS Triangle Generator
//----------------------------------------------------------------------
// Convert a number to specified unit
// @function unit
// @param {number} $num number to be converted to unit
// @param {string} $units unit number will be converted to
// @returns {string}
//----------------------------------------------------------------------
@function unit($num, $units) {
@return #{$num}#{$units};
}
@wehrhaus
wehrhaus / Solarized (Dark).tmTheme
Created October 13, 2014 03:11
Modified Solarized Dark Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Solarized (dark)</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@wehrhaus
wehrhaus / YTVideoLoader.js
Last active August 29, 2015 14:07
YouTube iFrame Video Loader - Over simplifies working with the YouTube iFrame API
// # YTVideoLoader.js
// Doc: []
// ## Namespacing
// * Namespace YTVideoLoader Object
// ### Public Methods Available:
// * YTVideoLoader.confirmAPIReady()
// * YTVideoLoader.destroyPlayer()
// * YTVideoLoader.playerControl()
// * YTVideoLoader.buildPlayer()
@wehrhaus
wehrhaus / For-Loop-Has-Own-Property.sublime-snippet
Created September 19, 2014 15:57
Sublime Snippet - sets up for loop with hasOwnProperty check and fix for IE8 support
<snippet>
<content><![CDATA[
/* IE8 fix for window.hasOwnProperty - set to ignore error from jshint */
/* jshint -W001 */
$2.hasOwnProperty = $2.hasOwnProperty || Object.prototype.hasOwnProperty;
for ($1 in $2) {
if ($2.hasOwnProperty($1)) {
console.log($2[$1]$0);
}
}
@wehrhaus
wehrhaus / diamond.styl
Created July 15, 2014 21:52
Stylus Diamond Generator
diamond(width, dColor)
dWidth = unit(width, px)
display block
width dWidth;
height dWidth;
background dColor
position relative
top dWidth
transform rotate(-45deg)
transform-origin 0 100%
@wehrhaus
wehrhaus / triangle.styl
Created July 15, 2014 21:51
Stylus Triangle Generator
triangle(orientation, width, height, color)
if orientation == top
border-width 0 unit(width/2, px) unit(height, px) unit(width/2, px)
border-color transparent transparent color transparent
else if orientation == left
border-width unit(height/2, px) unit(width, px) unit(height/2, px) 0
border-color transparent color transparent transparent
else if orientation == bottom
border-width unit(height, px) unit(width/2, px) 0 unit(width/2, px)
border-color color transparent transparent transparent
@wehrhaus
wehrhaus / getPercentage.styl
Created July 8, 2014 16:05
Stylus Percentage Difference Calcualator
// http://www.mathsisfun.com/percentage-difference.html
// get percentage difference of 2 numbers
// returns optional unitType as well in the form of '%, px, em' etc
getPercentageDifference(v1, v2, unitType = '')
return unit(((v1 - v2) / ((v1 + v2) / 2)) * 100, unitType)
// get percentage difference of 2 numbers then returns the result minus a given max value
// returns optional unitType as well in the form of '%, px, em' etc
getPercentageDifferenceMinusMax(v1, v2, max, unitType = '')
return unit(max - getPercentageDifference(v1, v2), unitType)
@wehrhaus
wehrhaus / ajaxTemplate.js
Created July 1, 2014 14:20
jQuery Ajax Template
var jqxhr = $.ajax({
url: url,
type: 'GET', // default is GET but you can use other verbs based on your needs.
cache: true, // default is true, but false for dataType 'script' and 'jsonp', so set it on need basis.
data: {}, // add your request parameters in the data object.
dataType: 'json', // specify the dataType for future reference
jsonp: 'callback', // only specify this to match the name of callback parameter your API is expecting for JSONP requests.
statusCode: { // if you want to handle specific error codes, use the status code mapping settings.
404: handler404,
500: handler500