Skip to content

Instantly share code, notes, and snippets.

View daskol's full-sized avatar
🤙

Daniel Bershatsky daskol

🤙
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / jpg2png.py
Created February 21, 2018 20:40
JPG to PNG converter in python with pillow
#!/usr/bin/env python3
import click
import PIL.Image
@click.command()
@click.argument('input', type=click.Path(exists=True, dir_okay=False))
@click.argument('output', type=click.Path(exists=False))
def main(input, output):
img = PIL.Image.open(input)
@daskol
daskol / jpg2png.go
Last active February 21, 2018 20:43
JPG to PNG converter in pure Go
package main
import (
"flag"
"io"
"log"
"os"
jpg "image/jpeg"
"image/png"
@daskol
daskol / listem.c
Created February 9, 2018 20:49
IPv4 and IPv6 sockets on Linux.
// listen.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 listen.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 / inject-metrica.sh
Created January 19, 2018 22:40
Inject Yandex Metrica counter into all HTML files after <body> tag.
#!/bin/bash
# inject-metrica.sh
# Inject Yandex Metrica counter into all HTML files after <body> tag.
COUNTER='<put Yandex Metrica one-line counter here>'
COUNTER=$(sed 's/\//\\\//g' <<< $COUNTER)
for file in $(ls *.html); do
echo "processing $file"
sed -i "s/<body>/<body>\n$COUNTER/g" $file