This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. get list of branches merged to dev, filter out dev and master, without spaces in the beginning | |
# 2. delete each branch | |
git branch --merged dev --list "[!dev|master]*" --format "%(refname:short)" | ForEach-Object { git branch $_ -d } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibonacci(n) { | |
return Math.round((Math.pow(1.618033988749895, n) - Math.pow(-0.618033988749895, n)) / 2.23606797749979); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Getters and setters are not enumerable and, obviously, neither are private fields. | |
*/ | |
class MetadataObject extends Object { | |
#metadata = undefined; | |
get metadata() { return this.#metadata; } | |
set metadata(value) { this.#metadata; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. get list of branches merged to dev, filter out dev and master | |
# 2. delete each branch | |
git branch --merged dev --list "[\!dev|master]*" | xargs -n 1 git branch -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inspired by https://markus.oberlehner.net/blog/usestate-and-usereducer-with-the-vue-3-composition-api/ | |
import { readonly, ref, UnwrapRef } from "vue"; | |
// "corporate" version | |
export function useState<T>(initialState: T | undefined) { | |
type InitialState = T | undefined; | |
type State = UnwrapRef<T> | undefined; | |
type StateFn = (currentState: State) => State; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use this as the callback function for an Array.map that returns a partial | |
* object. It's the functional equivalent of the Pick type. | |
* | |
* @example | |
* const arr = [{a: 1, b: 1, c: 1}, {a: 2, b: 2, c: 2}] | |
* const oldWay = arr.map(({ a, c }) => ({ a, c })); | |
* const newWay = arr.map(pick("a", "c")); | |
*/ | |
function pick<T extends object, K extends keyof T>( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I started building this, then came across a more robust solution: | |
* {@link https://github.com/therealparmesh/object-to-formdata} | |
*/ | |
import { isPlainObject } from "is-plain-object"; | |
type Value = string | Blob | number | boolean | null | undefined | Date; | |
function convert<T extends Value>(value: T): string | Blob { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inspired by this article by Rafael Bardini: | |
* {@link https://rbardini.com/making-optional-properties-nullable-typescript/} | |
*/ | |
type NullUnion<T> = T | null; | |
// type NullableProps<T> = { | |
// [K in keyof T]: NullUnion<T[K]> extends T[K] ? K : never; | |
// }[keyof T]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum BinaryEnum { | |
One = 0b0001, | |
Two = 0b0010, | |
Four = 0b0100, | |
Eight = 0b1000, | |
} | |
const keys = Object.keys(BinaryEnum).filter(x => isNaN(Number(x))) as (keyof typeof BinaryEnum)[]; | |
const values = Object.values(BinaryEnum).filter(x => typeof x === 'number') as number[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('focusin', (e) => console.log(e.target), true); |