Skip to content

Instantly share code, notes, and snippets.

@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>
@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 / 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 / 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 / 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 / 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;
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 / currentIP.py
Created July 11, 2020 12:06
A script for Sky customers to email out their external IP address when it changes
#! /usr/bin/env python
from urllib.request import urlopen, Request
import urllib
import base64
from bs4 import BeautifulSoup
import os.path
import time
import smtplib
def main():
@Mellen
Mellen / poker.py
Last active January 4, 2023 11:32
Rank poker hands.
VALUE_ORDER = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
class PokerHand:
def __init__(self, cards):
self.cards = []
self.rankName = ''
self.original = cards
for card_str in cards:
self.cards.append(Card(card_str.upper()))
self.highest = self.cards[0]
@Mellen
Mellen / day10.js
Last active December 11, 2019 17:29
AoC 2019 day 10
function Asteroid(position)
{
this.position = position;
this.slopes = new Map();
}
Asteroid.prototype.slopeAndDistance = function(other)
{
let xdiff = (other.position.x - this.position.x);
let ydiff = (other.position.y - this.position.y);