Skip to content

Instantly share code, notes, and snippets.

View maybe in D
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() {
View My fucking eyes!!
class PlayerBehavior : MonoBehavior
{
void Start()
{
// Debug.Log("Testing...");
// this.foo = bar;
View Polymorphic monostate
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
DNA Reverse Complement
View revComp.d
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 Jul 9, 2017
Map generation script. Results on https://imgur.com/a/j11Cm
View MapGenerator.jsx
// 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.
View MapGeneratorCS3.jsx
// 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 Dec 26, 2017
Expressive C++ challenge in D
View challenge.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 Feb 9, 2018
A template for defining algebras
View algebra.d
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 Mar 5, 2018
Suggested design for Layout!T
View Layout.d
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 Mar 12, 2018
Implicit Head-mutable Conversion for Temporaries
View headmutable.md

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.