Skip to content

Instantly share code, notes, and snippets.

View qrealka's full-sized avatar

Dmitry Loginov qrealka

View GitHub Profile
@qrealka
qrealka / effective_modern_cmake.md
Created May 28, 2018 16:16 — forked from mbinna/effective_modern_cmake.md
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@qrealka
qrealka / measure.cpp
Created May 30, 2018 10:32
c++ measure struct
using namespace std::chrono;
struct measure
{
template<typename F, typename ...Args>
static std::chrono::milliseconds::rep ms(F func, Args&&... args)
{
auto start = system_clock::now();
func(std::forward<Args>(args)...);
auto stop = system_clock::now();
@qrealka
qrealka / warmup_rdtsc.c
Created May 30, 2018 11:53
RDTSC accuracy measure
#ifdef _MSC_VER
#pragma intrinsic(__rdtsc)
inline u64 GetRDTSC()
{
int a[4];
__cpuid(a, 0x80000000); // flush OOO instruction pipeline
return __rdtsc();
}
inline void WarmupRDTSC()
@qrealka
qrealka / intrusive_ptr.cpp
Created May 30, 2018 22:16
intrusive pointer
template<class T>
class intrusive_ptr {
public:
using pointer = T*;
using const_pointer = const T*;
using element_type = T;
using reference = T&;
using const_reference = const T&;
constexpr intrusive_ptr() noexcept : ptr_(nullptr) {}
@qrealka
qrealka / wininet_auth.cpp
Created June 11, 2018 10:57
wininet basic auth
// Main function
if(!ConnectionInit()) throw IDS_INET_CONNECT_ERR;
if ( !(hInternetReq = HttpOpenRequest(m_hInternetConn,
lpVerb,
lpUrl,
HTTP_VERSION,
TEXT(""),
(LPCTSTR*) AcceptTypes,
dwFlags,
@qrealka
qrealka / bits.cpp
Created June 13, 2018 19:02
pack unpack bits
template <class T, class InputIt, class OutputIt>
void pack_bits_to(InputIt first, InputIt last, OutputIt d_first)
{
static_assert(std::is_integral<T>::value);
while (first != last) {
DataType buf = 0;
for (std::size_t i = 0; i < 8 * sizeof(T); ++i) {
bool bit = (first != last) ? (*(first++)) : 0;
template <class I, // I models ForwardIterator
class P, // P is binary predicate (value_type(I), value_type(I)) -> bool
class O> // O is a function (I, I) -> void
auto split(I begin, I end, P predicate, O subsequnce) -> O {
while(begin != end) {
auto split_pos = std::adjacent_find(begin, end, predicate);
if (split_pos != end) ++split_pos;
subsequnce(begin, split_pos);
begin = split_pos;
}
@qrealka
qrealka / procdump
Created July 10, 2018 10:38
procdump KB
How to collect memory dumps using ProcDump
Introduction
Process memory dumps are very efficient sources of information that are used for troubleshooting websites, which is the reason they are frequently requested by Sitecore Support.
Various tools exist that allow collecting the memory dumps of a specific process, both based on user request (on-demand), as well as based on a specific event (conditional).
This article describes the way to gather memory dumps using the ProcDump application.
@qrealka
qrealka / prototype.cpp
Last active July 26, 2018 08:27
one prototype
// ref_counter.h
class ref_counter {
std::atomic<size_t> references;
public:
size_t aquire();
size_t release();
};
// TODO: perhaps could be better use boost TypeErasure to make it shorter
// interface.h
@qrealka
qrealka / tag_backend.cpp
Created July 27, 2018 07:55
tagged backend
#include <memory>
#include <string>
#include <atomic>
class base_object {
std::atomic<size_t> ref_count;
public:
size_t aquire() { return ++ref_count; }
size_t release() { return --ref_count; }
};