Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

James Edward Lewis II lewisje

💭
I may be slow to respond.
View GitHub Profile
@lewisje
lewisje / keybase.md
Created Dec 7, 2019
verification for Keybase
View keybase.md

Keybase proof

I hereby claim:

  • I am lewisje on github.
  • I am lewisje (https://keybase.io/lewisje) on keybase.
  • I have a public key ASCMAUXVxmtQRyrx40JOErH18pznSvs4snXEkDzo4-SLKQo

To claim this, I am signing this object:

@lewisje
lewisje / lodash_browser_json_transformer.js
Last active Apr 3, 2016 — forked from leudanielm/lodash_browser_json_transformer.js
Lodash in-browser JSON transformer (should work back to IE6)
View lodash_browser_json_transformer.js
(function (document) {
'use strict';
/*
* LODASH in-Browser JSON transformer
* Use this in a bookmarket (save its contents in a bookmark) and whenever you open a JSON response (e.g. https://www.reddit.com/.json)
* you can use it to test lodash methods against the data.
* Lodash is exposed on window as _ and "json" global variable contains the data within the browser window.
*
* Copy the line below and save it as the url of a new bookmark (it's the same code as below but minified for bookmark use):
* javascript:!function(e){"use%20strict";function%20t(){s=JSON.parse(j.innerText||j.textContent),y.src=p,y.onload=n,e.head.appendChild(y)}function%20n(){window.json=JSON.parse(JSON.stringify(s)),i(window.json),m.oninput=o,e.body.appendChild(m),e.body.appendChild(x)}function%20o(e){var%20t,n=e||event,o=n.target||n.srcElement;return%20o.value?(t=a(o.value),void(t&&"object"==typeof%20t?(r(o,"success"),i(t)):r(o,"error"))):(i(s),void%20r(o,"success"))}function%20i(e){j.innerText?j.innerText=JSO
@lewisje
lewisje / dualPivotQuicksort.js
Last active Nov 20, 2020
Dual-Pivot Quicksort algorithm by Vladimir Yaroslavskiy, now with more input validation and support for (non-astral-plane-safe) string sorting (MIT License): https://web.archive.org/web/20151002230717/http://iaroslavski.narod.ru/quicksort/DualPivotQuicksort.pdf
View dualPivotQuicksort.js
// https://web.archive.org/web/20141119215047/http://jsperf.com/javascript-quicksort-comparisons
// based on work from Vladimir Yaroslavskiy: https://web.archive.org/web/20151002230717/http://iaroslavski.narod.ru/quicksort/DualPivotQuicksort.pdf
var dualPivotQuicksort = (function (Math, toString, undefined) {
'use strict';
function swap(arr, i, j) {
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
function dualPivotQuicksort(arr, comp, left, right, div) {
@lewisje
lewisje / nodeInsertion.js
Last active Mar 31, 2016
Encapsulates this hack from before MutationObservers existed (IE10+, no-ops on older browsers, MIT license): https://davidwalsh.name/detect-node-insertion
View nodeInsertion.js
var nodeInsertion = (function (document, undefined) {
'use strict';
function noop() {}
var result = {add: noop, remove: noop};
if (typeof String.prototype.trim !== 'function') return result; // Every browser that supports animations also has String#trim
// a stylesheet that holds our special keyframe code: https://davidwalsh.name/add-rules-stylesheets
var animName = ('node_' + Math.random() + '_inserted').split('.').join(''), sheet = (function () {
var style = document.createElement('style');
style.appendChild(document.createTextNode(['@-o-','@-moz-', '@-webkit-', '@', ''].join('keyframes ' +
@lewisje
lewisje / fnChain.js
Last active Feb 22, 2016 — forked from SeanJM/fnChain.js
A function which allows the augmentation of an Object with functional methods.
View fnChain.js
// Here is a JSFiddle with a concrete example: https://jsfiddle.net/SeanJM/rg3ftcgk/1/
// This is one of Sean's most leveraged functions, which he uses to keep my code nice and modular
function fnChain(target, source, args) {
'use strict';
var objProto = Object.prototype, hasOwn, chain, k;
if (objProto.toString.apply(args) !== '[object Array]') {
throw new TypeError('Invalid argument for "fnChain": The 3rd argument must be an array of arguments.');
}
hasOwn = objProto.hasOwnProperty;
chain = function chain(k) {
@lewisje
lewisje / DumpSource.url
Last active Nov 26, 2015
Crude "View Current Source" bookmarklet (public domain): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/plaintext
View DumpSource.url
javascript:document.documentElement.innerHTML='<plaintext>'+document.documentElement.innerHTML;
@lewisje
lewisje / OptimizationRevivers.js
Last active Aug 29, 2015
This gist encapsulates most uses of try/catch/finally blocks, a simple way to make functions from non-functions, and getting a reference to the global object, without triggering the optimization killers in V8: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax
View OptimizationRevivers.js
// part of a pair of functions intended to isolate code that kills the optimizing compiler
// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax
function functionize(func, arg) {
switch (typeof func) {
case 'string':
return arg ? new Function(String(arg), func) : new Function(func);
case 'function':
return func;
default:
return function () {return func;};