Skip to content

Instantly share code, notes, and snippets.

View wehrhaus's full-sized avatar

Justin Wehrman wehrhaus

  • ['WehrHaus', 'EquipmentShare']
  • Kansas City, MO
View GitHub Profile
@wehrhaus
wehrhaus / .gitignore
Last active August 29, 2015 13:57
Starter .gitignore file
# Generics
*~
*.lock
*.DS_Store
*.sublime-workspace
# Logs
logs
*.log
@wehrhaus
wehrhaus / take_note
Last active August 29, 2015 13:57
Simple note keeper script. Creates files based on date and timestamps entries.
#!/bin/bash
# Simple note keeper script.
# Creates files based on date and timestamps entries.
# setup date format to ##.##.##
dateStamp=$(date +"%m.%d.%y")
# write note to:
fileName=$HOME/TakeNote/note_${dateStamp}.txt
@wehrhaus
wehrhaus / decomposeTimestamp.js
Created April 11, 2014 03:50
Breakdown timestamp into useable parts.
var decomposeTimestamp = function (timestamp) {
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
d = new Date(timestamp),
component = {};
return component = {
day: function () { return d.getDate(); },
month: function (type) { // call month('num') for 1 thru 12 instead of Names
if (type === 'num') {
return d.getMonth() +1;
@wehrhaus
wehrhaus / bvFilter.js
Last active August 29, 2015 13:59
Filter BazaarVoice Results
// Util for cleaning up the BV Timestamp
var decomposeTimestamp = function (timestamp) {
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
d = new Date(timestamp),
component = {};
return component {
day: function () { return d.getDate(); },
month: function (type) { // call month('num') for 1 thru 12 instead of Names
if (type === 'num') {
@wehrhaus
wehrhaus / optionAlphaSort.js
Last active August 29, 2015 14:00
Take a <select> object with a group of <options> that are sorted by a numeric value attribute and sort alphabetically by the text.
$(document).ready(function () {
var $selector = $('#selector'),
$options = $selector.find('option'),
sortedOptions = [], i;
for(i = 0; i < $options.length; i += 1) {
sortedOptions.push([$($options[i]).text(), i]);
}
@wehrhaus
wehrhaus / app.js
Created April 24, 2014 01:52
Render `pretty` Jade templates via Express v3.x using 'pretty' flag
if (app.get('env') === 'development') {
app.use(function(req, res, next) {
app.locals.pretty = true;
next();
});
}
@wehrhaus
wehrhaus / Require.js config with noConflict jQuery released back into the wild
Last active August 29, 2015 14:00
Require.js config with noConflict jQuery released back into the wild
/js
/libs
jquery-private.js
jquery.js
config.js
@wehrhaus
wehrhaus / Super_Sub_Constructor_Pattern
Last active August 29, 2015 14:01
Superconstructor / Subconstructor Example
// Superconstructor
function Person(name) {
this.name = name;
}
Person.prototype.sayHelloTo = function (otherName) {
console.log(this.name + ' says hello to ' + otherName);
};
Person.prototype.describe = function () {
return 'Person name ' + this.name;
};
@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
@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)