Skip to content

Instantly share code, notes, and snippets.

@IgnusG
IgnusG / validations.js
Last active October 8, 2018 19:08
Playing around with string templates in JS (for validation)
const isArray = (o) => o.map !== undefined;
const generateValidation = (string, ...validationLiterals) => {
const [ head, ...strings ] = isArray(string) ? string : [string];
return (...validationArg) => {
const validationResults = validationLiterals.map((validation) => validation(...validationArg));
if (validationResults.every((e) => e === null)) {
return { valid: true };
}
@IgnusG
IgnusG / eslint-plugin-svelte3+2.7.3.patch
Created November 24, 2020 10:38
WARNING: This is an unofficial (unsupported) patch - stuff might break! - Credit goes to https://github.com/NicoCevallos
diff --git a/node_modules/eslint-plugin-svelte3/index.js b/node_modules/eslint-plugin-svelte3/index.js
index 86ec523..cba16d2 100644
--- a/node_modules/eslint-plugin-svelte3/index.js
+++ b/node_modules/eslint-plugin-svelte3/index.js
@@ -62,6 +62,15 @@ const get_line_offsets = str => {
return offsets;
};
+// find the index of the last element of an array matching a condition
+const find_last_index = (array, cond) => {

What is prototypical inheritance and how useful is it?

How can JavaScript be used to improve accessibility on the web?

What is event bubbling and how is it different to event capturing?

Bubbling is one of the 2 phases in event propagation. The other phase is called the capturing phase. The 2 phases are always run in the order: capturing then bubbling.

Events bubble from the target (source element) and move up the DOM tree to the root.

#!/bin/bash
is_git_repo() {
git rev-parse --show-toplevel > /dev/null 2>&1
result=$?
if test $result != 0; then
>&2 echo 'Not a git repo!'
exit $result
fi
}
@IgnusG
IgnusG / function-overloads.ts
Created January 31, 2023 17:39
Get parameters and their associated return types from overloaded signatures (does not work for generics)
/* eslint-disable @typescript-eslint/no-explicit-any */
type OverloadedProps<Signature> = Pick<Signature, keyof Signature>;
type OverloadedSignatureToUnionStep<
Signature,
PartialOverloadedSignature = unknown,
> = CurrentPiano extends FivePianos
? PartialOverloadedSignature
: Signature extends (
@IgnusG
IgnusG / areDaysBordering.ts
Last active May 7, 2025 12:22
date-fns additional helpers
import { differenceInDays } from 'date-fns';
/** Checks whether two days are bordering/adjacent to each other
*
* @example
*
* ```typescript
* areDaysBordering(new Date('2025-05-01'), new Date('2025-05-02')) === true
* areDaysBordering(new Date('2025-05-01'), new Date('2025-05-10')) === false
* ```