Skip to content

Instantly share code, notes, and snippets.

@RepComm
RepComm / WinCursorParser.js
Last active March 26, 2024 05:41
Windows Cursor (*.CUR) | Icon (*.ICO) Parser in Node
/* Built using Matthew Sachin's documentation as reference
* https://github.com/MathewSachin/NIco/wiki/Ico,-Cur-and-PE-Formats
* See example function 'test'
*
* Abilities:
* Read a cursor or icon file and get it's image data (raw)
*
* Future plans:
* Read and then parse into different data sets for convenience like:
* 1d arrays of hex/web colors, or int colors
@RepComm
RepComm / owot_draw_lines.js
Last active January 12, 2020 04:18
A WIP (functional) script to draw lines by clicking (hold control and click), soon to come: Filling shapes. Click w/o ctrl key to reset shape drawing.
var ctrlIsDown = false;
var fillChar = "▓";
var points = [{x:undefined,y:undefined},{x:undefined,y:undefined}];
var lastPointModified = false; //false = 1, true = 2
var cursorCoordsGlobal = {x:0,y:0};
function onClick (evt) {
if (evt.button != 0) return;
@RepComm
RepComm / math.js
Created January 30, 2019 19:51
Some math functions I need to stop copying
let pi = 3.141592653589793; //All the digits I could remember..
let radians = (degrees) => degrees * (pi / 180);
let degrees = (radians) => radians * (180 / pi);
let lerp = (a, b, c) => a + c * (b - a);
let dist = (x1, y1, x2, y2) => Math.sqrt(
Math.pow(x1 - x2, 2) +
Math.pow(y1 - y2, 2)
);
@RepComm
RepComm / owotanim.js
Created January 11, 2020 23:24
OurWorldOfText Preservation Animation WIP
/**Get char from world coordinates
* @param {Integer} x world coordinate
* @param {Integer} y world coordinate
*/
let getCharFromXY = (x, y)=> {
return getChar(
Math.floor(x / 16),
Math.floor(y / 8),
x - Math.floor(x / 16) * 16,
y - Math.floor(y / 8) * 8
@RepComm
RepComm / mc.snippet01.js
Created March 6, 2020 00:28
Random Color Concrete Tool - Spigot/ScriptCraft snippet
//Imports
//Aliases
var PlayerInteractEvent = org.bukkit.event.player.PlayerInteractEvent;
var Material = org.bukkit.Material;
//List of concrete colors
var concreteColors = [
Material.BLACK_CONCRETE,
@RepComm
RepComm / mc.snippet02.js
Created March 6, 2020 01:06
Replace & with text format control char - Spigot/ScriptCraft plugin snippet
//Imports
//Aliases
var PlayerChatEvent = org.bukkit.event.player.PlayerChatEvent;
//Event listener
function onPlayerChat (evt) {
//Get the message
var msg = evt.getMessage();
@RepComm
RepComm / scriptcraft-sphere.js
Created March 29, 2020 21:16
spigot-scriptcraft-sphere.js
function sphere (worldname, x, y, z, diameter, clearMethod) {
var Material = org.bukkit.Material;
if (clearMethod === undefined) clearMethod = "none";
var r = diameter/2;
var w = server.getWorld(worldname);
if (!w) throw "No world by name of " + worldname;
var b = w.getBlockAt(x, y, z);
var bl = b.getLocation();
var bv = bl.toVector();
@RepComm
RepComm / turtle.js
Last active April 13, 2020 23:01
A turtle for ourworldoftext.com
class OWOTPos {
static TileWidth = 16;
static TileHeight = 8;
constructor() {
this.tileX = 0;
this.tileY = 0;
this.charX = 0;
this.charY = 0;
this.x = 0;
@RepComm
RepComm / lerp.ts
Created March 3, 2021 01:43
Lerp and Inverse Lerp
/**Linear interpolation between from and to, using 0.0 - 1.0 interpolant `by`*/
export const lerp = (from: number, to: number, by: number): number => {
return from*(1-by)+to*by;
}
/**Performs the inverse of lerp
* Will give you the interpolant given the interpolated number and its bounds (to and from)
*/
export const inverseLerp = (from: number, to: number, value: number): number => {
return (value - from) / (to - from);
@RepComm
RepComm / user-kick.sh
Created May 30, 2021 19:03
Kick a linux user off every pts/# session they're connected with
#!/bin/bash
# example usage: ` ./user-kick jon ` - kicks 'jon' pts sessions off
# this works by mapping username to pts port, then pts port to process id, and killing the process with kill -9
# commands run:
# 'who' - for finding pts ports
# 'grep' - for filtering command output
# 'ps' - for listing processes by their pts port
# 'kill' - for terminating the process ids