Skip to content

Instantly share code, notes, and snippets.

function timeit(fn, count, pars)
{
performance.measure('start');
for(let i = 0; i < count; i++)
{
fn(...pars);
}
performance.measure('end');
starts = performance.getEntriesByName('start')
ends = performance.getEntriesByName('end')
@Mellen
Mellen / dev.to.spam.filter.js
Last active December 4, 2020 03:02
Filters out the posts from the dev.to feed that are obviously spam
// ==UserScript==
// @name dev.to spam filter
// @version 1
// @include http*
// @match *://dev.to/*
// @grant none
// @run-at document-end
// ==/UserScript==
const dev_posts = document.body;
@Mellen
Mellen / areSameWeek.js
Last active September 7, 2021 08:10
Detect if two dates are in the same week based on UTC time
function areSameWeeksUTC(date1, date2, boundaryDay=0)
{
if(date1 > date2)
{
let t = date1;
date1 = date2;
date2 = t;
}
if(((((date2 - date1)/1000)/3600)/24)>6)
@Mellen
Mellen / ordinalSuffix.js
Last active October 1, 2021 14:12
For any non-negative integer, this function supplies the correct English ordinal suffix.
function ordinalSuffix(n)
{
let units = n % 10;
let tens = n % 100;
let ord = (units > 3 || units < 1) || (tens > 10 && tens < 20) ? 'th' : (units == 1 ? 'st' : (units == 2 ? 'nd' : 'rd'));
return ord;
}
@Mellen
Mellen / string_multiplication.js
Last active July 21, 2022 07:48
Function that will multiply two string representations of numbers (strings that match /^(-?)(\d+)(([.])(\d+))?$/)
function multiply(a, b)
{
let am = a.match(/^(-?)(\d+)(([.])(\d+))?$/)
if(am === null)
{
throw `Format Error: ${a} is not a valid number`
}
let bm = b.match(/^(-?)(\d+)(([.])(\d+))?$/)
if(bm === null)
@Mellen
Mellen / partialise.js
Last active August 11, 2022 21:16
A function that will turn a normal javascript function into one that allows for partial application
(function()
{
function unaryCall(arg)
{
this.args = [];
return arg;
}
function partialise(initialFunction)
{
@Mellen
Mellen / boilerplate.html
Last active September 22, 2022 09:02
Biolerplate for HTML 5 files
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
</html>