Skip to content

Instantly share code, notes, and snippets.

View thygrrr's full-sized avatar
infinite loop

tiger tiger tiger thygrrr

infinite loop
View GitHub Profile
@thygrrr
thygrrr / CollectionsBenchmarks.cs
Last active November 6, 2024 08:27
.NET Benchmark of Frozen, Immutable, and normal Generic Collections
// SPDX-License-Identifier: Unlicense
// Inspired by https://okyrylchuk.dev/blog/when-to-use-frozen-collections-in-dotnet/
using System.Collections.Frozen;
using System.Collections.Immutable;
using BenchmarkDotNet.Attributes;
namespace Benchmark.Conceptual;
[ShortRunJob]
@thygrrr
thygrrr / Damp.cs
Last active November 6, 2024 10:07
C# Damping for Godot et al
//SPDX-License-Identifier: MIT
using System.Runtime.CompilerServices;
using Godot;
using Vector3 = System.Numerics.Vector3;
namespace Jovian.Math
{
public static class Damp
{
@thygrrr
thygrrr / CameraZoomAndPan.gd
Last active November 6, 2024 10:10
Godot Zoom and Pan, smooth & cursor-centric Camera2D motion
# SPDX-License-Identifier: Unlicense or CC0
extends Node2D
# Smooth panning and precise zooming for Camera2D
# Usage: This script may be placed on a child node
# of a Camera2D or on a Camera2D itself.
# Suggestion: Change and/or set up the three Input Actions,
# otherwise the mouse will fall back to hard-wired mouse
# buttons and you will miss out on alternative bindings,
# deadzones, and other nice things from the project InputMap.
@thygrrr
thygrrr / MixerGroupSlider.cs
Last active November 6, 2024 10:11
Unity MixerGroupSlider, a better-than-logarithmic AudioMixerGroup fader GUI Slider that is more pleasant and intuitive for the users to use, and utilizes the entire value range of its slider. Furthermore, fader values are serialized in PlayerPrefs.
//SPDX-License-Identifier: Unlicense
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
namespace Tiger.Audio
{
[RequireComponent(typeof(Slider))]
@thygrrr
thygrrr / Swizzles.cs
Last active November 24, 2023 14:38
I typed up some Swizzles for y'all!
This file has been truncated, but you can view the full file.
//SPDX-License-Identifier: Unlicense
using UnityEngine;
using Unity.Mathematics;
using System.Runtime.CompilerServices;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
namespace Tiger.Swizzles
@thygrrr
thygrrr / QuaternionUtil.cs
Created October 20, 2023 15:32 — forked from maxattack/QuaternionUtil.cs
Some Helper Methods for Quaternions in Unity3D
using UnityEngine;
/*
Copyright 2016 Max Kaufmann ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
@thygrrr
thygrrr / wordle.py
Last active September 2, 2023 15:28
Wordle Back-Solver, for final result and scores, how many legal games are there?
# SPDX-License-Identifier: Unlicense OR CC0-1.0+
words = [w.lower().strip() for w in open("words.txt", "r").readlines()]
print("loaded", len(words), "Words")
def match(word: str, final: str, score: chr, index: int) -> bool:
return (score == "G" and word[index] == final[index]) or \
(score == "W" and word[index] not in final) or \
(score == "Y" and word[index] != final[index] and word[index] in final)
@thygrrr
thygrrr / Loggers.cs
Last active November 6, 2024 10:11
Unity Loggers, zero-boilerplate drop-in replacement logger in 25 lines of code
//SPDX-License-Identifier: Unlicense OR CC0-1.0+
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
// ReSharper disable MemberCanBePrivate.Global
namespace Loggers
{
/// <summary>
@thygrrr
thygrrr / pomodoro.ps1
Last active November 6, 2024 10:12
Powershell Pomodoro Timer, locks the workstation when timer expires
# SPDX-License-Identifier: Unlicense
if ($args.count -eq 0)
{
write-host "Pomodoro Timer that locks the workstation (screen) when done."
write-host "Usage: pomodoro.ps1 <minutes> ['activity']"
write-host "Example: pomodoro.ps1 5 try out new script"
Exit
}
# Select default activity if none is specified, otherwise concat all optional arguments
@thygrrr
thygrrr / ControlSystem.cs
Last active February 5, 2022 12:43
A ECS system where a physical object can "cut" through a turn and glide like a ship or a bird.
using Jovian.ECS.Components;
using Jovian.ECS.Components.Space;
using Jovian.ECS.Components.Vessels;
using Jovian.ECS.Systems.Physics;
using Unity.Burst;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Physics.Systems;