Skip to content

Instantly share code, notes, and snippets.

View ThirdPartyNinjas's full-sized avatar

Jesse Chounard ThirdPartyNinjas

View GitHub Profile
// Note: Experimental code, probably not production useful!
// Get a unique identifier based on the type, without modifying the type
// This will be unique for the runtime of the program, but is based on execution
// order, so it will possibly change the next time the program runs.
// Don't serialize it!
using UniqueIdType = uint64_t;
struct UniqueIdBase
using System;
using System.Collections.Generic;
public class ShuffleBag<T>
{
public ShuffleBag() : this(-1) { }
public ShuffleBag(Int32 seed)
{
if(seed < 0)
@ThirdPartyNinjas
ThirdPartyNinjas / Vorbis.cs
Created August 15, 2019 19:29
FNA Vorbis Player
using Microsoft.Xna.Framework.Audio;
using System;
namespace Fenix.Audio
{
public class Vorbis : IDisposable
{
public int Channels { get; private set; }
public int SampleRate { get; private set; }
public float Duration { get; private set; }
@ThirdPartyNinjas
ThirdPartyNinjas / Coroutine.cs
Last active September 22, 2022 19:56
Simple Coroutines (for XNA/FNA/etc.)
using System.Collections;
using System.Collections.Generic;
namespace Memento
{
public class Coroutine
{
public bool Paused { get; set; }
internal void Reset(IEnumerator routine)
@ThirdPartyNinjas
ThirdPartyNinjas / msys_gcc_local.txt
Created May 23, 2017 15:58
Adding local search paths to MinGW/MSYS
Instructions copied from here: http://www.mingw.org/wiki/HOWTO_Use_the_GCC_specs_file
1) Check for an existing gcc specs file in <mingw-root>/lib/gcc/mingw32/<gcc-version>
2) If it doesn't exist, generate one
cd <mingw-root>/lib/gcc/mingw32/<gcc-version>
gcc -dumpspecs > specs
3) Add to the top of the specs file
*local_prefix:
@ThirdPartyNinjas
ThirdPartyNinjas / PiDay.cs
Last active March 12, 2018 20:52
Calculating Pi from random numbers
using System;
namespace PiDay
{
// The probability of two random numbers to be coprime is P = 6 / Pi^2
// So let's generate a bunch of random numbers. Figure out how often they're coprime.
// Use that percentage as our probabilty and solve for Pi.
// Pi = sqrt(6 / P)
// For more info, watch the video where I stole the idea: https://youtu.be/RZBhSi_PwHU
-- HUMAN RESOURCE MACHINE PROGRAM --
BUMPUP 14
BUMPUP 14
COPYTO 17
BUMPUP 14
COPYTO 18
BUMPUP 14
COPYTO 15
BUMPUP 14
@ThirdPartyNinjas
ThirdPartyNinjas / awful.c
Last active August 29, 2015 14:02
#define awfulness
#include <stdio.h>
#define return return 1 +
int ReturnFour()
{
return 4;
}
int main()
@ThirdPartyNinjas
ThirdPartyNinjas / ExportLibraryItems.jsfl
Last active May 14, 2021 09:36
Simple script to export Flash library items to png files. Doesn't check for invalid file names, and fails if the item is nested in multiple folders. Tested with Adobe Creative Cloud Flash Professional CC, (trial version)
//Usage:
//1) Save this file to disk.
//2) Load the target *.fla file in Flash.
//3) Commands | Run Command, Choose this file.
//4) Choose a target output folder, then sit back and wait.
fl.outputPanel.clear();
var outputScaleFactor = 2;