Skip to content

Instantly share code, notes, and snippets.

@RepComm
RepComm / settings.json
Created April 10, 2022 22:26
.vscode/settings.json - C language brackets on same line settings
{
"C_Cpp.vcFormat.newLine.beforeOpenBrace.namespace": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.type": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.lambda": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "sameLine",
"C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "sameLine",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google }",
}
@RepComm
RepComm / statemachine.ts
Created March 22, 2022 17:02
simple state managment in typescript
export interface JsonMap<T> {
[key: string]: T;
}
export interface TransitionJson {
delayMillis: number;
bidirectional?: boolean;
}
@RepComm
RepComm / strutils.c
Last active February 27, 2022 06:12
C string utilities
#ifndef STRUTILS_C
#define STRUTILS_C 1
#ifndef str
#define str char *
#endif
#include <stdlib.h>
#include <stdbool.h>
@RepComm
RepComm / bendfactor.js
Last active January 20, 2022 19:18
pipe bending gain factor calculation
const DEG2RAD = Math.PI / 180;
const perimeter = {
square (radius) {
return radius * 2 * 4;
},
circle (radius) {
return Math.PI * 2 * radius;
},
@RepComm
RepComm / glsl-helpers.glsl
Created November 16, 2021 18:28
glsl helpers
/*Sample an image at a reduced resolution*/
vec4 pixelate ( in sampler2D sampler, in vec2 uv, in float divs ) {
return texture(sampler,
vec2(
floor( uv.x * divs ),
floor( uv.y * divs )
) / divs
);
}
@RepComm
RepComm / anim.ts
Last active September 8, 2022 23:11
Bare bones number animation track in typescript
/**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 => {
@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
@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 / 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 / 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();