Skip to content

Instantly share code, notes, and snippets.

@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 (
#!/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
}

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.

@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) => {
@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 / parks&rec.md
Created July 31, 2018 14:55
My favorite quotes from Parks and Rec

Best Quotes

  • Which one citizen described as "Disturbingly Enticing"
  • That's my husband. ... Who's he carying?
  • Either you hire her back or I quit! ... You don't work for me
  • You couldn't remember your phone number. But you gave me your phone
  • You're trying to lure this young lady into your van? ... Yeah?! But she's being really difficult about it
  • Greg, your service is crap.
  • You forgot to paint a painting son
  • You can wait at that table and someone will be here sometime. ... But aren't you here now? ... No
@IgnusG
IgnusG / books.md
Last active July 12, 2019 17:41
Books to Read
  • The Art of War
  • How to talk TED
  • Debt: years
  • Start with Why?
  • Leaders eat last
  • Aufm Weg zur finanzieller Freiheit
  • Adversaries into allies (Bob Burg)
@IgnusG
IgnusG / git-superfixup.pl
Last active April 13, 2022 12:59 — forked from oktal3700/git-superfixup.pl
Perl script for automating the process of creating fixup! commits for use with git rebase -i --autosquash
#!/usr/bin/perl
# Scan unstaged changes in git tracked files, identify which commits they could
# be applied to as fixups, and automatically produce the appropriate "fixup!"
# commits for use with "git rebase -i --autosquash".
#
# Copyright (C) 2016, 2017 by Mat Sutcliffe
# This program is free software; you can redistribute it and/or modify it under
# the GNU General Public License as published by the Free Software Foundation;
# either version 2 of the License, or (at your option) any later version.
@IgnusG
IgnusG / order_by_array.rb
Last active February 23, 2018 19:02
Orders one array according to another array
objects = []
order = %w(first second)
objects
.group_by(&:order_by_this) # Create grouping according to field
.each { |_, h| h.sort_by!(&:sort_each_by_this).reverse! } # Each hash sorted individually
.values_at(*order) # Sorting according to order
.compact # Reject empty hash keys (no elements for order item)
.flatten(1) # Remove hash table
.concat(objects.reject { |o| order.include? o.order_by_this }) # Append all unidentified at the end
function detectSeparator(input) {
const availableSeparators = [ ';', ',', '|' ];
const separatorCount = availableSeparators.map((separator) => occurrences(input, separator));
return R.transpose([ availableSeparators, separatorCount ])
.reduce((maxSeparator, separator) => {
return separator[1] > maxSeparator[1] ? separator : maxSeparator;
}, [ availableSeparators[0], -1 ])[0];
}