Skip to content

Instantly share code, notes, and snippets.

View gosoccerboy5's full-sized avatar
🎮
Check out my new game!

gosoccerboy5

🎮
Check out my new game!
View GitHub Profile
@gosoccerboy5
gosoccerboy5 / circumscribe.js
Last active March 28, 2023 02:24
Get the equation, center, and radius of a circle given 3 points on its circumference.
/**
* circumscribe(Number x1, Number y1, Number x2, Number y2, Number x3, Number y3)
*
* Returns an object describing the circle's center, radius, and equation in Standard Form.
* Returns an error if points are overlapping or on the same line.
* Example: `circumscribe(5, -3, -1, -3, 2, -6)` returns {circumcenter: [2, -3], equation: "(x-2)²+(y+3)²=9", radius: 3}
**/
function circumscribe(x1, y1, x2, y2, x3, y3) {
// It took some math to figure this out but I'll never tell you how 😈
@gosoccerboy5
gosoccerboy5 / spellingbee.js
Created January 9, 2023 02:29
Gives you the answers to NYT spelling bee. Paste it in the console once you have the game on your screen
(function() {
const solutions = window.gameData.today.answers;
let list = document.createElement("div");
list.style = `position:fixed;width:15%;height:40%;left:2%;top:30%;
border:5px solid black;z-index:999;padding:5px;background:white;
overflow-y:scroll;resize:both;`;
document.body.append(list);
list.innerHTML = `<h2 style='cursor:all-scroll;user-select:none;font-size:20px;'>Word list</h2>
<hr/><ul></ul>`;
let listEl = list.children[2];
// ==UserScript==
// @name Hide Upvote Count
// @description Hides upvote count on posts and comments on Reddit
// @match *://*.reddit.com/*
// @version 0.0.0.0.1
// @developer gosoccerboy5
// ==/UserScript==
(function() {
'use strict';
@gosoccerboy5
gosoccerboy5 / area.js
Last active May 10, 2022 16:58
Find the perimeter or area of a polygon from a set of points
/**
* area(Array<Array<Number>> ...list)
*
* takes in a set of points (in clockwise or counterclockwise order) and returns the area of the polygon the points form
* example call: `area([3, 10], [9, 7], [11, 2], [2, 2]);`
**/
function area(...list) {
let total = 0;
for (let index = 0; index < list.length; index++) {
@gosoccerboy5
gosoccerboy5 / findMidpointFromPointsAndRatio.js
Last active April 21, 2022 20:35
Random math crap that helps you with tedious school math
// Find a point between two points that fits a certain ratio of distance to both of them
function findMidpointFromPointsAndRatio(a, b, c, d, f = 1, g = 1) {
/**
Example: The coordinates of the endpoints of Line ST are S(10, 2) and T(17, 16).
Point U is on ST and divides it such that SU:TU is 2:5.
How the function would be called: findMidpointFromPointsAndRatio(10, 2, 17, 16, 2, 5);
What it should return: Array [12, 6]
**/
const h = f+g;
return [a + f*(c-a)/h, b + f*(d-b)/h];
@gosoccerboy5
gosoccerboy5 / quadratic.js
Last active March 25, 2022 20:08
A small API that can give information about a quadratic equation, including vertex, zeros, y-intercept, and coefficients.
// Parse a quadratic, find its coefficients, and feed it into the "quadratic" function
function parseQuadratic(input) {
const refined = input.toLowerCase().replaceAll(" ", "");
// A regex that matches and finds the coefficients in a quadratic in the format ax^2+bx+c
const matches = refined.match(/(-?[0-9.]*)[a-z]\^2(?:([+-][0-9.]*)[a-z])?([+-][0-9.]*)?/)
.slice(1) // We don't want the first value (which is the full match)
.map(str => Number( // we will convert our refined coefficients from a string to a number
(str ?? "0") // If the current item in the matches list is undefined, it was not provided, the coefficient will be 0
.replace(/^[+-]?$/, x => x + "1"))); // If we have only +/- or even no coefficient along with the x, we assume it is 1
@gosoccerboy5
gosoccerboy5 / nextEvent.dart
Last active October 19, 2021 13:49
Await the next event occurring on an element.
// Use this to await the next event occurring on an element.
/* Usage example:
await querySelector("#myButton").next("click");
print("Button clicked!");
*/
import "dart:html";
import "dart:async";
extension on Element {
@gosoccerboy5
gosoccerboy5 / numbersasfunctions.dart
Last active July 25, 2021 22:06
Using numbers - as functions
const pi = 3.1415;
extension NumbersAsFunctions on num {
num call(num other) => this * other;
}
void main() {
print(2(pi)); // 6.283
}
@gosoccerboy5
gosoccerboy5 / _trim-whitespace.dart
Last active July 19, 2021 15:18
A recreation of trim-whitespace.html on my formatting-help repository.
import "dart:html";
final input = querySelector("#input") as TextAreaElement;
final target = querySelector("#output") as TextAreaElement;
final number = querySelector("#amount") as InputElement;
final trigger = querySelector("#trigger") as ButtonElement;
// Setup elements
void main() {
input.addEventListener("input", (Event event) {
@gosoccerboy5
gosoccerboy5 / _tabs-to-spaces.dart
Last active August 27, 2021 20:41
A recreation of tabs-to-spaces.html on my formatting-help repository.
import "dart:html";
final input = querySelector("#input") as TextAreaElement;
final output = querySelector("#output") as TextAreaElement;
final radio = querySelector("#tabs2spaces") as RadioButtonInputElement;
final button = querySelector("#button") as ButtonElement;
final spacesPerTabs = querySelector("#spacesPerTabs") as InputElement;
// Setup elements
void main() {