Skip to content

Instantly share code, notes, and snippets.

View aaronbeall's full-sized avatar

Aaron Beall aaronbeall

View GitHub Profile
// ==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==
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];
@aaronbeall
aaronbeall / sortOn.ts
Created November 8, 2017 20:05
TypeScript array sortOn key
function sortOn<T>(array: T[], ...fields: (keyof T)[]) {
return array.sort((a, b) => {
for (const f of fields) {
if (a[f] > b[f]) return 1;
if (a[f] < b[f]) return -1;
}
return 0;
});
}
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;
}
// ---------- webpack.config.ts ---------- //
import * as path from "path";
import * as webpack from "webpack";
import * as loaders from "./webpack/loaders";
import { plugins } from "./webpack/plugins";
const config: webpack.Configuration = {
entry: {
app: './src/index.tsx',
styleguide: './styleguide/index.tsx'
@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'