Skip to content

Instantly share code, notes, and snippets.

@metanomial
metanomial / minesweeper.js
Created February 2, 2019 04:26
Generates minesweeper for Discord
// Use CLI flag --size <number> (or -s <number>) to set board dimensions
// Use CLI flag --count <number> (or -c <number>) to set bomb count
const argv = require('minimist')(process.argv.slice(2))
const minesweeper = require('minesweeper')
const size = Math.max(Math.floor(Number(argv.size || argv.s)) || 8, 4)
const count = Math.min(Math.max(Math.floor(Number(argv.count || argv.c)) || Math.floor(size**2 / 6), 4), size**2)
const mineArray = minesweeper.generateMineArray({
@metanomial
metanomial / clipbot.js
Last active April 16, 2019 22:47
Universal Paperclips Bot (In-progress, v16)
let marginAdjust = 0
setInterval(function() {
// Find and research ready active projects
const readyProject = activeProjects.find(project => project.cost())
if(readyProject) return readyProject.effect()
// Free-will era
if(humanFlag) {
@metanomial
metanomial / autolike.js
Created October 14, 2019 01:32
Systematically like all YouTube videos in a playlist. Watch out for autoplay
// Skip delay in milliseconds
// Raise if your connection is slow
const delay = 8000;
function autolike() {
const likeButton = document.querySelector('button[aria-label^=like]')
const nextButton = document.querySelector('.ytp-next-button')
if(!isSelected(likeButton)) likeButton.click()
nextButton.click();
setTimeout(autolike, delay)
function polynomial(...coefficients) {
return function(x) {
let result = 0;
for(const [index, coefficient] of coefficients.entries()) result += coefficient * x ** index;
return result;
}
}
@metanomial
metanomial / example.js
Last active December 4, 2019 22:37
ECMAScript Class Enum Block
class Color {
enum {
RED(0xff0000),
GREEN(0x00ff00),
BLUE(0x0000ff)
}
constructor(hex) {
hex %= 0x1000000;
this.red = hex >> 0x10;
this.green = (hex >> 0x8) % 0x100;
@metanomial
metanomial / Email.js
Last active December 6, 2019 09:02
AWS Lambda Mail Forwarder
const AWS = require('aws-sdk');
/**
S3 service interface
@type {S3}
@see {@link https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html}
**/
const s3 = new AWS.S3({
signatureVersion: 'v4'
});
@metanomial
metanomial / rationals.js
Last active December 13, 2019 06:32
Rational Number Class and Utilities
/**
Check if value is a float-point number
@param {value} value
@return {*}
**/
function isFloat(value) {
const float = Number.parseFloat(value);
return !Number.isNaN(float) && float % 1 !== 0;
}
@metanomial
metanomial / bigint-abs.js
Created December 13, 2019 22:12
BigInt.prototype.abs
Object.defineProperty(BigInt.prototype, 'abs', {
get() {
return this.valueOf() < 0n
? this.valueOf() * -1n
: this.valueOf();
}
})
(15n).abs; // 15n
(-5n).abs; // 5n
Math.symbol = {
ceil: Symbol('Math.symbol.ceil')
};
class ComplexNumber {
constructor(a, b) {
this.a = a;
this.b = b;
}
toString() {
import { UUIDGen } from './utils/UUID.js';
const uuidGen = UUIDGen();
// Object property definition method
class User {
constructor() {
Object.define(this, 'uuid', {
value: uuidGen.next(),
writable: false,
configurable: false