Skip to content

Instantly share code, notes, and snippets.

View sirtony's full-sized avatar

Tony King sirtony

  • Philadelphia, PA, USA
  • 03:35 (UTC -04:00)
View GitHub Profile
@sirtony
sirtony / grep.d
Created March 2, 2015 19:59
A grep-like tool written in D.
module grep;
private:
import std.stdio;
import std.regex;
import std.getopt;
import std.range;
import std.file;
import std.path;
@sirtony
sirtony / Callback.d
Last active August 29, 2015 14:15
A struct that wraps both function and delegate types, allowing them to be used interchangeably.
final struct Callback( TRet = void, TArgs ... )
{
public alias TRet delegate( TArgs ) DelegateType;
public alias TRet function( TArgs ) FunctionType;
private DelegateType dg;
private FunctionType fn;
public this( DelegateType dg ) { this.dg = dg; }
public this( FunctionType fn ) { this.fn = fn; }
@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;