Skip to content

Instantly share code, notes, and snippets.

View NoelFB's full-sized avatar

Noel Berry NoelFB

View GitHub Profile
@NoelFB
NoelFB / StackUtf8.cs
Created October 5, 2023 04:45
Stack based UTF8 string in C#
using System.Buffers;
using System.Buffers.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
/// <summary>
/// Stack-based UTF8 string for ImGui.
/// I frequently want to do short string manipulation (ex. $"{Icon} Play!") and this
/// avoids allocating on the new strings every single frame.
@NoelFB
NoelFB / StackString.cs
Created October 5, 2023 04:43
simple stack-based C# string
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
/// <summary>
/// Stack-based String
/// </summary>
[InterpolatedStringHandler]
[SkipLocalsInit]
public unsafe struct StackString
{
@NoelFB
NoelFB / Gui.cs
Created September 18, 2023 04:36
Foster ImGuiNET Wrapper
using System.Diagnostics;
using System.Numerics;
using Foster.Framework;
using ImGuiNET;
public static class Gui
{
private static readonly VertexFormat VertexFormat;
private static IntPtr context;
private static bool beginCalled = false;
#include <blah.h>
#include "imgui/imgui.h"
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui_internal.h"
using namespace Blah;
namespace
{
MeshRef mesh;
@NoelFB
NoelFB / routine.h
Last active November 7, 2022 07:19
Simple C++ Coroutine using a switch statement internally
#pragma once
namespace YourNamespace
{
struct Routine
{
// Current "waiting time" before we run the next block
float wait_for = 0;
// Used during `rt_for`, which repeats the given block for X time
@NoelFB
NoelFB / aseprite-guid.lua
Created April 22, 2020 17:11
creating unique GUIDs for Aseprite files
-- This creates proper GUIDs for Aseprite files so the game can load them.
-- To Use:
-- 1) Open Aseprite and go to File -> Scripts -> Open Scripts Folder and place this file there
-- 2) Restart Aseprite
-- 3) Run this script when you save an Aseprite file and it will automatically create
-- GUIDs for the sprite along with every slice
-- More Info: https://www.aseprite.org/docs/scripting/
@NoelFB
NoelFB / Aseprite.cs
Last active May 10, 2024 01:44
ugly C# .ase (aseprite) parser
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
// File Format:
// https://github.com/aseprite/aseprite/blob/master/docs/ase-file-specs.md
// Note: I didn't test with with Indexed or Grayscale colors
@NoelFB
NoelFB / index.js
Created June 4, 2018 23:42
Javascript HTML template engine that just... runs JS in a vm
let data = {
title: "All My Posts",
posts: [
{ title: "first post", body: "nothing to see here" },
{ title: "second post", author: { name: "Somebody" }, body: "another post, wow" },
{ title: "final post", body: "this is the end" }
]
};
let fs = require("fs");
@NoelFB
NoelFB / Tile3D.cs
Last active November 2, 2021 16:24
3D Tile editor thing
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshCollider))]
[ExecuteInEditMode]
public class Tile3D : MonoBehaviour
@NoelFB
NoelFB / TerrainEditor.cs
Last active January 22, 2021 02:13
Terrain Thingy
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TerrainManager))]
public class TerrainEditor : Editor
{
private TerrainManager terrain { get { return (TerrainManager)target; } }
private Vector2Int? selected;