Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
JesseKPhillips / StructOptions-eg.d
Last active October 16, 2019 15:55 — forked from run-dlang/main.d
Example of Meta Programming to Use Structures to define getopt command line arguments.
import std.traits;
import std.getopt;
// Specify The Parameter Structure
struct Options
{
@Option("threads", "t")
@Help("Number of threads to use.")
size_t threads;
@JesseKPhillips
JesseKPhillips / CheeseWiz.d
Last active July 7, 2019 16:24 — forked from run-dlang/main.d
Code shared from run.dlang.io.
import std.stdio, std.traits;
struct ModelA
{
// D only allows single inheritance, must use interfaces
interface iAnimal
{
string Type();
string Name();
void Attack(iAnimal who);
@JesseKPhillips
JesseKPhillips / WithPrevious.d
Created April 14, 2019 17:09
Creates a range over a range that utilizes a function to create the next iteration off the previous result and the next element.
// Execute with dmd arguments: -unittest -main
import std.range;
import std.traits;
/**
* Calls fun with the previous result and the current iteration state.
*/
struct WithPrevious(alias fun, StateType) {
StateType _state;
@JesseKPhillips
JesseKPhillips / GenericComposition.d
Created August 9, 2017 01:01
Shows a couple of different ways to check at compile time that a composed class inherits specific interfaces.
void main() {}
class Provider {
Concrete c;
}
class Concrete : HasThis, HasThat { }
interface HasThis {}
@JesseKPhillips
JesseKPhillips / mystory.md
Last active November 18, 2016 00:31
mkUSAgreatAgain: My letter to the president

Dear President Elect,

I expect that you'll get a large number of requests for help, many of which will be to help others and not the author. That is one of the great things about persons, it isn't just about themselves, instead life should be better for all. But the United States of America was great, not for what it did, but instead for what it could not do. I want to make my suggest toward fixing the government.

The founders, as flawed as they were, did two great things to the government. They made the government open/transparent and granted it powers. Consider what the government is doing and see if you can find that power granted in the Constitution; if it isn't there or you find it isn't clear, draft a modification to the Constitution so that it can be written and people can see that power exists.

Consider also that the Constitution does not specify a partisan government, yet is it fair to say that the country had more than two choices (Clinton and Trump)? Either we need the Constitution to specify a

@JesseKPhillips
JesseKPhillips / wrapStructTest.d
Created November 11, 2015 23:11
Provides testing of wrapping a structure into Range interfaces
// Based on: http://he-the-great.livejournal.com/49174.html
import std.range;
import exp = std.experimental.typecons;
interface InputRange(E) {
@property E front();
void popFront();
@property bool empty();
}
auto test(T)(T lhs) {
auto t = new Test!T;
t.lhs = lhs;
import std.typecons : Tuple;
return Tuple!(Test!T , "lhs", Test!T, "verify")(t, t);
}
class Test(T) {
T lhs;
@JesseKPhillips
JesseKPhillips / DividendWorksheet2014.d
Last active August 29, 2015 14:16
Provides the sequence of events for the USA 2014 Qualified Dividend and Capital Gain Tax Worksheet.
/**
* Provides the sequence of events for the USA 2014 Qualified Dividend and Capital Gain Tax Worksheet.
*
* This is license under Boost 1.0:
* http://www.boost.org/LICENSE_1_0.txt
*
* Do not rely on this software being correct, do yourself a favor and
* review the the logic.
*
* It relys on cmdln.interact found on github:
@JesseKPhillips
JesseKPhillips / noloops.d
Last active August 29, 2015 14:13
Translation to D of the Java 8 No more loops post
// Original: http://www.deadcoderising.com/java-8-no-more-loops/
import std.algorithm;
import std.range;
import std.typecons;
private struct Article {
private immutable string title;
private immutable string author;
private immutable string[] _tags;
#!/usr/bin/dmd -run
// Solution to Project Euler problem 61
// For a more readable version, see 061.rb
// Author: David J. Oftedal.
import std.stdio, std.math, std.algorithm, std.string, std.conv, std.c.stdlib, std.range;
// The ABC formula for solving quadratic equations (where the solutions are real numbers).
// Restrict to integer solutions.