Skip to content

Instantly share code, notes, and snippets.

View PetarKirov's full-sized avatar

Petar Kirov PetarKirov

View GitHub Profile
import std.stdio, core.sync.mutex;
import std.traits : lvalueOf;
struct Resource(T)
{
struct Payload
{
Mutex mtx;
int refCount;
T value;
@PetarKirov
PetarKirov / pegged_logic.d
Created July 30, 2017 13:43
Parsing logic formulas with pegged
/++ dub.sdl:
name "pegged_logic"
dependency "pegged" version="~>0.4.2"
+/
import std.json;
struct Text
{
string name;
@PetarKirov
PetarKirov / bitarray.d
Created August 12, 2017 14:28
Perf bench for std.bitmanip.BitArray
void main()
{
import std.algorithm : map, max;
import std.datetime : benchmark, to, TickDuration;
import std.meta : aliasSeqOf, I = Alias;
import std.range : array, iota, roundRobin;
import std.random : uniform;
import std.stdio : File, writefln;
enum evnSizes = [2, 8, 16, 32, 64, 128, 256, 512, 1024, 2 << 12, 2 << 14, 2 << 20]; // , 2 << 22, 2 << 24];
@PetarKirov
PetarKirov / text.md
Last active August 22, 2017 14:26
Evaluating `scope`

Consider the following program:

@safe:

char[] formatInPlace(T)(char[] buf, T value);

void main()
{
    char[1024] buffer;
    formatInPlace(buffer[], 28.625);
@PetarKirov
PetarKirov / main.d
Created September 9, 2017 13:09
CTFE RNG
// http://forum.dlang.org/post/oxxydengmzzefjxjqgma@forum.dlang.org
/+ CTRNG
Proof-Of-Concept Compile-Time Random Number Generator.
Please never actually use this or anything like it.
While doing some metaprogramming tomfoolery, I stumbled into an
interesting scenario. It occurred to me that with some work, I could
probably turn what I had into a functioning compile-time random
number generator, despite D's restrictions on metaprogramming intended
@PetarKirov
PetarKirov / test.d
Created September 9, 2017 22:37
CTFE Keeping global state
size_t bsearch(alias pred, uint start, uint end)()
{
static if (end <= start)
static assert (0);
else static if (start + 1 == end && pred!start)
return start;
else
{
vibe-d
sociomantic-tsunami/ocean
dlang/dub
higgsjs/Higgs
rejectedsoftware/ddox
BlackEdder/ggplotd
eBay/tsv-utils-dlang
dlang-community/D-Scanner
dlang-tour/core
d-widget-toolkit/dwt
@PetarKirov
PetarKirov / dub_variable_expansion.d
Last active September 9, 2018 16:23
Variable expansion in Dub
import std.array : appender;
import std.regex : regex, replaceAll;
import std.string : format, indexOf, toUpper;
import std.stdio : writeln;
string getVariable(string var)
{
return "<%s>".format(var.toUpper);
}
@PetarKirov
PetarKirov / posix_spawn_example.d
Created October 14, 2018 16:51
Example usage of posix_spawn in D
import core.sys.posix.sys.types : mode_t, pid_t;
import core.sys.posix.signal : sigset_t;
import core.sys.posix.sched : sched_param;
import core.stdc.stdio : perror, printf;
import core.stdc.errno : errno;
import core.stdc.stdlib : exit, EXIT_FAILURE;
void checkErrno(int err, const char* msg)
{
if (!err) return;
@PetarKirov
PetarKirov / output.md
Created February 11, 2019 13:28 — forked from wilzbach/output.md
Measure import time for each module in Phobos
module bare import time
std.regex 1.04s
std.net.curl 0.29s
std.zip 0.19s
std.path 0.15s
std.socket 0.15s
std.file 0.14s
std.mmfile 0.14s
std.datetime 0.14s