Skip to content

Instantly share code, notes, and snippets.

View aaronbeall's full-sized avatar

Aaron Beall aaronbeall

View GitHub Profile
function uniqueArray<T>(array: T[], toUniqueValue?: (current: T) => any): T[] {
const values = toUniqueValue ? array.map(toUniqueValue) : array;
return array.filter((current, index) => values.indexOf(values[index]) == index);
}
// Example
const array = [{ id: 0, k: "a" }, { id: 1, k: "b" }, { id: 2, k: "a" }, { id: 3, k: "c" }];
const result = uniqueArray(array, item => item.k);
expect(result).toEqual([{ id: 0, k: "a" }, { id: 1, k: "b" }, { id: 3, k: "c" }]);
Array.from(document.querySelectorAll("*")).filter(elem => elem.scrollLeft > 0)
// ES6+TS port of mrdoob's stats.js
// Need this because lib.d.ts doesn't have Performance.memory
declare global {
interface Performance {
memory: any;
}
}
export class Stats {
// ==UserScript==
// @name Bitbucket Diff Improvements
// @version 1.0
// @description Adds features to Bitbucket Diff view:
// * Visual emphasis to more heavily changed files in the diff summary
// * Expand/collapse file diffs, auto-collapse package-lock.json
// * Back to top fixed link
// @author Aaron Beall
// @match https://bitbucket.org/*
// ==/UserScript==
function numberToText(num: number, numStrings: string[]): string {
let str = "";
do {
const r = num % numStrings.length;
num = Math.floor(num / numStrings.length);
str = `${numStrings[r]}${str}`;
} while (num > 0);
return str;
}
@aaronbeall
aaronbeall / youtube-playlist-duration.js
Last active August 10, 2023 19:49
Total hours in YoutTube playlist
(Array.from(document.querySelectorAll("#time-status #text")).map(node => node.textContent).reduce((total, text) => {
const [sec, min, hr = 0] = text.split(":").reverse();
return total + (parseInt(hr) * 60 * 60) + (parseInt(min) * 60) + parseInt(sec);
}, 0) / 60 / 60).toFixed(2);
// Example - https://www.youtube.com/playlist?list=PLvqxe4XbcSiErm2kHuldndImavib9wh8c
// Result: '55.51'