Skip to content

Instantly share code, notes, and snippets.

@JonathanGawrych
JonathanGawrych / .gitignore
Created January 21, 2016 00:15
Java .gitignore template
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
@JonathanGawrych
JonathanGawrych / Sort.js
Created January 9, 2015 00:22
Simple sort toggle to be used with angular's sortBy. Allows multilevel sorting.
var defaultSortBy = 'lastName';
var sortBy = defaultSortBy.slice();
function toggleSortBy(sort) {
// if we are using default, switch to array.
if (typeof sortBy === 'string')
sortBy = [];
// if the value is in decending order
if (sortBy.indexOf('-' + sort) !== -1) {
// remove it
@JonathanGawrych
JonathanGawrych / mapAssociative.js
Created January 6, 2015 22:29
Bullet-proof function to transform an array into a map using a callback function to determine the key
// Similar to Array.prototype.map, this function takes an array-like object and turns it into an associative map
// Instead of the callback function being used to transform the value in the returned array, it is called to get
// the key instead. Unlike map, this function will use the second param in place of `this`, if `this` isn't bound
function mapAssociative(callback, thisArg) {
var arr, len;
/*jshint validthis:true */
arr = this || thisArg;
/*jshint validthis:false */
if (arr === window) {
@JonathanGawrych
JonathanGawrych / fonts.less
Last active November 18, 2015 21:47
Less Font Stacks from cssfontstack.com
@weight-thin: 100;
@weight-extra-light: 200;
@weight-light: 300;
@weight-normal: 400;
@weight-book: 400;
@weight-regular: 400;
@weight-medium: 500;
@weight-demi-bold: 600;
@weight-bold: 700;
@weight-heavy: 800;
@JonathanGawrych
JonathanGawrych / is global item
Last active August 29, 2015 14:07
determine if an object is a global object/constructor (based if it's non-enumerable properties of window)
// get all native objects key names (include non-enumerable properties)
var windowItems = Object.getOwnPropertyNames(window);
// exclude deprecated browser items to avoid console warnings
// the tradeoff is 'isOnWindow' will incorrect report false for these items
var deprecatedItems = ['webkitIDBTransaction',
'webkitIDBRequest',
'webkitIDBObjectStore',
'webkitIDBKeyRange',
'webkitIDBIndex',
@JonathanGawrych
JonathanGawrych / Angular transformRequest Date Long
Last active August 29, 2015 14:07
transformRequest to make requests made with angular transform Date objects into the long time, rather than iso string
// untested. Probably works. based off of angular's toJsonReplacer
transformRequest: [function(d) {
// why is angular.isFile or angular.isBlob not exposed? Who knows! Code copied here
if (!angular.isObject(d) ||
Object.prototype.toString.call(d) === '[object File]' ||
Object.prototype.toString.call(d) === '[object Blob]') {
return d;
}
return JSON.stringify(d, function(key, value) {