Skip to content

Instantly share code, notes, and snippets.

@schveiguy
schveiguy / d1ops.d
Last active June 14, 2022 16:30
D1 operator overloads
mixin template D1Ops() {
// binary operations
static foreach(op, d1;
["+" : "opAdd", "-" : "opSub", "*" : "opMul", "/" : "opDiv",
"%" : "opMod", "&" : "opAnd", "^" : "opXor", "|" : "opOr",
"<<" : "opShl", ">>" : "opShr", ">>>" : "opUShr", "~" : "opCat",
"in" : "opIn"]) {
static if(__traits(hasMember, typeof(this), d1))
alias opBinary(string s : op) = mixin(d1);
// _r version
@schveiguy
schveiguy / sqldemo.d
Last active June 7, 2021 15:17
Show sqlbuilder usage
import sqlbuilder.uda;
import sqlbuilder.dataset;
import sqlbuilder.dialect.sqlite;
// Note all of these are sql-injection-proof
struct users
{
@primaryKey @autoIncrement int id; // a non-unique primary key doesn't make sense
string name;
@schveiguy
schveiguy / day1.md
Last active September 28, 2020 00:29
Beerconf 2020 September

Major topics discussed during BeerConf September 2020 edition

  1. Walter implemented __totype(string) (dlang/dmd#11797) Points raised in objection to the feature are:
  • It can't work in CTFE, as they are not polymorphic
  • It's inferior to the capabilities type functions

(General conversation about science fiction books, genres, and authors)

  1. All rejoice for -preview=in!
@schveiguy
schveiguy / gbdateadded.d
Created July 12, 2020 13:57
Take a golf blitz team message and print out all the times the players joined.
import iopipe.bufpipe;
import iopipe.textpipe;
import iopipe.json.serialize;
import iopipe.json.parser;
import iopipe.json.dom;
import std.io;
import std.typecons;
import std.datetime;
import std.conv;
@schveiguy
schveiguy / wishitwouldwork.d
Created May 22, 2020 17:17
dotdotdot test case
template NewFilter(alias pred, T...)
{
import std.meta : AliasSeq;
static if(T.length == 1)
{
static if(pred!T)
alias NewFilter = AliasSeq!(T);
else
alias NewFilter = AliasSeq!();
}
@schveiguy
schveiguy / get_recursive.d
Created February 21, 2020 17:49
Another recursive range possibility, using simple linked-list stack.
import std.range;
struct StackFrame(T)
{
StackFrame* prev;
T range;
}
struct StackRange(T, alias recurse) if (isInputRange!(typeof(recurse(T.init))))
{
@schveiguy
schveiguy / app.d
Last active January 14, 2020 17:12
Sample graphql program that fails
import std.stdio;
import vibe.d;
import graphql.parser;
import graphql.builder;
import graphql.lexer;
import graphql.ast;
import graphql.helper;
import graphql.schema;
import graphql.traits;
@schveiguy
schveiguy / gblevelup.d
Last active September 5, 2019 00:48
Golf Blitz level checker
import std.algorithm;
import std.range;
import std.string;
import std.array;
import std.conv;
// |level|common|rare|epic|bux|xp|xptonextlevel|
enum xpData =
`|1|1|1|1|5|4|8|
|2|2|1|1|6|5|10|
@schveiguy
schveiguy / raindrops.d
Created September 4, 2019 20:14
Raindrops demo code.
import std.algorithm;
void main(string[] args)
{
import std.stdio;
// args[0] is the program name, args[1] through args[n] are the input strings.
// first validate the input
auto input = args[1 .. $];
foreach(i; 1 .. input.length)
{
@schveiguy
schveiguy / eponymous.d
Last active May 27, 2017 01:04
Voldemort types article
module eponymous;
template inputChain(R1, R2)
if(isInputRange!R1 && isInputRange!R2 &&
is(ElementType!R1 == ElementType!R2))
{
auto inputChain(R1 r1, R2 r2)
{
...
}