Skip to content

Instantly share code, notes, and snippets.

View dcollien's full-sized avatar

David Collien dcollien

View GitHub Profile
@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 / 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 / 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 / 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 / artStyles.json
Created July 9, 2023 17:49
JSON lists of art styles and artists useful for image prompts (midjourney, stable diffusion)
[
{
"label": "1850's Daguerrotype",
"value": "Daguerrotype",
"filters": [
"photography",
"digital art"
]
},
{
@dcollien
dcollien / index.html
Last active May 5, 2020 12:39
xAPI iFrame Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>xAPI Form Example</title>
<!-- xAPI base functionality, from: https://github.com/RusticiSoftware/TinCanJS/blob/master/build/tincan-min.js -->
<script src="tincan-min.js"></script>
<!-- Setting up the xAPI connection from launch data -->
<script src="xapi-interface.js"></script>
@dcollien
dcollien / AnimatedCanvas.tsx
Last active February 12, 2020 08:51
Animated Canvas Component
import React, { useRef, useEffect, useCallback, useState } from "react";
type UpdateHandler = (dt: number) => void;
type ContextRenderer = (ctx: CanvasRenderingContext2D) => void;
export interface IAnimatedCanvasProps {
width: number;
height: number;
onFrame: UpdateHandler;
render: ContextRenderer;
Moved to: https://github.com/dcollien/mp4filechecker/blob/master/src/index.ts
<html>
<head>
<title>Simple xAPI Example</title>
<script src="tincan-min.js"></script>
</head>
<body>
<p>This is an xAPI Example</p>
<button type="button" id="complete-button">Send Completion Statement</button>
<span id="status"></span>
<script>
import time
import urllib.parse
import hmac
import hashlib
import base64
SB_NAME = "ol-events"
EH_NAME = "ol-user-metrics"
SAS_NAME = "collect-user-metric"
SAS_VALUE = "EXAMPLE-TOKEN"