Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
ForeverZer0 / VarInt.cs
Last active May 3, 2022
Static helper classes for reading/writing Minecraft-compatible VarInt and VarLong values to a Stream or arbitrary array of bytes.
View VarInt.cs
using System.Runtime.CompilerServices;
namespace MyNamespace;
/// <summary>
/// Provides static functions for encoding/decoding variable-length integers represented as a <see cref="int"/>.
/// </summary>
public class VarInt
{
private const int SEGMENT_BITS = 0x7F;
@ForeverZer0
ForeverZer0 / Vaccine Exemption Letter
Created Nov 7, 2021
Legal Letter from Robert Barnes
View Vaccine Exemption Letter
Dear Boss,
Compelling any employee to take any current Covid-19 vaccine violates federal
and state law.
First, federal law prohibits any mandate of the Covid-19 vaccines as unlicensed,
emergency-use-authorization-only vaccines. Subsection bbb-3(e)(1)(A)(ii)(III) of section 360 of Title 21 of the United States Code, otherwise known as
the Emergency Use Authorization section of the Federal Food, Drug, and Cosmetic
Act, demands that everyone give employees the “option to accept or refuse administration”
of the Covid-19 vaccine. This right to refuse emergency, experimental vaccines, such as
@ForeverZer0
ForeverZer0 / EndianSwapExtensions.cs
Created Aug 24, 2021
Swap endian of numeric types using grouped bit-shifts instead of the much slower Array.Reverse.
View EndianSwapExtensions.cs
using System;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
namespace ChangeThisNamespace
{
/// <summary>
/// Contains extension methods dealing with endianness of numeric types.
/// </summary>
[PublicAPI]
@ForeverZer0
ForeverZer0 / Adler32.cs
Created Aug 24, 2021
C# ZLib stream implementation
View Adler32.cs
using System;
using System.Runtime.CompilerServices;
namespace ZLib
{
/// <summary>
/// An Adler-32 checksum implementation for ZLib streams.
/// </summary>
/// <seealso href=""/>
public sealed class Adler32
@ForeverZer0
ForeverZer0 / url_match.c
Created Feb 8, 2021
Validate URL in C (POSIX)
View url_match.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
printf("Enter the website URL:\n");
fgets(str, 100, stdin);
if (!strcmp(str, "\n")) {
@ForeverZer0
ForeverZer0 / snake_case.rb
Created Nov 29, 2020
Convert from camelCase/PascalCase to snake_case in Ruby
View snake_case.rb
def snake_case
return downcase if match(/\A[A-Z]+\z/)
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([A-Z])/, '\1_\2').
downcase
end
"FooBar".snake_case #=> "foo_bar"
"HeadlineCNNNews".snake_case #=> "headline_cnn_fake_news"
"CNN".snake_case #=> "cnn"
@ForeverZer0
ForeverZer0 / GL.Delegates.cs
Created May 10, 2020
Generated C# bindings for OpenGL 3.3 (Core Profile)
View GL.Delegates.cs
using System;
using System.Runtime.InteropServices;
using System.Security;
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
namespace OpenGL
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@ForeverZer0
ForeverZer0 / MeshLoader.cs
Created May 4, 2020
Simplified loader for creating a mesh from Wavefront OBJ (*.obj) format.
View MeshLoader.cs
/*
* MIT License
*
* Copyright (c) 2020 Eric Freed
*
* 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
@ForeverZer0
ForeverZer0 / SphereMesh.cs
Last active May 3, 2020
Various mesh generation techniques for spheres.
View SphereMesh.cs
/*
* MIT License
*
* Copyright (c) 2020 Eric Freed
*
* 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
@ForeverZer0
ForeverZer0 / RectPacker.cs
Created Apr 4, 2020
High-efficiency bin-packer implementation for 2D rectangles.
View RectPacker.cs
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace MyNamespace
{
/// <summary>
/// Represents a rectangular box shape.
/// </summary>