Skip to content

Instantly share code, notes, and snippets.

import std.typecons;
import std.traits;
import std.typetuple;
import std.stdio : writeln;
struct Maybe(T) {
T value = void;
bool b = true;
@property static Maybe None() {
class PlayerBehavior : MonoBehavior
{
void Start()
{
// Debug.Log("Testing...");
// this.foo = bar;
final class PolymorphicMonostate(T) if (is(T == class)) {
static T _instance;
static void Create(T2 : T = T, U...)(U args) if (is(typeof(new T2(args)))) {
_instance = new T2(args);
}
T get() {
return _instance;
}
alias get this;
} version (unittest) {
@Biotronic
Biotronic / revComp.d
Created May 22, 2017 06:30
DNA Reverse Complement
import std.exception;
import std.stdio;
import std.conv;
import std.range;
import std.algorithm;
import std.datetime;
import std.meta;
string randomDna(int length) {
import std.random;
@Biotronic
Biotronic / MapGenerator.jsx
Last active July 9, 2017 14:59
Map generation script. Results on https://imgur.com/a/j11Cm
// The desired width of the image.
var desiredSize = UnitValue(prompt("Please type the desired width of your map (in pixels).", "2048"), "px");
var generatedSize = UnitValue("2048", "px");
// How many times to apply the difference clouds filter to the background.
// This can be lower for smaller maps, and probably should be bigger for ginormous ones.
var numClouds = 6;
// How many times to apply the difference clouds filter to the highlight layer.
// The desired width of the image.
var desiredSize = UnitValue(prompt("Please type the desired width of your map (in pixels).", "2048"), "px");
var generatedSize = UnitValue("2048", "px");
// How many times to apply the difference clouds filter to the background.
// This can be lower for smaller maps, and probably should be bigger for ginormous ones.
var numClouds = 6;
// How many times to apply the difference clouds filter to the highlight layer.
@Biotronic
Biotronic / challenge.d
Last active December 26, 2017 02:37
Expressive C++ challenge in D
/*
Expressive C++17 challenge, in D
http://www.bfilipek.com/2017/09/the-expressive-cpp17-challenge.html
D features used:
Ranges (MmText, zip, map)
UFCS (all over)
String mixins (in find)
Wysiwyg strings
Scoped imports
@Biotronic
Biotronic / algebra.d
Last active February 9, 2018 17:04
A template for defining algebras
import std.algorithm : among;
import std.array : appender;
import std.string : split, isNumeric;
import std.meta : allSatisfy, aliasSeqOf, Filter, templateNot, Repeat;
import std.conv : to, text;
import std.format : format;
alias complex = Algebra!(
float,
"1,i",
@Biotronic
Biotronic / Layout.d
Last active March 5, 2018 12:25
Suggested design for Layout!T
module layout;
import std.meta;
import std.traits;
import packs;
/**
* Deconstructs a type into its primitive fields, recursing into sub-types.
*
* Params:
@Biotronic
Biotronic / headmutable.md
Created March 12, 2018 07:57
Implicit Head-mutable Conversion for Temporaries

Implicit Head-mutable Conversion for Temporaries

Field Value
DIP: 1xxx
Review Count: 0
Author: Biotronic

Abstract

This document describes a method for implicitly converting const data structures to head-mutable when types are inferred for temporary variables. This already happens for built-in pointers and arrays, but user-defined types do not enjoy the same benefit. This document argues for a solution where the existing alias this feature is pressed into service to create temporaries with the desired head-mutability when the aliased value has the right type.