This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function index(...n) { | |
const base = 26; | |
const base0 = base * 10; | |
const aCode = 'a'.charCodeAt(0); | |
const z = String.fromCharCode(base - 1 + aCode); | |
return n.map(function(n) { | |
let ret = String.fromCharCode(Math.floor(n / 10) % base + aCode) + String(Math.floor(n % 10)); | |
while (n >= base0) { | |
ret = z + ret; | |
n -= base0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function partialDeepEquals(a, b) { | |
if (!a || typeof a !== 'object') { | |
if (b instanceof RegExp) { | |
return b.test(a); | |
} | |
return a == b; | |
} | |
if (Array.isArray(a)) { | |
if (!Array.isArray(b)) { | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function midSuffle(a) { | |
var length = a.length; | |
var mid = Math.floor(length / 2); | |
var b = [a[mid]]; | |
b.length = length; | |
for (var i = 1; i < length; i++) { | |
if (i % 2 === 0) { | |
b[i] = a[mid + i / 2]; | |
} else { | |
b[i] = a[mid - ((i + 1) / 2)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let seen = new WeakMap(); | |
function safeJson(key, value) { | |
if (key.startsWith('_') || key.startsWith('$')) return; | |
if (typeof value === 'function') return; | |
if (typeof value === 'bigint' || typeof value === 'symbol') { | |
return String(value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* genBirthdayChances(length) { | |
for (let i = 0; i < length; i++) { | |
yield [ 1, 1, 0.0019126241045620209 ]; | |
yield [ 1, 2, 0.0022844959626743748 ]; | |
yield [ 1, 3, 0.0026541586810355663 ]; | |
yield [ 1, 4, 0.002704723435339952 ]; | |
yield [ 1, 5, 0.0026885230771647606 ]; | |
yield [ 1, 6, 0.0026782137583260023 ]; | |
yield [ 1, 7, 0.0026816501979389216 ]; | |
yield [ 1, 8, 0.0026043303066482343 ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class StyleMap extends Map { | |
toString(space, newline) { | |
let style = ''; | |
for (let [key, value] of this) { | |
style += key; | |
style += ':'; | |
if (typeof space === 'number') { | |
for (let i = 0; i < space; i++) { | |
style += ' '; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function base64url(base64) { | |
return String(base64).replace(/[^A-Za-z0-9_-]/g, m => | |
m === '+' ? '-' : | |
m === '/' ? '_' : | |
'' | |
); | |
} | |
export function base64standard(base64) { | |
base64 = String(base64).replace(/[^A-Za-z0-9+/]/g, m => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {boolean} [noDashes=false] Set to true to remove hyphens in output. | |
* @returns {string} The output UUID string. | |
*/ | |
export default function uuidGen(noDashes) { | |
return [ | |
('00000000' + Math.floor(Math.random() * 0x100000000).toString(16)).slice(-8), | |
('0000' + Math.floor(Math.random() * 0x10000).toString(16)).slice(-4), | |
('0000' + Math.floor(Math.random() * 0x10000).toString(16)).slice(-4), | |
('0000' + Math.floor(Math.random() * 0x10000).toString(16)).slice(-4), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Promise.any is the inverse of Promise.all | |
* | |
* Promise.all = reject first error or resolve all successes | |
* Promise.any = resolve first success or reject all errors | |
*/ | |
Promise.any = function(promises) { | |
return Promise.all(promises.map(p => { | |
return p.then( | |
resolve => { throw resolve; }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Show User-ID on Twitter | |
// @namespace larryc5 | |
// @version 1.0 | |
// @description Gets the ID of the user and puts it in the URL. | |
// @author Larry Costigan | |
// @include /^https?:\/\/(?:[^\/?#.]+\.)*twitter\.com\/[^\/?#]+(?:[\?#].*)?$/ | |
// @require https://code.jquery.com/jquery.min.js | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/larryc5/a1b7271f2ba8ef0cf2d26a6577167ed8/raw/twitter-show-id.user.js |