Skip to content

Instantly share code, notes, and snippets.

View DmitryOlshansky's full-sized avatar
💭
https://dmitry-olsh.medium.com/brain-the-missing-manual-254ba32e0e0e

Dmitry Olshansky DmitryOlshansky

💭
https://dmitry-olsh.medium.com/brain-the-missing-manual-254ba32e0e0e
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.olshansky</groupId>
<artifactId>elastik</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@DmitryOlshansky
DmitryOlshansky / elastik.kt
Created April 25, 2020 13:23
A simple bulk uploader script with SMILE format support
package me.olshansky
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.smile.SmileFactory
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.http4k.client.ApacheClient
import org.http4k.core.*
import org.http4k.core.Method.*
@DmitryOlshansky
DmitryOlshansky / qemu-binfmt-setup.sh
Created June 16, 2018 06:26
Install binfmt for all cpus via qemu-user-static
#!/bin/sh
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390/HPPA/Xtensa/microblaze
# program execution by the kernel
qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
mips mipsel mipsn32 mipsn32el mips64 mips64el \
sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb microblaze microblazeel"
i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
@DmitryOlshansky
DmitryOlshansky / threaded-code.d
Created May 7, 2018 19:56
PoC for threaded code VM
import std.stdio;
// works for x86_64 ;)
R enterThreadedCode(R, T)(R function(T) target, T arg) {
asm @nogc nothrow {
naked;
mov RAX, RSP;
mov RSP, [RDI];
push RAX;
mov RAX, [RDI];
@DmitryOlshansky
DmitryOlshansky / comminication1.d
Created January 31, 2018 15:04
Out of band signal
// Consider that we spin up one of these guys per file
// the idea is that we can interrupt this fiber by sending Control message
// that will be processed out of bounds
void logFileProcessor(Stream!Control controlPlane, File inp)
{
bool done = false;
auto source = inp.byLine; //
while(!done){
multiplex( // pick one of sources that are ready and execute branches
controlPlane, {
Library topics
1. Multi-threading the scheduler.
- have a thread pool with thread per core (+affinity to avoid overheads)
- balance each spawned fiber to e.g. least-loaded thread of the pool
- provide a hint to spawn on the same thread as parent (?)
@DmitryOlshansky
DmitryOlshansky / dump
Last active August 29, 2015 14:07
Dump of GC usage - Phobos (mediawiki)
{| class="wikitable"
! Module
! Artifact
! Reason
! Possible Fix(es)
|-
|-
|std.algorithm [https://github.com/D-Programming-Language/phobos/blob/95222b884d7ad1a75b336f8f64a5a3bb2303ed1f/std/algorithm.d#L10409]
|TimSortImpl.sort
@DmitryOlshansky
DmitryOlshansky / gist:7ce9394ccc5bf27359da
Last active August 29, 2015 14:06
Analyzing effect of a std.uni pull
Seems good. Numbers themselves have variability of up to 2 Mb/s between runs of exactly the same test.
Before (git HEAD):
====================
m8-Alpha [arwiki], 273256 hits, 5.67256, 110.15 Mb/s
m8-Mark [arwiki], 496 hits, 5.8008, 107.71 Mb/s
m8-Symbol [arwiki], 152 hits, 5.80076, 107.71 Mb/s
m8-Number [arwiki], 7216 hits, 5.78192, 108.06 Mb/s
tri-alpha [arwiki], 273256 hits, 8.79468, 71.04 Mb/s
decode-only [arwiki], 342832 hits, 2.50764, 249.16 Mb/s
@DmitryOlshansky
DmitryOlshansky / trusted.d
Last active August 29, 2015 14:05
Encapsulating trust
module trusted;
/// Forward arguments to some @system callable $(D fun)
auto ref call(alias fun, Args...)(auto ref Args args) @trusted
{
return fun(args);
}
/// @trusted function to clearly isolate taking address of a local
auto addrOf(T)(ref T value) @trusted
@DmitryOlshansky
DmitryOlshansky / exceptions.d
Last active August 29, 2015 14:02
writeln/writefln style exceptions
/// $(D write)-style construction of exceptions, optionally with given super type.
auto exception(Base=Exception, string file = __FILE__,
size_t line = __LINE__, Args...)(Args args)
{
return exceptionfImpl!Base(null, args, file, line);
}
/// $(D writef)-style construction of exceptions, optionally with given super type.
auto exceptionf(Base=Exception, string file = __FILE__,
size_t line = __LINE__, Args...)(string fmt, Args args)