Skip to content

Instantly share code, notes, and snippets.

View mildfuzz's full-sized avatar

John Farrow mildfuzz

View GitHub Profile
name: compose
services:
bazarr:
container_name: bazarr
environment:
PGID: "1000"
PUID: "1000"
TZ: Europe/London
hostname: media-server
image: lscr.io/linuxserver/bazarr:latest
@mildfuzz
mildfuzz / useful.ts
Last active June 15, 2021 08:00
Useful Typescript
// returns an optional type of properties of T where type satisfies U
export type KeysOfValueType<T, U> = {
[K in keyof T]: T[K] extends U ? K : never
}[keyof T]
// returns an optional type of properties of T where T[prop]=string
export type StringsOf<T> = KeysOfValueType<T, string>
// example of getting only string values from an object in a generic
// https://github.com/microsoft/TypeScript/issues/44532
@mildfuzz
mildfuzz / prepare-commit-msg
Created September 25, 2019 12:35
.git/hooks/prepare-commit-msg
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@mildfuzz
mildfuzz / ComposableMutator.ts
Created July 22, 2019 13:11
ComposableMutator
type ComposableMutatorFn<T> = (t: T) => T;
export class ComposableMutator<T> {
constructor(private mutators: ComposableMutatorFn<T>[], private data?: T) {
this.mutators = mutators || [data => data];
}
public addMutator(fn: ComposableMutatorFn<T>): ComposableMutator<T> {
return this.dupe(fn);
}
@mildfuzz
mildfuzz / factorise.ts
Last active December 12, 2016 08:16
Factorise integers. Use the list of factors to find highest and lowest common denominators
function factors(x: number): number[] {
const f = [];
for(let i = 2; (i*i) <= x; i++) {
if(x % i === 0) {
f.push(i);
}
}
return f;
}
@mildfuzz
mildfuzz / improved music genie parser
Created June 7, 2016 08:39
likes all folders I like, skips and dislikes all folders I dislike
function parseGenie() {
var owner = $('#nowPlayingFolder').html();
if (/Farrow|dave|simon_mp3|tom|Jason|Sunya/.test(owner)) {
$('span[onclick="rate(1);"]').click();
}
if (/hannah|moosix|ben|Andy|Ryan|scattershot/.test(owner)) {
$('span[onclick="rate(-1);"]').click();
setTimeout(()=> {
$('#btNext').click();
@mildfuzz
mildfuzz / promise-generator-trigger.js
Created May 21, 2016 23:09
Using a generator to trigger a sequence of promises
function* triggerGen(res, rej) {
const result = yield;
if (result) {
res(result);
} else {
rej();
}
}
var trigger;
@mildfuzz
mildfuzz / .jshintrc
Created May 4, 2016 08:49
.jshintrc
{
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
@mildfuzz
mildfuzz / .jslintrc
Created May 4, 2016 08:43 — forked from irae/.jslintrc
my jslintrc
{
/*** Globals ***/
// To ignore any custom global variables, enable the `predef` option and list
// your variables within it.
"predef": [
"exports",
"YUITest",
"YUI",
"YUI_config",
"YAHOO",
@mildfuzz
mildfuzz / limiter.js
Created April 15, 2016 10:08
limiter
function limit(num, bottom, top) {
if (top < bottom) {bottom = top;}
if (num < bottom) {
return bottom;
}
if (num > top) {
return top;
}
return num;
}