Skip to content

Instantly share code, notes, and snippets.

@GideonPARANOID
GideonPARANOID / parallel.yml
Created March 19, 2024 10:00
Dynamic parallelism for a triggerable GHA workflow
name: Dynamic parallelism
run-name: Dynamic parallelism ${{ github.ref_name }} with ${{ toJson(inputs) }}
on:
workflow_dispatch:
inputs:
parallelism:
description: How many jobs to run in parallel
required: true
type: string
default: '1'
@GideonPARANOID
GideonPARANOID / jitter.ts
Created March 15, 2024 15:59
Jitter a value with configurable amount, direction & precision.
export enum JitterDirection {
UP = 'up',
DOWN = 'down',
UP_DOWN = 'up_down',
}
/**
* @param {Number} value Value to jitter.
* @param {Number} factor How much jitter to apply.
* @param {JitterDirection} direction Whether to return bigger, smaller or either values.
@GideonPARANOID
GideonPARANOID / local-storage.ts
Last active November 16, 2021 08:09
Little hook for using Local Storage to save things.
import { useState } from 'react';
const marshall = (value: any) => JSON.stringify(value);
const unmarshall = (value: string) => JSON.parse(value);
const getBaseLS = <T>(getDefaultValue: () => T, key: string): T => {
const stored = window.localStorage.getItem(key);
if (stored) {
return unmarshall(stored) as T;
}

Ginger Oat Biscuits

Ingredients

  • 100g oats.
  • 100g sugar.
  • 100g self raising flour.
  • 100g hard margarine/unsalted butter.
  • 1tbsp golden syrup.
  • 1tsp bicarbonate of soda (or baking powder) dissolved in a little warm water.
@GideonPARANOID
GideonPARANOID / combine-unique.js
Last active March 16, 2018 08:58
Combines uniquely a list of lists of primitive values.
combineUnique(...list) {
return list
.filter((value) => value && value.length)
.reduce((total, current) => [ ...total, ...current ], [ ])
.reduce((total, current) => {
if (!total.find((value) => current === value)) {
total.push(current);
}
return total;
}, [ ]);
@GideonPARANOID
GideonPARANOID / blockable.decorator.js
Last active November 30, 2017 16:23
JS decorator which exposes a variable on an instance denoting that a (synchronous/asynchronous) method is running, with option to block subsequent calls
import * as _ from 'lodash';
/**
* @param {string} blockableKey property to attach to the instance to denote method activity
* @param {boolean} blocking option to disable subsequent calls to function while executing
* @return {object} function descriptor decorated for monitoring method activity
* @desc adds a property saying that the function is currently being called, useful for blocking ui
*/
export default (blockableKey, blocking = false) =>
(target, key, descriptor) => {
@GideonPARANOID
GideonPARANOID / length.sh
Created April 20, 2017 15:01
Calculating the number of lines in non-binary files in a directory
#!/bin/bash
total='0'
for i in `grep -r -I -l . .`; do
total=$(expr $total + `wc -l $i | awk '{ print $1 }'`)
done
echo $total
@GideonPARANOID
GideonPARANOID / cacheable.js
Last active April 26, 2017 14:30
Invalidable caching ES7 decorator, probably doesn't work
import * as _ from 'lodash';
export default (target, key, descriptor) => {
const { get, set } = descriptor;
return {
...descriptor,
get: function getAndCache() {
const isStatic = !_.isObject(this);
const cacheProperty = isStatic ? '__staticCache' : '__cache';
// checking for cache clearing properties
@GideonPARANOID
GideonPARANOID / .bashrc
Last active January 13, 2017 15:05
Probably very dangerous overrides for `cd` and `cat` to perform nicely with invalid inputs (file/directory)
# moves to path/opens file in vim
# @param path or file
function cd {
if [ -z $1 ]; then
builtin cd ~/
elif [ -d $1 ]; then
builtin cd "$1"
elif [[ $1 == \.\.\.* ]]; then
for (( i=0; i<`expr ${#1} - 1 `; i++ )); do
builtin cd ..
@GideonPARANOID
GideonPARANOID / ignore-deleted-files-commit.sh
Created January 6, 2016 07:17
Allows committing with locally deleted files & not removing them from the repo
git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin