Skip to content

Instantly share code, notes, and snippets.

View austindd's full-sized avatar

Austin Davis austindd

  • Colorado
View GitHub Profile
import React from 'react'
export default function useDarkMode({
intervalTime = 300,
getIsDark = defaultGetIsDark,
} = {}) {
// Keep track of the current mode
const [isDark, setIsDark] = React.useState(() => getIsDark())
// Set up the checker
// POLYFILLS
// Event.composedPath
// Possibly normalize to add window to Safari's chain, as it does not?
(function(E, d, w) {
if(!E.composedPath) {
E.composedPath = function() {
if (this.path) {
return this.path;
}
var target = this.target;
@akabe
akabe / extensible_record_by_lens.ml
Last active September 4, 2019 01:43
Extensible record by Lens trick in OCaml
(** The Lens trick: getter and setter for fields *)
type ('s, 'v) lens =
{
get: 's -> 'v;
set: 'v -> 's -> 's;
}
let id_lens = {
get = (fun x -> x);
set = (fun v _ -> v);
@dypsilon
dypsilon / examples.js
Last active April 28, 2024 08:52
Lazy Continuation Monad in JavaScript
const Cont = require('./lazy-continuation');
// pointed version
const c = Cont.of(5) // initial value
.chain((x) => {
return Cont.of(x + 5); // synchronous computation
})
.chain((x) => { // async computation
return new Cont((resolve) => {
setTimeout(() => resolve(x + 15), 500);
@jackrusher
jackrusher / abstract.md
Last active February 14, 2024 16:31
An old programming koan.

The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures."

Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and

@mohsen1
mohsen1 / reactor.js
Last active January 15, 2022 21:57
Reactor Pattern in JavaScript
function Event(name){
this.name = name;
this.callbacks = [];
}
Event.prototype.registerCallback = function(callback){
this.callbacks.push(callback);
}
function Reactor(){
this.events = {};