Skip to content

Instantly share code, notes, and snippets.

View dcollien's full-sized avatar

David Collien dcollien

View GitHub Profile
@dcollien
dcollien / compressJson.js
Last active February 21, 2024 02:55
Compress JSON data to use in a URL (GZIP)
/*
Compress (gzip) JSON-serialisable object and output as base 64; Decompress base 64 data and output as parsed JSON.
Useful for URLs, e.g.
Compress:
const bigObject = { ...lotsOfData };
const url = "https://www.example.com/?" + await compressToUrl(bigObject);
@dcollien
dcollien / Canvas.tsx
Created March 20, 2024 01:23
React animated canvas component
import React, {
useRef,
useImperativeHandle
} from "react";
import useAnimationFrame from "../hooks/animationFrame";
type UpdateHandler = (dt: number, canvas: HTMLCanvasElement) => void;
export interface CanvasProps extends React.CanvasHTMLAttributes<HTMLCanvasElement> {
onAnimationFrame: UpdateHandler;
@dcollien
dcollien / decimalExpansion.js
Created December 5, 2024 11:09
Decimal Expansion (JS)
function decimalExpansion(numerator, denominator) {
// Special case for 0
if (denominator === 0) {
return null;
} else if (numerator === 0) {
return { whole: 0, nonRecurring: "", recurring: null };
}
const whole = Math.floor(numerator / denominator);
let remainder = numerator % denominator;
@dcollien
dcollien / App.css
Last active February 25, 2025 03:48
React Audio Recorder with Level Display
We couldn’t find that file to show.
@dcollien
dcollien / gist:ff527bdc6a14569cfa8036b5568d01b1
Last active March 12, 2025 11:53
A localized/i18n decimal expansion and recurring decimal rendering component for React
This has moved to: https://github.com/dcollien/react-decimal-expansion