Skip to content

Instantly share code, notes, and snippets.

@Mellen
Mellen / binarise.js
Last active May 29, 2019 19:24
This turns any positive integer into its binary representation, but as an integer, so it's not really binary. Just a fun thing I figured out.
var p = Math.log(20)/Math.log(2) - 1;
function binarise(x)
{
if(x === 0)
{
return 0;
}
if(x === 1)
@Mellen
Mellen / SE Temperature Conversion Chat Commands
Last active November 2, 2018 10:32
grease monkey script for Stack Exchange chat that allows other users to force you to tell them the result of converting from one temperature scale to another
// ==UserScript==
// @name Chat Commands
// @namespace StackScripts
// @description commands that can be executed in chat
// @version 1
// @grant none
// @include http://chat.stackexchange.com/rooms/1/sandbox
// @include http://chat.stackexchange.com/rooms/35/the-bridge
// @author http://english.stackexchange.com/users/3559/matt-%D0%AD%D0%BB%D0%BB%D0%B5%D0%BD
// ==/UserScript==
@Mellen
Mellen / index.html
Last active January 22, 2017 01:44
Sandpiles
<!DOCTYPE html>
<html>
<head>
<title>sandpile</title>
</head>
<body>
<canvas id="canv" width="300" height="300"></canvas>
<script src="js/sandpile.js" type="text/javascript"></script>
</body>
</html>
@Mellen
Mellen / string_distance.py
Last active May 2, 2018 06:30
A way of calculating the distance between 2 strings
def string_distance(s1, s2):
allchars = ''.join(sorted(set(s1+s2)))
s1vals = [allchars.index(c) for c in s1]
s2vals = [allchars.index(c) for c in s2]
diffs = [abs(x-y) for x,y in zip(s1vals,s2vals)]
lengthdiff = abs(len(s1)-len(s2))
return sum(diffs)+lengthdiff
@Mellen
Mellen / disk_use_analysis.py
Created March 11, 2019 17:46
A method for seeing how a disk (on MS Windows) is used.
#! python
import os
import shutil
import argparse
import json
parser = argparse.ArgumentParser(description='Creates a report about the distribution over folders of disk use.')
parser.add_argument('drive_letter', nargs=1, metavar='drive letter', help='The drive that should be analysed.')
@Mellen
Mellen / replaceNumericEntities.js
Last active August 30, 2019 10:05
Replacing number based html entities with characters, either hex or decimal.
const NORMAL = 0;
const FOUNDAMP = 1;
const FOUNDHASH = 2;
const FOUNDX = 3;
const FOUNDHEX = 4;
const GOTENTITY = 5;
const FOUNDDEC = 6;
function replaceNumericEntities(input)
{
@Mellen
Mellen / day9.js
Last active December 10, 2019 21:33
AOC day 9
function Processor(instructions)
{
this.instructions = instructions.map(i => i);
this.instructionPointer = 0;
this.input = [];
this.inputPointer = 0;
this.output = null;
this.running = false;
this.sendOutput = null;
this.relativebase = 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);
@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 / 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():