Skip to content

Instantly share code, notes, and snippets.

@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) {
@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 / 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 / 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 / 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 / .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 / SIMD popcnt
Last active January 17, 2017 22:22
Calculated a the Hamming Weight (number of set bits) in a Single-Instruction Multi-Data type in JavaScript
// see http://stackoverflow.com/questions/109023/
let simd3 = SIMD.Uint32x4.splat(0x33333333);
let simd5 = SIMD.Uint32x4.splat(0x55555555);
let simd01 = SIMD.Uint32x4.splat(0x01010101);
let simd0F = SIMD.Uint32x4.splat(0x0F0F0F0F);
function popcnt(simd) {
simd = SIMD.Uint32x4.sub(simd, SIMD.Uint32x4.and(SIMD.Uint32x4.shiftRightByScalar(simd, 1), simd5));
simd = SIMD.Uint32x4.add(SIMD.Uint32x4.and(simd, simd3), SIMD.Uint32x4.and(SIMD.Uint32x4.shiftRightByScalar(simd, 2), simd3));
@JonathanGawrych
JonathanGawrych / LESS CSS slanted border
Created January 17, 2017 22:57
Implementing a slanted border between a top-right and bottom-left block
@bottom-left-bg-color: #ff0000;
@top-right-bg-color: #0000ff;
@border-color: #cccccc;
@border-width: 5px;
@slant-angle: 15deg;
@slant-height: 10px;
@slant-anti-aliasing: 20%
@slant-width: tan(@slant-angle) * @slant-height;
@slant-hypotenuse: @slant-height / cos(@slant-angle);
// 1 << bit == 1 << (bit % 32)
// 1 << 33 == 2
// need a structure to represent bit >= 32
var bit = 32;
[(bit >> 5 == 3) << bit,
(bit >> 5 == 2) << bit,
(bit >> 5 == 1) << bit,
(bit >> 5 == 0) << bit]

Keybase proof

I hereby claim:

  • I am JonathanGawrych on github.
  • I am jonathangawrych (https://keybase.io/jonathangawrych) on keybase.
  • I have a public key whose fingerprint is A680 6B2B A7AC FEB9 5CD2 1F37 5E23 FEF2 F8AC 3368

To claim this, I am signing this object: