Skip to content

Instantly share code, notes, and snippets.

View lewisje's full-sized 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 December 7, 2019 01:48
verification for Keybase

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 April 3, 2016 09:43 — forked from monostere0/lodash_browser_json_transformer.js
Lodash in-browser JSON transformer (should work back to IE6)
(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 March 29, 2022 17:21
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
// 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 March 31, 2016 18:38
Encapsulates this hack from before MutationObservers existed (IE10+, no-ops on older browsers, MIT license): https://davidwalsh.name/detect-node-insertion
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 February 22, 2016 04:23 — forked from SeanJM/fnChain.js
A function which allows the augmentation of an Object with functional methods.
// 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 November 26, 2015 22:23
Crude "View Current Source" bookmarklet (public domain): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/plaintext
javascript:document.documentElement.innerHTML='<plaintext>'+document.documentElement.innerHTML;
@lewisje
lewisje / OptimizationRevivers.js
Last active August 29, 2015 14:25
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
// 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;};