Skip to content

Instantly share code, notes, and snippets.

View jshcrowthe's full-sized avatar

Josh Crowther jshcrowthe

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jshcrowthe on github.
  • I am jshcrowthe (https://keybase.io/jshcrowthe) on keybase.
  • I have a public key ASCKd2-KHXSwnLsJCrcw6nNvv9bC8s9_8bFAplynScOSlgo

To claim this, I am signing this object:

@jshcrowthe
jshcrowthe / chunkArray.js
Last active February 28, 2018 05:18
Basic Array Chunking Function
function* chunkArray(dataset = [], offset = 5) {
let start = 0;
while (start < dataset.length) {
const chunk = dataset.slice(start, start + offset);
yield chunk;
start += offset;
}
}
@jshcrowthe
jshcrowthe / possibly.js
Last active November 3, 2017 09:20
yeoman/insights ApplicationInisights Provider Sandboxing
module.exports = {
// ALL THE OTHER PROVIDERS ARE HERE
applicationinsights(id, payload) {
/**
* This feels like it's in the right direction, IDK
*/
const ai = require('applicationinsights');
/**
* I'm assuming that the tracking code is the instrumentationId,
@jshcrowthe
jshcrowthe / index.html
Last active September 13, 2017 18:49
Demo consuming a module with Webpack
<html>
<head>
<script src="/main.js"></script>
</head>
</html>
@jshcrowthe
jshcrowthe / index.browser.esm.js
Last active August 10, 2021 21:06
test-module
console.log('Loaded test-module via pkg.browser');
export function logModule() {
console.log('`logModule` called in test-module');
}
export function totallyUnused() {
console.log('I go totally unused!');
}
@jshcrowthe
jshcrowthe / clientRect-iterable.js
Last active May 9, 2017 22:00
Iterable ClientRects
ClientRect.prototype[Symbol.iterator] = function() {
// ClientRect's properties apparently can't be discovered with Object.keys :(
const obj = Object.assign({}, {
top: this.top,
right: this.right,
bottom: this.bottom,
left: this.left,
height: this.height,
width: this.width,
});
@jshcrowthe
jshcrowthe / debounce-fxn.js
Last active April 19, 2018 20:59
Javascript Event Debounce (Run function X only once after Y ms)
function debounce(fn, delay) {
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
@jshcrowthe
jshcrowthe / throttle-fxn.js
Created January 26, 2017 22:13
Javascript Event Throttle (Run function X once every Y ms)
function throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) {
@jshcrowthe
jshcrowthe / hashCode.js
Last active July 14, 2016 20:59
String.prototype.hashCode
String.prototype.hashCode = function() {
var hash = 0;
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
@jshcrowthe
jshcrowthe / conditional-polyfill.js
Last active July 14, 2016 19:03
Conditionally Load WC Polyfill
var webComponentsSupported = ('registerElement' in document
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template'));
if (!webComponentsSupported) {
var wcPoly = document.createElement('script');
wcPoly.src = '/bower_components/webcomponentsjs/webcomponents-lite.js';
wcPoly.async = true;
(document.head || document.getElementsByTagName("head")[0]).appendChild(wcPoly);
}