Skip to content

Instantly share code, notes, and snippets.

View garettbass's full-sized avatar
🤓

Garett Bass garettbass

🤓
View GitHub Profile
@garettbass
garettbass / msvc_sections.c
Last active December 11, 2019 18:37
Enumerating section symbols with MSVC (https://rextester.com/TOUNK25484)
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
#include <stdio.h>
#define CONCAT(A, B) _CONCAT(A, B)
#define _CONCAT(A, B) A##B
#define TOSTRING(...) _TOSTRING(__VA_ARGS__)
#define _TOSTRING(...) #__VA_ARGS__
@garettbass
garettbass / clang_sections.c
Last active June 23, 2020 20:28
Enumerating section symbols with clang/gcc (https://repl.it/@garettbass/clangsections)
#include <stdio.h>
#define CONCAT(A, B) _CONCAT(A, B)
#define _CONCAT(A, B) A##B
#define TOSTRING(...) _TOSTRING(__VA_ARGS__)
#define _TOSTRING(...) #__VA_ARGS__
#ifdef SECTION_DEFINITIONS
#define _section_declaration_definition(SECTION) section_definition(SECTION)
@garettbass
garettbass / link.cpp
Created December 23, 2019 19:15
A simple embedded link and list
@garettbass
garettbass / typenameof.hpp
Last active January 27, 2020 19:53
Get the namespace-qualified name of a type without RTTI.
#include <stdint.h>
#include <stdio.h>
#include <string.h>
template<typename T>
const char* typenameof() {
#if defined(__clang__)
enum { header = sizeof("const char *typenameof() [T = ")-1 };
enum { footer = sizeof("]")-1 };
static char buffer[sizeof(__PRETTY_FUNCTION__)-(header+footer)] {};
@garettbass
garettbass / build.sh
Created May 5, 2020 01:10
This is the bash script I run to build C/C++ projects on Windows & macOS.
#!/usr/bin/env
CMDLINE="$0 $@"
#-------------------------------------------------------------------------------
function usage {
echo "Usage:"
echo ""
echo " sh $0 [options] <sources> [-- ...]"
@garettbass
garettbass / Utilities.cs
Created October 1, 2020 18:29
Some C# utility methods that came in handy recently
public static void Swap<T>(ref T a, ref T b) => (a,b)=(b,a);
public static void Sort<T>(ref T a, ref T b, ref T c, Comparison<T> comparison)
{
if (comparison(a, b) > 0) Swap(ref a, ref b);
if (comparison(a, c) > 0) Swap(ref a, ref c);
if (comparison(b, c) > 0) Swap(ref b, ref c);
}
@garettbass
garettbass / LocalPackageConverter.cs
Last active September 20, 2023 15:00
Convert Unity packages from Library/PackageCache into local packages. (more info in comments below)
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public static class LocalPackageConverter
using UnityEditor;
using UnityEngine;
using UnityEditor.Animations;
using System.IO;
public class CreateBlendTreeAsset
{
[MenuItem("Assets/Create/Animation Blend Tree", priority = 402)]
private static void CreateBlendTree()
{
@garettbass
garettbass / shaders.nim
Created March 15, 2021 01:19
WIP, translating Nim code to GLSL
import glm
import macros
import sets
import strformat
import strutils
import tables
macro shader*(n: typed) =
n.expectKind(nnkStmtList)
let astFile = n.lineInfoObj.filename & ".ast"
@garettbass
garettbass / type_index_generator.zig
Last active June 7, 2022 15:49
A generic type that maps provided types to monotonically increasing integers.
const std = @import("std");
pub fn TypeIndexGenerator(comptime TIndex: type) type {
const index_info = @typeInfo(TIndex);
const TInt = switch (index_info) {
.Int => TIndex,
.Enum => |t| if (t.is_exhaustive)
@compileError("TIndex enum must be non-exhaustive")
else
t.tag_type,