Skip to content

Instantly share code, notes, and snippets.

View dcollien's full-sized avatar

David Collien dcollien

View GitHub Profile
@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"
from datetime import datetime
import re
import string
def to_course_code(course_path, creation_date):
"""
Turns a course path into a short course code.
Max 14 characters (but likely under 10).
Not guaranteed to be unique
but has month/year of creation date, and single character hash
const uncurry = (fn) => (...args) => args.reduce((fn, arg) => fn(arg), fn);
const curry = (fn) => {
const collect = (args, arg) => {
const collected = args.concat([arg]);
return (
collected.length >= fn.length
? fn.apply(null, collected)
: collect.bind(null, collected)
);
};