Skip to content

Instantly share code, notes, and snippets.

View Laeeth's full-sized avatar

Laeeth Isharc Laeeth

View GitHub Profile
@Laeeth
Laeeth / gitrmcache.d
Created January 10, 2015 22:55
remove cached git files
module gitrmcache;
import std.stdio;
import std.file;
import std.process;
int main(string[] args)
{
if (!((args.length==2) || (args.length==3)))
{
writefln("syntax is gitrmcache <path> [filespec]");
@Laeeth
Laeeth / endswith.d
Created January 10, 2015 23:08
writeup on endswith
import std.array;
import std.string;
import std.stdio;
import std.range;
uint endsWithAny(alias pred = "a == b", Range, Needles)(Range haystack, Needles needles)
if (isBidirectionalRange!Range && isInputRange!Needles &&
is(typeof(.endsWith!pred(haystack, needles.front)) : bool))
{
foreach (i, e; needles)
@Laeeth
Laeeth / reflection1.d
Created January 11, 2015 00:24
reflection
module deneme;
import std.string;
import std.traits;
struct MyAttr
{}
@MyAttr
void foo(int i, double d) pure @nogc nothrow @property
@Laeeth
Laeeth / h5cat.d
Created January 11, 2015 03:09
see contents of hdf5 data file
import hdf5.wrap;
import hdf5.bindings.enums;
import std.stdio;
import std.file;
void main(string[] args)
{
if (args.length!=2)
{
@Laeeth
Laeeth / hdf5example.d
Created January 13, 2015 16:58
Extract from wrapper code for high level HDF5 wrapper
hid_t createDataType(T)(T datatype)
{
auto tid=H5T.create(H5TClass.Compound,datatype.sizeof);
enum offsetof(alias type, string field) = mixin(type.stringof ~"."~field~".offsetof");
foreach(member; __traits(derivedMembers, T))
{
// debug(5) writefln("member: %s: offset=%s",member,offsetof!(T,member));
H5T.insert(tid, member, offsetof!(T,member), mapDtoHDF5Type(typeof(__traits(getMember,T,member)).stringof));
}
@Laeeth
Laeeth / doveadm.d
Created January 15, 2015 04:48
Using linux sockets to talk to dovecot doveadm
module doveadm;
import std.stdio;
import std.socket;
import std.string;
import std.array;
import std.c.linux.socket;
import core.sys.posix.sys.un;
import std.conv;
enum doveadmSocketPath= "/var/run/dovecot/doveadm-server";
@Laeeth
Laeeth / fetch_page.py
Last active August 29, 2015 14:27 — forked from Smerity/fetch_page.py
An example of fetching a page from Common Crawl using the Common Crawl Index
import gzip
import json
import requests
try:
from cStringIO import StringIO
except:
from StringIO import StringIO
# Let's fetch the Common Crawl FAQ using the CC index
resp = requests.get('http://index.commoncrawl.org/CC-MAIN-2015-27-index?url=http%3A%2F%2Fcommoncrawl.org%2Ffaqs%2F&output=json')
@Laeeth
Laeeth / arrayOp.d
Last active September 11, 2015 22:02 — forked from MartinNowak/arrayOp.d
pure:
nothrow:
// T[] = T[] op T[]
void arrayOp(string op, T)(T[] res, in T[] a, in T[] b)
in
{
assert(res.length == a.length);
assert(res.length == b.length);
}
@Laeeth
Laeeth / arsdlua.d
Last active October 5, 2015 20:17
very simplistic arsd terminal lua repl
/*
Basic idea is to create an inspector for exploring state of a D program from a console using Lua
to view and perhaps modify D state. You can then call this inspector either like a breakpoint by
just placing a call to it where you wish your code to stop, or implement something fancier so that
you can interrupt the code live from the debugging console or specify conditions that will lead to
a 'breakpoint'. (Perhaps annotate the functions that need to check if they need to call in to the
debugger, and conceivably have some kind of interprocess communication).
Also means you can log to a data structure rather than text file, and inspect the data structure in
a more precise and structured way via Lua
@Laeeth
Laeeth / latency.txt
Created October 27, 2015 02:57 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms