Skip to content

Instantly share code, notes, and snippets.

@IanSSenne
IanSSenne / main.rs
Created July 17, 2024 23:46
A small program to compute and animate (in the terminal) piston sequences from a config file.
use lazy_static::lazy_static;
use pathfinding::prelude::bfs;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
fs,
thread::sleep,
time::{Duration, Instant},
};
package;
import haxe.macro.ComplexTypeTools;
import haxe.Json;
import haxe.EnumTools;
import haxe.macro.ExprTools;
import haxe.macro.Expr;
import haxe.macro.Context;
class ExprUtils {
@IanSSenne
IanSSenne / readme.md
Last active February 22, 2023 06:44
minecraft position argument regex

Minecraft Like Command Parsing Using Regex

In this article I will talk about how I attempted to parse the position argument of a minecraft command using regex as well as describe the regex I used to do so.

Summary

During my time working with the gametest framework for minecraft I wrote a small framework for building out custom commands. One feature sometimes used is the ability to specify a position in the world for the command to use. to do this I used a regex to locate a portion of the syntax needed to specify a position. The regular expression /^([~^]-?\d*(?:\.\d+)?|-?\d+(?:\.\d+)?)/ has a couple of parts where it looks for a prefix, and then a partial or complete number, minecraft supports 2 prefix, ~ and ^ which are used to specify a relative position, and an absolute position respectively. This regex also supports negative numbers, and numbers with decimal points as well as numbers without a prefix.

Table of Contents

@IanSSenne
IanSSenne / example-input.ts
Last active January 29, 2023 10:45
code to transpile a limited subset of types into serializer/deserializer using bin-serde
/**
* FUNCTIONALITY EXAMPLE
*/
type PrimaryKeyA = {
$type: "a";
a: number;
};
type PrimaryKeyB = {
$type: "b";
b: string;
type discard = never;
type AppendArgument<Base, Next> = Base extends (...args: infer E) => infer R
? (...args: [...E, Next]) => R
: never;
type ArgumentResult<T> =
| {
success: true;
value: T;
raw: string;
push?: boolean;
@IanSSenne
IanSSenne / GametestDB.ts
Last active February 7, 2022 01:51
a small Persistant storage i wrote for minecrafts gametest 1.18.2 (free for anyone to use with credit)
import * as MC from "mojang-minecraft";
interface IStringSaver {
save(value: string): void;
load(): string;
hasData(): boolean;
}
class MemorySaver implements IStringSaver {
private _data: string;
constructor() {
this._data = "";
using Sandbox.Game.EntityComponents;
using Sandbox.ModAPI.Ingame;
using Sandbox.ModAPI.Interfaces;
using SpaceEngineers.Game.ModAPI.Ingame;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VRage;
let mcmodel_settings = new Action("Model Settings", {
name: intl.translate("actions.model_settings_name"),
id: "java_animation_edit_settings",
description: intl.translate("actions.model_settings_description"),
icon: "info",
condition: () => Format.id === format.id,
click: function () {
var dialog = new Dialog({
id: "project",
title: intl.translate("settings.dialog.title"),
@IanSSenne
IanSSenne / FWState.java
Created August 19, 2020 02:17
this was not very much fun to write :(
package com.iansenne.fw;
import java.util.ArrayList;
import java.util.
function.Consumer;
class FWStateHandler<T>{
FWState<T>handle(String name, T value) {
boolean exists = FWStateManager.current().has(name);
if (exists) {
return (FWState<T>) FWStateManager.current().get(name);
const html = new Proxy(
{},
{
get(target, p) {
return (props = {}, children = []) => {
const el = document.createElement(p);
for (let prop in props) {
if (typeof props[prop] === "function") {
el.addEventListener(prop, props[prop]);
} else {