Skip to content

Instantly share code, notes, and snippets.

View katsaii's full-sized avatar
🟣
Icon by NightMargin

Kat katsaii

🟣
Icon by NightMargin
View GitHub Profile
@katsaii
katsaii / pool.gml
Last active September 3, 2022 22:34
A simple "ds_map" pooling example using probability to avoid constantly polling whether references are still alive. Technically unbound space complexity, but it is extremely unlikely to occur unless you're creating many new instances per frame without letting the garbage collector catch up.
/// @ignore
function __pool() {
static pool = [];
return pool;
}
function pool_get(container) {
var pool = __pool();
var poolMax = array_length(pool) - 1;
@katsaii
katsaii / factorial.rs
Last active March 7, 2022 11:07
A simple factorial function written in Rust
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
trait Factorialable<const N : usize> {
fn value() -> usize;
}
impl Factorialable<0> for () {
fn value() -> usize { 1 }
}
@katsaii
katsaii / RobloxRegionSpawner.lua
Last active January 3, 2022 21:00
A script for Roblox games that spawns parts within regions defined by `Start` and `End` controlpoints
local manager = script.Parent
-- helper function for colliding with humanoids
local function TouchedHumanoid(f)
return function(collider)
local parent = collider.Parent
if parent:FindFirstChildWhichIsA("Humanoid") then
f(parent)
end
end
@katsaii
katsaii / split_name.pl
Created March 15, 2021 04:12
Splits a name and displays all possible splits, prefixes and suffixes.
fst((A, _), A).
snd((_, B), B).
name("katsaii").
?-
name(Name),
findall((Prefix, Suffix), string_concat(Prefix, Suffix, Name), Pairs),
maplist(fst, Pairs, Prefixes),
maplist(snd, Pairs, Suffixes),
@katsaii
katsaii / main.pl
Created December 5, 2020 03:21
My first prolog program!
distance(A, B, Dist) :-
A = (X1, Y1),
B = (X2, Y2),
Dx is X2 - X1,
Dy is Y2 - Y1,
Dist is sqrt(Dx * Dx + Dy * Dy).
closest([X | Xs], Target, Min) :-
distance(X, Target, Dist),
closest_ext(Xs, Target, (X, Dist), Min).
@katsaii
katsaii / scr_defer.gml
Created August 19, 2020 13:04
Defer execution of a block until another block is complete.
/* Deferred Exeuction of Code
* --------------------------
* Kat @Katsaii
*/
#macro DEFER for (;; {
#macro UNTIL ; break; })
@katsaii
katsaii / scr_controllers.gml
Created July 1, 2020 13:43
Handles the creation of controller objects and parents, offering runtime errors in situations where there could be strange behaviour.
/* Singleton object utilities
* --------------------------
* Kat @Katsaii
*/
#macro __instance_create_layer_internal instance_create_layer
#macro __instance_create_depth_internal instance_create_depth
#macro instance_create_layer instance_create_checked_layer
#macro instance_create_depth instance_create_checked_depth
#macro PREFIX_SINGLETON "the"
@katsaii
katsaii / draw_curve.gml
Last active November 1, 2020 18:05
A function which lets you draw bezier cuves in GameMaker.
/// @desc Draws a bezier curve with 3 control points.
/// @param x1 {Real} The X coordinate of the first control point.
/// @param y1 {Real} The Y coordinate of the first control point.
/// @param x2 {Real} The X coordinate of the second control point.
/// @param y2 {Real} The Y coordinate of the second control point.
/// @param x3 {Real} The X coordinate of the third control point.
/// @param y3 {Real} The Y coordinate of the third control point.
/// @author Kat @katsaii
var x1 = argument0;
var y1 = argument1;
@katsaii
katsaii / string_tokenise.gml
Last active February 7, 2020 11:12
Tokenises a string into an array of strings and numbers, where anything between double quotes is considered a string.
/// @desc Tokenises a string into a list of values.
/// @param str {String} The string to tokenise.
/// @author Kat @katsaii
var str = argument0;
var tokens = [];
var len = string_length(str);
for (var i = 1; i <= len; i++) {
var prefix = string_char_at(str, i);
if (char_is_whitespace(prefix)) then continue;
var value = undefined;
@katsaii
katsaii / quicksort.c
Created October 15, 2019 22:20
Sorts an array and removes any duplicate elements.
#include <stdio.h>
#include <stdlib.h>
void swap(int* a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
return;
}