Skip to content

Instantly share code, notes, and snippets.

View TheGreatRambler's full-sized avatar
🎯
Focusing

TheGreatRambler TheGreatRambler

🎯
Focusing
View GitHub Profile
@TheGreatRambler
TheGreatRambler / distancebetweentwopoints.js
Last active December 20, 2017 22:50
Simple function to get distance between two points with an added twist --- in order to prevent performance problems with squaring large numbers and getting the square root of their addition, the smallest x and y values are set as zero and the largest are set as the difference between the two points. This way, the performance is better.
function distancebetweentwopoints(x1, y1, x2, y2) {
if (x1 > x2) {
x1 = x1 - x2;
x2 = 0;
} else {
x2 = x2 - x1;
x1 = 0;
}
if (y1 > y2) {
y1 = y1 - y2;
@TheGreatRambler
TheGreatRambler / arrayruiner.js
Last active February 15, 2018 17:12
Use this function to randomly ruin a array by splitting it up and inserting those chunks in random places.
function randomlySplitArray(inputarray, chunksize, numofloops) {
function randomint(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var temparray = inputarray;
for (var q = 0; q < numofloops; q++) {
var start = randomint(0, inputarray.length - chunksize);
var othertemp = temparray.splice(start, chunksize);
var index = randomint(0, temparray.length - chunksize - 1);
// https://stackoverflow.com/questions/7032550/javascript-insert-an-array-inside-another-array
@TheGreatRambler
TheGreatRambler / headers.js
Created March 4, 2018 21:48
Get headers of file from ajax request
function returnheaders(ajaxrequest) {
var headers = ajaxrequest.getAllResponseHeaders();
var arrofheaders = headers.trim().split(/[\r\n]+/);
var mapofheaders = {};
arrofheaders.forEach(function (line) {
var parts = line.split(': ');
var header = parts.shift();
var value = parts.join(': ');
mapofheaders[header] = value;
});
@TheGreatRambler
TheGreatRambler / webworkerfunc.js
Last active March 24, 2018 17:47
A function that can be used to run functions in web workers
// Function that can run a function supplied in a web worker
// MIT License Copyright TheGreatRambler
// Free to use
function runInWebWorker(func, argsarray, callback) {
// func: function to use
// argsarray: the arguments to pass
// callback: the callback function
var blobdata = 'var returnstatement=(' + func.toString() + ')(' + argsarray.join(",") + ');self.postMessage(returnstatement);self.close();';
console.log(blobdata);
var blobURL = URL.createObjectURL(new Blob([blobdata], {
@TheGreatRambler
TheGreatRambler / cowsay.sh
Last active April 18, 2018 01:05
Cowsay fun
#!/bin/bash
# copyright TheGreatRambler
# List all cowsay cows with a fun fortune!
stringtouse="$(fortune)"
timesaround=0
for i in $(cowsay -l)
do
if (($timesaround > 2))
@TheGreatRambler
TheGreatRambler / diep.js
Last active May 7, 2018 21:59
Win quizlet live! Not working yet.
// wshook.js
var wsHook={};
(function(){function e(a){this.bubbles=a.bubbles||!1;this.cancelBubble=a.cancelBubble||!1;this.cancelable=a.cancelable||!1;this.currentTarget=a.currentTarget||null;this.data=a.data||null;this.defaultPrevented=a.defaultPrevented||!1;this.eventPhase=a.eventPhase||0;this.lastEventId=a.lastEventId||"";this.origin=a.origin||"";this.path=a.path||[];this.ports=a.parts||[];this.returnValue=a.returnValue||!0;this.source=a.source||null;this.srcElement=a.srcElement||null;this.target=a.target||null;this.timeStamp=
a.timeStamp||null;this.type=a.type||"message";this.__proto__=a.__proto__||MessageEvent.__proto__}var d=wsHook.before=function(a,c){return a},g=wsHook.after=function(a,c){return a};wsHook.resetHooks=function(){wsHook.before=d;wsHook.after=g};var f=WebSocket;WebSocket=function(a,c){this.url=a;var b=(this.protocols=c)?new f(a,c):new f(a);var d=b.send;b.send=function(a){arguments[0]=wsHook.before(a,b.url)||a;d.apply(this,arguments)};b._addEventListener=b.addEventListener;b.addEventListen
@TheGreatRambler
TheGreatRambler / bundle.min.js?1579794062
Last active January 23, 2020 16:41
Paddle Force Mod
(function() {
var MEMORY_KEYS_KEY, MEMORY_MAX_ITEMS, slice = [].slice, extend = function(child, parent) {
for (var key in parent) {
if (hasProp.call(parent, key))
child[key] = parent[key]
}
function ctor() {
this.constructor = child
}
ctor.prototype = parent.prototype;
@TheGreatRambler
TheGreatRambler / index.js
Created August 21, 2020 03:43
Get valid MC names from a text file
const lineByLine = require("n-readlines");
const axios = require("axios");
const fs = require("fs");
function has(str, char) {
return str.indexOf(char) !== -1;
}
const liner = new lineByLine("./words.txt");
var outFile = fs.createWriteStream("validnames.txt");
@TheGreatRambler
TheGreatRambler / ColorfulLife.js
Created June 3, 2022 23:48
Cleanup of code from jaxry/colorful-life to run on your own website, including typescript implementation
(function() {
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
if(!gl) {
alert('Could not load WebGL');
}
class Renderer {
constructor(canvas, gl, renderWidth, renderHeight) {
@TheGreatRambler
TheGreatRambler / overengineered_bit_moving.cpp
Created June 20, 2022 23:47
Overengineered bit moving (right shifts only)
uint64_t src = start + size;
uint64_t dest = new_start + size;
if(src % 8 != 0) {
uint8_t b = bytes[src >> 3] >> (8 - src % 8) & ((1UL << (src % 8)) - 1);
if(dest % 8 == 0) {
bytes[(dest >> 3) - 1] &= 0xFF << (src % 8);
bytes[(dest >> 3) - 1] |= b;
// std::cout << "1" << std::endl;