Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View aaronbeall's full-sized avatar

Aaron Beall aaronbeall

View GitHub Profile
@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'
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;
}
// ==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==
// 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 {
Array.from(document.querySelectorAll("*")).filter(elem => elem.scrollLeft > 0)
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" }]);
const flatten = array => (
array.reduce((accumulated, current) => accumulated.concat(
Array.isArray(current) ? flatten(current) : current
), [])
);
// Test
const before = [[1,2,[3]],4];
const after = flatten(before);
const expected = [1,2,3,4];
function arrayToMap<T, K extends keyof T>(array: T[], key: K): { [key: string]: T } {
return array.reduce((map, item) => ({
...map,
[`${item[key]}`]: item
}), {});
}
// Example
const array = [{ id: "a"}, { id: "b" }, { id: "c" }];
const byId = arrayToMap(array, "id"); // { "a": { id: "a"}, "b": { id: "b"}, "c": { id: "c"} }
Patching "plotOptions.series.dataLabels.filter.operator" with { doclet: { values: [Function: values] } }
Patching "plotOptions.tilemap.tileShape" with { doclet: { values: '["hexagon", "circle", "diamond", "square"]' } }
Patching "yAxis.tooltipValueFormat" with { doclet: { type: { names: [Array] } } }
Patching "chart.parallelAxes.title" with { doclet: { extends: 'xAxis.labels' } }
Type already exists for [plotOptions,ad,name] at [plotOptions.sma.name] of {String,}, removing own def with type {undefined}
Type already exists for [plotOptions,atr,name] at [plotOptions.sma.name] of {String,}, removing own def with type {undefined}
Type already exists for [plotOptions,atr,params,period] at [plotOptions.sma.params.period] of {Number,}, removing own def with type {undefined}
Removed all children of [plotOptions,atr,params] and no type information is left, removing def
Type already exists for [plotOptions,bb,name] at [plotOptions.sma.name] of {String,}, removing own def with type {undefined}
Type already exists for [p
type Color = string;
// Type definitions for Highcharts 6.0.3 (HEAD commit d351c6e on Fri Nov 24 2017 13:38:58 GMT+0100 (W. Europe Standard Time))
// Project: http://www.highcharts.com/
// Definitions generated from https://api.highcharts.com/
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
declare namespace Highcharts {
// plotOptions.ad.params