Skip to content

Instantly share code, notes, and snippets.

Avatar

Steven Schveighoffer schveiguy

View GitHub Profile
@schveiguy
schveiguy / d1ops.d
Last active Jun 14, 2022
D1 operator overloads
View d1ops.d
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 Jun 7, 2021
Show sqlbuilder usage
View sqldemo.d
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 Sep 28, 2020
Beerconf 2020 September
View day1.md

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 Jul 12, 2020
Take a golf blitz team message and print out all the times the players joined.
View gbdateadded.d
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;
View wishitwouldwork.d
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 Feb 21, 2020
Another recursive range possibility, using simple linked-list stack.
View get_recursive.d
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 Jan 14, 2020
Sample graphql program that fails
View app.d
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 / raindrops.d
Created Sep 4, 2019
Raindrops demo code.
View raindrops.d
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 / gblevelup.d
Last active Sep 5, 2019
Golf Blitz level checker
View gblevelup.d
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 / test.html
Created May 26, 2017
Simple web page with one table
View test.html
<html>
<body>
before
<table>
<tr>
<td>table</td><td>data</td>
</tr>
</table>
after
</body>