Instantly share code, notes, and snippets.

View AllocUmm.cs
public static unsafe class AllocUmm
{
[Flags]
public enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
View MemoryInfo.cs
public class MemoryInfo
{
[Flags]
public enum AllocationType : uint
{
COMMIT = 0x1000,
RESERVE = 0x2000,
RESET = 0x80000,
LARGE_PAGES = 0x20000000,
PHYSICAL = 0x400000,
View Converters.cs
public static class Converters
{
public static bool IsValidPrimitive<T>()
{
var type = typeof(T);
switch(Type.GetTypeCode(type))
{
case TypeCode.Boolean:
case TypeCode.Char:
case TypeCode.SByte:
View StripHTMLAll.cs
public static string StripHTMLAll(string source)
{
try
{
string result;
result = source.Replace("\r", " ");
result = result.Replace("\n", " ");
result = result.Replace("\t", " ");
result = Regex.Replace(result, @"( )+", " ", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"<( )*head([^>])*>", "<head>", RegexOptions.IgnoreCase);
View ResizeEx.cs
public class ResizeEx
{
/// <summary>
/// Resizes a one-dimensional array to the specified new size.
/// </summary>
public static void Resize<T>(ref T[] array, int newSize)
{
if(newSize <= 0)
throw new ArgumentOutOfRangeException($@"New Size {newSize} must be greater than 0.");
if(array == null)
View TBuffer.cs
[DebuggerTypeProxy(typeof(HashSetDebugViewInt<>))]
[DebuggerDisplay("Count = {Count}")]
[Serializable]
public struct TBuffer<T>
{
private int _size;
private Murmur3.Result[] _hashes;
private bool _hashesUpToDate;
public T[] Things;
private static readonly TypeCode _typeCode;
View KvPair.cs
[Serializable]
public class KvPair<T1, T2> : IStructuralEquatable, IStructuralComparable, IComparable
{
public KvPair(T1 key, T2 value)
{
Key = key;
Value = value;
}
public T1 Key {get;}
public T2 Value{get;}
View BoyerMoore.cs
public class BoyerMoore
{
private int[] _jumpTable;
private byte[] _pattern;
private int _patternLength;
public BoyerMoore()
{
}
public BoyerMoore(byte[] pattern)
{
View CopyFileEx.cs
public bool CopyFileEx(string sourceFile, string targetFile)
{
long bytesLeft = 0;
long bytesProcessed = 0;
long sectorsCopied = 0;
var fileinfo = new FileInfo(sourceFile);
var fileFragments = FileFragments.GetFileAllocation(sourceFile);
if(fileFragments.TotalFragments == 0 || fileinfo.Length == 0)
return false;
var device = new Device(512);
View FileFragments.cs
public class FileFragments
{
private const int FSCTL_GET_RETRIEVAL_POINTERS = 0x00090073;
private const uint FileAccess_GenericRead = 0x80000000;
private const uint FileAccess_GenericWrite = 0x40000000;
private const uint FileShare_Read = 0x00000001;
private const uint FileShare_Write = 0x00000002;
private const uint FileShare_ReadWrite = FileShare_Read | FileShare_Write;
private const uint FileMode_OpenExisting = 0x00000003;
private const uint FileAttributes_Normal = 0x00000080;