Skip to content

Instantly share code, notes, and snippets.

View MoritzKn's full-sized avatar

Moritz Kneilmann MoritzKn

View GitHub Profile
@MoritzKn
MoritzKn / reverseArrayWithIterator.js
Last active April 27, 2021 20:26
Demo of generators and iterator
let a = [1, 2, 3, 4];
for (let item of a) {
console.log(item);
}
function* reverse () {
for (let i = a.length - 1; i >= 0; i--) {
yield a[i];
}
@MoritzKn
MoritzKn / nodeColors.js
Last active October 12, 2016 09:15
Terminal colors in Nodejs without extra dependencies
const util = require('util');
const colorize = (str, colorCodes) => `\x1b[${colorCodes[0]}m${str}\x1b[${colorCodes[1]}m`;
const bold = str => colorize(str, util.inspect.colors.bold);
const italic = str => colorize(str, util.inspect.colors.italic);
const underline = str => colorize(str, util.inspect.colors.underline);
const inverse = str => colorize(str, util.inspect.colors.inverse);
const white = str => colorize(str, util.inspect.colors.white);
const grey = str => colorize(str, util.inspect.colors.grey);
@MoritzKn
MoritzKn / rubberBandEffect.ts
Created February 17, 2020 13:13
Rubber Band Effect
function rubberBandEffect(
val: number,
lowerBounds: number,
upperBounds: number,
padding: number = 25,
): number {
const lowerLimit = lowerBounds - padding;
const upperLimit = upperBounds + padding;
if (val < lowerLimit) {
@MoritzKn
MoritzKn / smooth-expand.js
Last active February 21, 2020 14:09
POC Smooth Element Expand Animation
function getElementsAfter(el, {stopAt, skip, only} = {}) {
let elements = [];
while (el) {
while (el.nextElementSibling) {
el = el.nextElementSibling
elements.push(el)
}
while (el && !el.nextElementSibling) {
el = el.parentElement
@MoritzKn
MoritzKn / aligned-table.js
Last active December 18, 2020 18:15
Print aligned tables
function alignedTable({
alignments = [],
separator = ' ',
prefix = '',
suffix = '',
newLine = '\n',
rows = [],
} = {}) {
function toString() {
const lengths = {};
@MoritzKn
MoritzKn / fetchJson.js
Last active December 18, 2020 18:34
Fetch and validate JSON (the fetch wrapper that I write over and over again)
async function fetchJson(url, options, validate) {
const response = await fetch(url, options);
let json;
let jsonError;
try {
json = await response.json();
} catch (error) {
jsonError = error;
}
import NextAuth from "next-auth";
import AzureADProvider from "next-auth/providers/azure-ad";
// This really is the default config, the issue only occuries in combination
// with the Azure AD config and I can not give you my secrets.
// Please keep reading the issue, thank you :)
export default NextAuth({
providers: [
AzureADProvider({
@MoritzKn
MoritzKn / README.md
Last active June 2, 2023 14:58
Debug React.memo and changes in props

useDebugChanges

Debug when something changes in react. Relevant for React.memo, useMemo or useEffect.

Example usage:

import { memo, useState, useCallback } from "react";

interface ExampleProps {