Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
JesseKPhillips / lconst.d
Created November 30, 2010 02:54
Creating Safe Mutable members in a const/immutable object.
/**
* This code comes from a D newsgroup discussion by Max Samukha
* and Simen kjaeraas: http://thread.gmane.org/gmane.comp.lang.d.general/43408/focus=43476
*
* The intent is to provide a safe way to mutate some data in a const method.
*
* The rules to achieve this are:
* * Only mutable data can be assigned to a Mutable
* * Referenced fields can be modified (inner class fields, pointer target)
* * Value types can be modified if the encapsulating class
@JesseKPhillips
JesseKPhillips / callcenter.d
Last active September 24, 2015 16:07
A translation of some code written in Go to demonstrate Goroutines.
/*
* Original Go: http://www.mprescient.com/journal/2011/1/9/concurrency-in-go-a-call-center-tutorial.html
*/
module main;
import core.thread,
std.array,
std.concurrency,
std.conv,
@JesseKPhillips
JesseKPhillips / gist:774983
Last active September 24, 2015 16:18
Example of callcenter using parrallelfuture
module main;
import core.thread;
import std.algorithm;
import std.conv;
import std.datetime;
import std.parallelism;
import std.random;
import std.range;
import std.stdio;
@JesseKPhillips
JesseKPhillips / csvtests.d
Created January 30, 2011 03:46
Unittests for csvRange
import csvRange;
import std.stdio;
void main() {
}
unittest {
@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)
@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 / 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 / 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 / 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 / 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;