Skip to content

Instantly share code, notes, and snippets.

View pomle's full-sized avatar

Pontus Alexander pomle

View GitHub Profile
const maxArea = Math.PI * max ** 2;
const pointArea = (point.intensity / max) * maxArea;
const value = Math.sqrt(pointArea / Math.PI);
const size = 8 + (value / max) * 24;
@pomle
pomle / react-vs-vue.md
Last active March 10, 2022 05:56
React vs. Vue

React vs. Vue

This text explains why I believe we should allow and prefer the React library for frontend development for client facing applications.

This document tries to be as objective as possible, except under the opinion section. I have not brought up issues that can be solved with lint rules or are already solved with tooling. I have also taken for granted that TypeScript is a given requirement for the organisation long term.

High importance issues

@pomle
pomle / sort.ts
Last active December 31, 2021 13:20
type Direction = "asc" | "desc";
export function sortBy<T>(val: (value: T) => number) {
return function sort(dir: Direction) {
const invert = dir === "asc" ? 1 : -1;
return function compare(a: T, b: T) {
return (val(a) - val(b)) * invert;
};
git_commit := $(shell git rev-parse --short HEAD)
export REACT_APP_VERSION := $(git_commit)
.PHONY: all
all: install test build start
.PHONY: install
install:
npm install
@pomle
pomle / useContentCache.ts
Last active December 20, 2022 17:54
Captain Hook's Fabulous Hooks
/*
Creates a sticky block of rendered content.
Useful when you want to memoize part of the render tree and optionally rerender.
*/
import { useMemo, useRef } from "react";
export function useContentCache(
renderer: () => React.ReactElement | undefined,
deps: any[]
const fib = (n) => {
let a = 0, b = 1, c;
for (let i = 0; i < n; i++) {
c = a;
a = b + a;
b = c;
}
return a;
}
>>SOURCE FORMAT FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
AUTHOR. Meth Meth Method
*> Example program using PERFORM, ACCEPT, TIMES
*> collect a number of user definable integers and mulitply them
*> with low memory footprint and display the result.
DATA DIVISION.

Find missing code

git log -S [text] --graph --oneline --decorate $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
import { useState, useEffect, useMemo } from "react";
import moment, { Moment, DurationInputArg2 as Unit } from "moment";
export const useLiveTime = (unit: Unit): Moment => {
const initial = useMemo(moment, []);
const [time, setTime] = useState<Moment>(initial);
useEffect(() => {
const nextTime = time
function between(subject, options = {}) {
const {rigidity, alias} = Object.assign({
rigidity: 10,
alias: new Map(),
}, options);
const keys = Object.keys(subject);
let last = Object.assign({}, subject);
let intended = subject;