Skip to content

Instantly share code, notes, and snippets.

View erthink's full-sized avatar
🎀
White Hat & Head: clip.dqd.kfa @ PositiveTechnologies

Леонид Юрьев (Leonid Yuriev) erthink

🎀
White Hat & Head: clip.dqd.kfa @ PositiveTechnologies
View GitHub Profile
@erthink
erthink / ascii_wc_avx2.c
Created February 26, 2020 01:06
Simple AVX2-enabled version of ASCII-only wc util
/*
* zlib License, see https://en.wikipedia.org/wiki/Zlib_License
*
* Copyright (c) 2020 Leonid Yuriev <leo@yuriev.ru>,
* Simple portable optimized ASCII-only version of wc tool.
* Just for fun &
* https://en.wikipedia.org/wiki/The_Computer_Language_Benchmarks_Game
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@erthink
erthink / ascii_wc.c
Last active March 3, 2020 15:27
Simple portable optimized ASCII-only version of wc util
/*
* zlib License, see https://en.wikipedia.org/wiki/Zlib_License
*
* Copyright (c) 2020 Leonid Yuriev <leo@yuriev.ru>,
* Simple portable optimized ASCII-only version of wc tool.
* Just for fun & https://en.wikipedia.org/wiki/The_Computer_Language_Benchmarks_Game
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
@erthink
erthink / naive_wc.c
Last active March 1, 2020 08:22
Naive C-implementation of wc
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
@erthink
erthink / ascii_wc_like_ghc.c
Created February 26, 2020 02:37
Inspired by ghc naive C-implementation of wc
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
@erthink
erthink / wc.hs.lst
Created February 26, 2020 01:39
asm-dump of wc.hs
[1 of 1] Compiling Main ( wc.hs, wc.o )
==================== Asm code ====================
.section .data
.align 8
.align 1
.globl __stginit_main@main:Main
.type __stginit_main@main:Main, @object
__stginit_main@main:Main:
@erthink
erthink / ascii_wc.hs
Created February 25, 2020 22:37
Simple ASCII-only version of wc util
{-# LANGUAGE Strict #-}
{-# LANGUAGE RecordWildCards #-}
import qualified Data.ByteString as BS
import System.Environment
import System.IO.Posix.MMap
data State = State
{ bs :: Int
, ws :: Int
@erthink
erthink / toc.sh
Created July 14, 2019 21:59
Generates Table of Contents for markdown document
#!/bin/bash
###########################################################
# This script generates a nested Table of Contents from a #
# markdown document's header tags. #
# https://github.com/leo-yuriev #
###########################################################
# DEFAULTS
@erthink
erthink / Windows_LockFileEx_WriteFile_Bug.cpp
Last active February 2, 2018 04:52
This testcase reproduce a multithread clash-bug between LockFileEx() and WriteFile()
// This testcase reproduce a multithread clash-bug
// between LockFileEx() and WriteFile().
//
// The bug was discovered when testing
// https://github.com/leo-yuriev/libmdbx and https://github.com/PositiveTechnologies/libfpta
// (Ultra fast, compact, Embedded Database for tabular and semistructured data).
//
//--------------------------------------------------------
// UPDATE 2018-02-02
//
@erthink
erthink / ly_random.c
Last active October 4, 2017 13:20
ly-random
#include <stdint.h>
static unsigned rnd_head, rnd_tail;
static uint32_t rnd_pool[64];
static __inline
uint32_t random_poly (unsigned n)
{
/* LY: доступ к ряду полинома через циклический буфер. */
return rnd_pool [(rnd_tail + n) & 63];
@erthink
erthink / patch.diff
Last active April 28, 2016 02:50
Intel's VTune driver (sepdk) fix for modern kernels
commit acaf1cd6b292c7b54f2d4861d12fedb2674bd8d3
Author: Leo Yuriev <leo@yuriev.ru>
Date: 2016-04-14 22:12:37 +0300
fix for modern kernels
diff --git a/src/vtsspp/module.c b/src/vtsspp/module.c
index 266becc..f662f89 100644
--- a/src/vtsspp/module.c
+++ b/src/vtsspp/module.c