Skip to content

Instantly share code, notes, and snippets.

View daskol's full-sized avatar
🤙

Daniel Bershatsky daskol

🤙
View GitHub Profile
@daskol
daskol / dev-null.sh
Created March 1, 2018 14:03
DevNull as a Service
#!/bin/bash
# dev-null.sh
# This shell script implement /dev/null as a Service(//aaS).
IFS=$'\n\n'
while true; do
rm -rf /tmp/input /tmp/output
mkfifo /tmp/input /tmp/output
@daskol
daskol / lock-free-asm.diff
Created March 15, 2018 19:08
Native code generation for different memory ordering flags for lock-free stack implementation.
--- weak-ordering.asm 2018-03-15 14:59:41.504213243 +0300
+++ stong-ordering.asm 2018-03-15 14:59:32.910123855 +0300
@@ -9,7 +9,7 @@
sub $0x38,%rsp
mov 0x78(%rdi),%eax
test %eax,%eax
+ jne 0x40a20a <StressPushPop(benchmark::State&)+490>
- jne 0x40a218 <StressPushPop(benchmark::State&)+504>
mov $0x409700,%r13d
mov $0x62ff68,%r15d
@daskol
daskol / clip.py
Created May 3, 2018 16:07
Branch Prediction in Python
from typing import List, Tuple
from random import randint
def gen_array(random=True, size=8 * 1024 * 1024):
if random:
return [randint(-1000, 1000) for i in range(size)]
else:
return list(sorted(gen_array(True, size)))
@daskol
daskol / endianness.h
Created May 25, 2018 12:07
Common routine for convertion from network ordered integers to host byte order.
/**
* \file endianness.h
* \brief This header defines common routine for convertion from network
* ordered integers(which is usually big endian) to byte order that is native
* to host.
*
* There is if-constexpr so C++17 compiler is strongly needed for this.
*/
#pragma once
@daskol
daskol / FindFontConfig.cmake
Created September 1, 2018 20:48
Find FontConfig library for configuring and customizing font access.
# FindFontConfig.cmake
# Daniel Bershatsky, 2018
#.rst:
# FindFontConfig
# --------------
#
# Find FontConfig library for configuring and customizing font access.
#
# Imported Targets
@daskol
daskol / socket-connection-to-ipv4-ipv6.c
Created December 1, 2018 14:28
Demonstration of connection to IPv4 and IPv6
// socket-binding.c
//
// This is small tool that helps to clarify how to listen IPv6 socket and it
// is nessesary or not listen IPv4 socket at the same time.
//
// Compile `gcc -std=c11 -o listen main.c`
//
// Run binary with option `-4` or `-6` and connect to port(default is 5489)
// with netcat in the following way.
// 1. `nc -4 127.0.0.1 5489`
@daskol
daskol / tty-size.c
Created April 4, 2019 13:28
Get size of console attached to stderr.
/**
* \file tty-size.c
* \brief Get size of console attached to stderr.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <unistd.h>
@daskol
daskol / maxout.py
Created April 18, 2019 12:35
Maxout unit in PyTorch
import torch as T
class Maxout(T.nn.Module):
"""Class Maxout implements maxout unit introduced in paper by Goodfellow et al, 2013.
:param in_feature: Size of each input sample.
:param out_feature: Size of each output sample.
:param n_channels: The number of linear pieces used to make each maxout unit.
:param bias: If set to False, the layer will not learn an additive bias.
"""
@daskol
daskol / tt_maxout.py
Created April 19, 2019 09:56
Implementation of TT-Maxout unit in PyTorch
# encoding: utf8
# filename: maxout.py
import torch as T
import torch.nn.init as I
class TTMaxout(T.nn.Module):
def __init__(self, in_features, out_features, n_channels, tt_rank,
bias=True, irange=0.005):
@daskol
daskol / moment-adjunctor.py
Created April 26, 2019 12:54
Moment Adjunctore for SGD Optimizer in PyTorch
# encoding: utf8
# filename: optimizer.py
import torch as T
def clip_momentum(value: float) -> float:
if value > 1.0:
return 1.0
elif value < 0.0: