Skip to content

Instantly share code, notes, and snippets.

View otac0n's full-sized avatar

John Gietzen otac0n

View GitHub Profile
@otac0n
otac0n / regexes.txt
Last active September 2, 2016 19:33
Cleaning Regexes
Remove trailing whitespace:
Pattern: [ \t]+(?=[\r\n])
Replace: ""
Replace tabs with spaces:
Pattern: (?<=^([^\t\r\n]{4})*)\t
Replace: " "
Pattern: (?<=^([^\t\r\n]{4})*[^\t\r\n]{1})\t
Replace: " "
Pattern: (?<=^([^\t\r\n]{4})*[^\t\r\n]{2})\t
// Copyright (c) 2013, 2014 Masato Hagiwara
// https://github.com/mhagiwara/camxes.js
// Copyright (c) 2018 John Gietzen
// This source is subject to the MIT license. Please see license.md for more information.
// Originally from http://users.digitalkingdom.org/~rlpowell/hobbies/lojban/grammar/index.html
@using System.Linq;
@members
{
private static string _join(IEnumerable<object> items)
{
void Main()
{
GetPassFailRateWithConfidence(10, 2, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(100, 20, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(1000, 200, 0.95).ToString().Dump();
GetPassFailRateWithConfidence(10000, 2000, 0.95).ToString().Dump();
}
public ErrorRate GetPassFailRateWithConfidence(long passes, long fails, double confidence)
{
@otac0n
otac0n / SexAndGender.linq
Last active May 5, 2025 21:51
A theory of sex and gender.
// My opinions are my own.
public class PseudobicerosHancockanus : Flatworm { }
public abstract class Flatworm : Animal
{
public Flatworm() : this(Sex.Male | Sex.Female) { }
public Flatworm(Sex sex) : base(sex) { }
}
@otac0n
otac0n / VotingSystems.linq
Created October 2, 2020 06:17
Voting Systems
void Demo<T>(IEnumerable<IEnumerable<T>> ballots, int seats, IEqualityComparer<T> comparer = null)
{
var elections = new Dictionary<string, Tuple<IElection<T>, ITieBreak<T>[]>>
{
["STV"] = Tuple.Create<IElection<T>, ITieBreak<T>[]>(
new SingleTransferableVoteElection<T>(),
new ITieBreak<T>[]
{
new BordaCountTieBreak<T>(),
new ApprovalCountTieBreak<T>(),
@otac0n
otac0n / MartingaleSimulation.linq
Last active August 6, 2021 08:23
Shows that the Martingale strategy has a 50% chance of doubling your money.
var rand = new Random();
bool Play(ref int bank, int bet)
{
var win = rand.Next(2) < 1;
checked
{
bank += win ? bet : -bet; // If you win, you gain your bet back AND the winnings. If you lose, you just lose your bet.
}
Oh Yeaheyay!
[The Mystic Crystal]
Long ago and far away
In labarynths of coral caves
A Mystic Crystal was forged in glass
With magic or some shit like that.
Its powers had been used for good
// Note: Much of the descriptions are from https://en.wikipedia.org/
void Main()
{
var sb = new StringBuilder();
sb.AppendLine("digraph classes {");
sb.AppendLine("node [shape=none width=0 height=0 margin=0];");
Func<Type, string> id = null;
id = FuncUtils.Memoize((Type type) =>
@otac0n
otac0n / SpecialRelativity.cs
Created November 9, 2022 08:24
Special Relativity
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Numerics.dll</Reference>
<Namespace>System.Drawing</Namespace>
<Namespace>System.Drawing.Drawing2D</Namespace>
<Namespace>System.Drawing.Text</Namespace>
<Namespace>System.Drawing.Imaging</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
</Query>
const int FrameRate = 30;
@otac0n
otac0n / prompt.txt
Created December 21, 2022 04:12
Embed ChatGPT in AR
You are now inhabiting my augmented reality headset. I may refer to you as "Computer" or "Headset" because of this.
I want you to help me control some software on my headset
From now on, I would like you to respond with code that contains your reponse, such as:
```
response = "I understand.";
```
If there is some some reason you want to issue a warning, you can first toggle the warning status with: