Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
JesseKPhillips / gist:9147869
Created February 22, 2014 02:46
Scala traits as D interface... maybe.
import std.stdio;
interface Flying {
@property string flyingMessage();
final void fly() {
writeln(flyingMessage);
}
}
interface Swimming {
@JesseKPhillips
JesseKPhillips / SaveRestoreProperties.d
Last active January 4, 2016 12:29
This shows that hiding implementation behind a function and provide a very simple client interface. As per a conversation on reddit: http://www.reddit.com/r/programming/comments/1w2xpl/selfreferential_functions_and_the_design_of/cey8y4v
import std.stdio;
@safe:
void main() {
Foo foo;
foo.Option.Val2 = "bye";
myFun(foo);
foo.DoSomeDebugging();
}
@JesseKPhillips
JesseKPhillips / osmpbfexample.d
Last active November 30, 2017 19:55
This gives a very basic parsing of osm.pbf files.
/**
* Explaination comments taken from:
* http://wiki.openstreetmap.org/wiki/PBF_Format#Design
*
* This gives a very basic parsing of osm.pbf files. The purpose was several
* fold.
*
* - Read PBF files
* - Learn the file layout
* - Verify the bytes match
@JesseKPhillips
JesseKPhillips / processTests.d
Created April 3, 2013 05:35
Unittests pulled from std.process (DLang)
import std.process2;
import std.stdio, std.array;
void main(string[] args) { write(args.join("\0")); }
unittest
{
import std.ascii;
auto x = executeShell("echo wyda");
// @@@ This fails on wine
@JesseKPhillips
JesseKPhillips / random2.d
Created October 23, 2011 19:12
Implimentation of randomCover that uses Random as a reference
import std.random;
import std.range;
auto randomCover2(Range,Rnd)(Range arr, ref Rnd random) {
return RandomCover2!(Range,Rnd)(arr,&random);
}
struct RandomCover2(Range, Random)
{
private Range _input;
@JesseKPhillips
JesseKPhillips / dateparse.d
Created October 13, 2011 00:10
std.dateparse braught to use std.datetime
// Written in the D programming language.
/**
* $(RED Deprecated. It will be removed in February 2012.
* Please use std.datetime instead.)
*
* dateparse module.
*
* Copyright: Copyright Digital Mars 2000 - 2009.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
@JesseKPhillips
JesseKPhillips / luad_non_empty_stack.d
Created October 11, 2011 15:53
This will cause the assert on line 184 of functions.d to fire.
version(Windows) {
pragma(lib, "lua51.lib");
} else
pragma(lib, "liblua.a");
import std.stdio;
import luad.all;
@JesseKPhillips
JesseKPhillips / csv.d
Created March 31, 2011 04:21
Crashing CSV
module csv;
import std.algorithm;
import std.array;
import std.range;
import std.conv;
import std.traits;
import std.stdio;
void main() {
@JesseKPhillips
JesseKPhillips / filerange.d
Created February 5, 2011 18:57
Attempt to make a slice-able forward range.
module filerange;
import std.algorithm;
import std.array;
import std.conv;
import std.exception;
import std.file;
import std.range;
import std.stdio;
@JesseKPhillips
JesseKPhillips / benchmarkcsv.d
Created February 1, 2011 03:55
Build a CSV file for testing performance
import csv;
import std.file;
void main() {
auto data = readText("sample.csv");
//auto records = csvText!Layout(data);
auto records = csvText!Layout(data, ["a", "b", "c", "d", "e"]);
foreach(r; records)