Skip to content

Instantly share code, notes, and snippets.

View Lachee's full-sized avatar
📖
xkcd.com/1421/

Lake Lachee

📖
xkcd.com/1421/
View GitHub Profile
@Lachee
Lachee / UUID.php
Last active November 5, 2021 02:33
Packs / Unpacks a integer ID into a pseudo faux UUID's with signature to verify origins. Formatting is customisable.
<?php
// Required if you are putting in a namespace:
// namespace app\helpers;
// use InvalidArgumentException;
/**
* Packs / Unpacks a integer ID into a pseudo faux UUID's ( 8-8-12 ) with signature to verify origins.
* Not secure, but provides an abstraction layer to hide the true nature of your database.
*
@Lachee
Lachee / Example.cs
Created September 2, 2021 23:16
Singleton class
public class Level : Singleton<Level>
{
public void DoStuff();
}
void OtherAccess() {
Level.instance.DoStuff();
}
@Lachee
Lachee / EOLConversion.cs
Last active August 26, 2021 12:17
Utility Script to create EOL Conversions.
// Author: Lachee
// License: Public Domain - Do what you want with it
// Note: Script to convert line endings in unity so you dont get those annoying warnings.
// Simply put this script in a folder called Editor, then go Tools -> EOL Conversion -> Windows/Unix
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEditor;
@Lachee
Lachee / Example.cs
Last active August 22, 2025 02:26
Gets the available streams from Twitch. Useful for plugging into services such as ffmpeg.
// Starts a restream at 480p
async Task RestreamLowQuality(string channelName) {
var availableStreams = await Sniffer.GetStreamsAsync(channelName); // Fetch all the available streams
var stream = availableStreams.Where(s => s.QualityNo == 480).FirstOrDefault(); // Get just the 480, otherwise the best we can.
return BeginRestream(stream.Url); // Pass it to FFMPEG to restream it
}
// Starts FFMPEG to restream the url. This avoids SSL issues with OpenCV
private Process BeginRestream(string url, bool sync = false, bool verbose = false)
{
@Lachee
Lachee / VarData.cs
Last active May 12, 2021 02:23
Variable Data Type for C# and Unity3D
using System;
using System.IO;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#else
using System.Numerics;
#endif
namespace Lachee.Dynamic
@Lachee
Lachee / Example.cs
Last active January 11, 2023 14:12
Unity3D Singleton Class
using UnityEngine;
public class LevelManager : Singleton<LevelManager> {
private void Start() {
Debug.Log("This is a singleton!", LeveLManager.instance);
}
public IEnumerator SoftWaitExample() {
yield return LevelManager.wait;
@Lachee
Lachee / keyword.cs
Created February 1, 2021 06:56
I like keywords i guess
public class Why : Span<U>, IDisposable where U : struct
{
const sbyte BECAUSE_YES = 2;
public object Contents { get => (string)this; set { _ = value; } };
public void Dispose() { throw new NotImplementedException(); }
public static explicit operator string(Why y) { return "cause fuck you"; }
}
public async IAsyncEnumerable<T> OhGod<T>(T t) where T : Why
{
@Lachee
Lachee / permutations.js
Created November 28, 2020 04:30
Calculates a permutation of a size x size binary image.
/**
Generate a grid of all permutations of a binary (black and white) NxN pixel image (where n is between 2 and 5).
Then filter it so it removes:
all rotationally symmetric patterns ( rotating it 90 is considered the same patterns )
all non-contiguous patterns ( all the white islands must be connected )
all translationally the same patterns (dont know the term) ( if you move it some distance to the left, its considered the same pattern ) ( i solved this by cropping the image to best fit and then scaling back up )
The result hopefully should be unique tetris pieces
*/
const canvas = document.querySelector('canvas#shapes');
@Lachee
Lachee / style.scss
Last active December 9, 2024 17:23
Automatic Dark-Theme switching for GitHub pages.
---
---
@import "{{ site.theme }}";
/**
Custom dark theme for Github Pages, by Lachee.
Put this exactly /assets/css/style.scss in your GitHub Pages root.
*/
@Lachee
Lachee / Config.cs
Last active August 20, 2020 05:33
LazyKey is a class that allows for JSON configuration files that utilise separate files for secret tokens. I use this a lot with my bots so I can have a universal configuration, but gitignore .key. It keeps the pattern matching between the Config.cs and the Config.json, by allowing implicit conversion from a string filename. There was the potent…
class Config
{
public string Project { get; set; } = "AProject";
public string Repository { get; set; } = "ARepo";
public string Organization { get; set; } = "https://dev.azure.com/org";
public LazyKey Credentials { get; set; } = "devops.key";
}