Skip to content

Instantly share code, notes, and snippets.

View qrealka's full-sized avatar

Dmitry Loginov qrealka

View GitHub Profile
@qrealka
qrealka / minipool.hpp
Created July 5, 2019 14:42 — forked from rofirrim/minipool.hpp
Very simple memory pool
#ifndef MINIPOOL_H
#define MINIPOOL_H
#include <cassert>
#include <cstddef>
#include <memory>
#include <new>
#include <utility>
/*
@qrealka
qrealka / hash_fnv1a.h
Created June 7, 2019 20:57 — forked from ruby0x1/hash_fnv1a.h
FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
#pragma once
#include <stdint.h>
//fnv1a 32 and 64 bit hash functions
// key is the data to hash, len is the size of the data (or how much of it to hash against)
// code license: public domain or equivalent
// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
inline const uint32_t hash_32_fnv1a(const void* key, const uint32_t len) {
cmake_minimum_required(VERSION 2.8)
set(CMAKE_INSTALL_PREFIX /usr)
project(UNITY_BUILD_NAME)
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
#include <cstring> // memcpy
#include <type_traits> // is_trivially_copyable
// http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h?view=markup
// bit_cast<Dest,Source> is a template function that implements the
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in
// very low-level functions like the protobuf library and fast math
// support.
//
@qrealka
qrealka / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created March 17, 2019 04:48 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \

I was told by @mmozeiko that Address Sanitizer (ASAN) works on Windows now. I'd tried it a few years ago with no luck, so this was exciting news to hear.

It was a pretty smooth experience, but with a few gotchas I wanted to document.

First, download and run the LLVM installer for Windows: https://llvm.org/builds/

Then download and install the VS extension if you're a Visual Studio 2017 user like I am.

It's now very easy to use Clang to build your existing MSVC projects since there's a cl compatible frontend:

@qrealka
qrealka / ntlmdecoder.py
Created November 13, 2018 10:33 — forked from aseering/ntlmdecoder.py
NTLM auth-string decoder
#!/usr/bin/env python
## Decodes NTLM "Authenticate" HTTP-Header blobs.
## Reads the raw blob from stdin; prints out the contained metadata.
## Supports (auto-detects) Type 1, Type 2, and Type 3 messages.
## Based on the excellent protocol description from:
## <http://davenport.sourceforge.net/ntlm.html>
## with additional detail subsequently added from the official protocol spec:
## <http://msdn.microsoft.com/en-us/library/cc236621.aspx>
##
@qrealka
qrealka / C++ normal operators.md
Created November 12, 2018 11:56 — forked from beached/C++ normal operators.md
A list of the normal signatures of C++ operators that allow overloading

C++ Operator Signatures

This is a list of C++ operators that can be overloaded and their normal signatures(a.k.a what an int would do)

Arithmetic

operator+ addition

  • free function -> T operator+( T const & lhs, T const & rhs )
  • member function -> T & operator+( T const & rhs )

operator+ unary plus

  • member function -> T &operator+( )
  • free function -> T & operator+( T & value )
@qrealka
qrealka / variant_any_cast_example.cpp
Created October 2, 2018 14:20 — forked from hoffis/variant_any_cast_example.cpp
Any, variant and lambda visitor
#include <boost/variant.hpp>
#include <boost/spirit/home/support/detail/hold_any.hpp>
#include <iostream>
#include <type_traits>
using Any = boost::spirit::hold_any;
template<typename ...> struct VariantAnyCast;
template<class T, class ... Rest>
@qrealka
qrealka / gist:f470374a585410900d0c3aeb5efe206a
Created October 2, 2018 11:52 — forked from gnzlbg/gist:5547905
variadic zip and join function extensions to boost range
#include <iostream>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include "tupleit.hh" // http://pastebin.com/LFkTHdQk
#include <stdio.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>