Skip to content

Instantly share code, notes, and snippets.

@DanielKeep
DanielKeep / serial.d
Created April 24, 2009 02:10
Simple binary serialisation of value types for D.
/**
* Simple binary serialisation of value types (oh, and arrays and AAs).
*
* Copyright © 2007 Daniel Keep
* License: http://www.opensource.org/licenses/zlib-license.php
*/
module serial;
version(Serial_NoReals)
{
/**
* Converts a function pointer to a delegate pointer.
*
* Copyright: © 2009, Daniel Keep.
*
* 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
/**
* Copyright: © 2009, Daniel Keep.
* License: MIT <http://www.opensource.org/licenses/mit-license.php>
*/
module etc.mem.util;
private
struct Align
{
ubyte a;
/*
Demonstration of a library-level Property implementation.
*/
import std.stdio;
const DefaultGetter = "";
const DefaultSetter = DefaultGetter;
/**
* Contains functions that operate on functions and delegates.
*
* Copyright: Copyright &copy; 2009, Daniel Keep.
* License: BSD v2 <http://www.opensource.org/licenses/bsd-license.php>
* Authors: Daniel Keep
*/
module tangox.util.Func;
import tango.core.Traits;
/// Parses the storage class for function arguments.
/// Authors: Daniel Keep
/// Copyright: Copyright © 2009 Daniel Keep
/// License: BSD v2 <http://www.opensource.org/licenses/bsd-license.php>
module argparse;
enum ParamSemantics
{
None = 0b0000,
In = 0b0001,
/**
* Collatz graph generator (inspired by http://www.xkcd.com/710/)
* Written by Daniel Keep; released to the Public Domain.
*
* To use this, compile and either dump the output to a file, or feed it
* directly into GraphViz like so:
*
* -----
* collatz 100 | dot -Ocollatz_100.svg -Tsvg
* -----
/*
That's 'binary search', not 'cow excrement' I'll have you know...
Written for http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
Sadly, there IS a bug in the original, unmodified version of the search due
entirely to me trying to be clever.
To compile and run this (using dmd), use:
module reprog_ssort;
/**
* Selection sort.
*
* This time actually writing out the various invariants and conditions.
* We're being FORMAL now, bitches.
*
* Compile with the 'paranoid' debug identifier to turn on all the various
* checks.
"
Function to compute DPI from diagonal screen length
and pixel dimensions.
Written in MathEval: http://github.com/DanielKeep/MathEval
"
let dpi(phD, pxW, pxH) = pxW / (phD / sqrt((pxH/pxW)**2 + 1))