/**
* Reliably adds a cache bust param to the url
* @param url: string
* @returns string
*/
function cacheBust(url) {
const urlObject = new URL(url, window.location.origin);
const paramsObject = new URLSearchParams(urlObject.search);
paramsObject.set("cacheBust", (new Date().getTime()).toString(36));
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Dislike Total (DT) is calculated | |
// by totaling the below 'mean' differences. | |
// The lowest DT is the winner. | |
function calcLeastDisliked(multiArray) { | |
const sum = array=>array.reduce((a,b)=>a + b, 0); | |
const singleArray = [].concat(...multiArray); | |
const avg = sum(singleArray) / singleArray.length; | |
return multiArray.map(ratings=>{ | |
const belowAvgRatings = ratings.filter(x=>avg > x, ratings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) 2021 Hunter Wilhelm | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro c-time | |
"Time an expression. Returns the time in milliseconds | |
Complexity: O(1) | |
- expr: an expression (not a lambda)" | |
[expr] | |
`(let [start# (. System (nanoTime)) | |
ret# ~expr] | |
(/ (double (- (. System (nanoTime)) start#)) 1000000.0))) | |
(defmacro benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a list of objects to a dictionary by one of their properties | |
* Assumes that all objects have the property and the value is unique | |
* | |
* @param {Array<Object>} objects - The array of objects | |
* @param {string} property - The property to turn the list of objects into Dict | |
* @return {Object<Object>} Dictionary of unmodified objects with the value | |
* of the properties as keys | |
*/ | |
function objectsToDictByProperty(objects, property) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @author Hunter Wilhelm | |
-module(prettyprintdict). | |
-export([pretty_print_dictionary/1]). | |
%%%-------- | |
%%% helper functions | |
%%%-------- | |
%% @doc The <kbd>isdict/1</kbd> function is a helper function that returns true if the | |
%% parameter is a dictionary. This function might not work in future updates of erlang if they |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
export function useReadDocumentTitle() { | |
const [title, setTitle] = useState(document.title); | |
useEffect(() => { | |
const titleElem = document.querySelector('title'); | |
if (!titleElem) return; | |
const observer = new MutationObserver(function (mutations) { | |
setTitle(mutations[0].target.textContent ?? ''); | |
}); |