Skip to content

Instantly share code, notes, and snippets.

View SirTony's full-sized avatar

Tony Stark SirTony

  • Philadelphia, PA, USA
View GitHub Profile
@SirTony
SirTony / lines.d
Created December 27, 2014 23:29
Counts all lines in source code files.
module lines;
import std.file;
import std.path;
import std.stdio;
import std.regex;
import std.getopt;
import std.string;
import std.traits;
import std.algorithm;
@SirTony
SirTony / NotNull.cs
Last active August 29, 2015 14:12
Represents a reference type that may never be assigned a value of null.
public struct NotNull<T> where T : class
{
private T mValue;
public T Value
{
get { return this.mValue; }
set
{
if( value == null )
throw new ArgumentNullException( "value" );
@SirTony
SirTony / envy.d
Last active August 29, 2015 14:08
A simple class to modify environment variables (Windows-only).
module envy;
version( Windows ):
private {
import std.windows.registry;
}
private enum ENV_KEY = "Environment";
@SirTony
SirTony / annotations.d
Last active August 29, 2015 14:07
Helpful user-defined attributes for marking TODOs and FIXMEs with code to be notified at compile time, rather than with comments and grepping for them later.
module annotations;
private {
import std.string;
import std.traits;
import std.array;
}
private template TargetInfo( alias target )
{
@SirTony
SirTony / imgconv.cs
Created October 7, 2014 14:26
A simple tool to convert an input image to a different format.
//Compile with: csc /nologo /r:System.Drawing.dll imgconv.cs
using System;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Drawing.Imaging;
static class Program
{
@SirTony
SirTony / pack.d
Last active August 29, 2015 14:06
UI archive compression tool for https://github.com/Evairfairy/PacketRogue
/+
Compile with:
dmd pack.d
Options:
Flag Type Required Default Description
---------------------------------------------------------
--out string yes <none> The name of the .ui file to output.
--dir string yes <none> The source directory to pack.
--width uint yes <none> Window client size width.
@SirTony
SirTony / util.d
Created September 4, 2014 01:49
A small collection of utility functions for the D programming language.
module util;
bool contains( T )( T[] a, T item )
{
foreach( x; a )
if( x == item )
return true;
return false;
}
@SirTony
SirTony / EventHandler.d
Last active August 29, 2015 14:05
A simple wrapper to handle both delegates and functions for the purposes of event callbacks, akin to .NET-style events.
module eventhandler;
/+
EventHandler implementation.
+/
struct EventHandler( TArgs... )
{
private import std.algorithm;
@SirTony
SirTony / bomb_size.py
Last active August 29, 2015 14:03
Calculates the theoretical uncompressed size of a zip bomb.
#Call with `python.exe bomb_size.py --noc`
#to suppress the thousands separator.
from sys import argv
suppressComma = len( argv ) >= 2 and argv[1] == "--noc"
def humanSize( size, places = 2, lower = False ):
units = ( "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" )
index = 0
newSize = size
@SirTony
SirTony / Format.cs
Last active August 29, 2015 14:02
Utilities for representing arbitrary byte-lengths in a human-readable way.
using System;
public static class Format
{
public static string HumanSize( int size, int places = 2, bool lower = false )
{
return Format.HumanSize( Convert.ToDecimal( size ), places, lower );
}
public static string HumanSize( long size, int places = 2, bool lower = false )