Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Beall aaronbeall

View GitHub Profile
View numberToText.ts
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;
}
View bitbucket-diff-improvements.tampermonkey.js
// ==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==
View stats.ts
// 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 {
View findScrolledElements.js
Array.from(document.querySelectorAll("*")).filter(elem => elem.scrollLeft > 0)
View uniqueArray.ts
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" }]);
View flatten.js
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];
View arrayToMap.ts
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"} }
View highcharts-dts-output.txt
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
View highcharts.d.ts
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
View highcharts-missing-types.txt
Inferred type of "plotOptions.cmf.params.volumeSeriesID" as {string} from default value {"volume"}
Inferred type of "plotOptions.macd.groupPadding" as {number} from default value {0.1}
Inferred type of "plotOptions.macd.minPointLength" as {number} from default value {0}
Inferred type of "plotOptions.macd.pointPadding" as {number} from default value {0.1}
Inferred type of "plotOptions.vbp.dataLabels.style.fontSize" as {string} from default value {"7px"}
Inferred type of "plotOptions.vbp.crisp" as {boolean} from default value {true}
Inferred type of "plotOptions.vbp.pointPadding" as {number} from default value {0}
Inferred type of "plotOptions.bellcurve.intervals" as {number} from default value {3}
Inferred type of "plotOptions.bellcurve.pointsInInterval" as {number} from default value {3}
Inferred type of "plotOptions.series.label.style.fontWeight" as {string} from default value {"bold"}