Skip to content

Instantly share code, notes, and snippets.

View sirtony's full-sized avatar

Tony King sirtony

  • Philadelphia, PA, USA
  • 10:28 (UTC -04:00)
View GitHub Profile
@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 )
@sirtony
sirtony / lisp.php
Last active August 29, 2015 14:00
Prototype Lisp interpreter implemented in PHP.
<?php
/**
This interpreter is largely a port of
this Python implementation: http://norvig.com/lispy.html
with several added features and a more object-oriented
approach with a focus on embedding in other scripts
rather than being a standalone script.
This is currently a prototype/proof-of-concept
@sirtony
sirtony / priorityqueue.d
Last active August 29, 2015 13:56
Implements a PriorityQueue collection in D.
module priorityqueue;
private import std.array : front, popFront;
public class PriorityQueue( _ElemType )
{
public alias _ElemType ElementType;
public enum SortMode : ubyte
{
@sirtony
sirtony / resourcepool.d
Created February 4, 2014 21:26
This is a port of the XNA generic resource pool (http://www.xnawiki.com/index.php/Generic_Resource_Pool) in the D programming language.
module resourcepool;
import std.traits;
public final class Pool( TClass ) if( !is( TClass == struct ) && !( isIntegral!TClass || isFloatingPoint!TClass ) && !is( TClass == bool ) && !isSomeChar!TClass )
{
private alias void delegate( TClass ) Action;
private alias bool delegate( TClass ) Predicate;
private alias TClass delegate() Func;
@sirtony
sirtony / path.php
Last active December 31, 2015 04:39
Combines segments of a filesystem path into an absolute path using the system's directory separator char, and supports checking for illegal characters on Windows systems. The path() function also supports multi-dimensional arrays.
<?php
function path()
{
// Determine if we are one windows, And get our path parts
$IsWindows = strtoupper( substr( PHP_OS, 0, 3 ) ) === "WIN";
$args = func_get_args();
$parts = array();
// Trim our paths to remove spaces and new lines