Skip to content

Instantly share code, notes, and snippets.

@daverigby
daverigby / checkpoint_iterator1.cpp
Created November 22, 2018 11:13
Checkpoint iterator model using raw reverse iterators (working)
#include <iostream>
#include <vector>
void print(const std::vector<int>& v) {
std::cout << "[";
for (auto& e : v) {
std::cout << e << " ";
}
std::cout << "]\n";
}
# Need to install libasan to be able to run sanitized
# binaries on a machine different to the build machine
# (for example for RPM sanitized packages).
# First need to get the compiler search dirs; then locate
@daverigby
daverigby / CLion_Ninja.md
Created July 3, 2018 10:00 — forked from nevkontakte/CLion_Ninja.md
Ninja support for CLion IDE

Ninja support for CLion IDE

This script enables Ninja-powered builds in CLion IDE by wrapping around CMake, which it uses. See my blog post for details.

Disclaimer

This script is provided AS IS with no guarantees given or responsibilities taken by the author. This script relies on undocumented features of CLion IDE and may lead to instability of build and/or IDE. Use it on your own risk under WTFPL terms.

@daverigby
daverigby / ubsan_break_on_runtime_errors
Last active June 19, 2018 12:40
UBSan: break on runtime errors in debugger
b __asan_backtrace_alloc
# GCC 7 on Ubuntu 16.06 requires a different symbol:
break __sanitizer::Die()
@daverigby
daverigby / undefined-enum
Last active March 15, 2018 14:18
Example of UBSan enum error
$ cat undefined.cc
#include <stdexcept>
enum Enum {
A,
B,
C,
Invalid
};
@daverigby
daverigby / c++_pretty_printing.md
Created March 13, 2018 16:52
Enable C++ pretty printing on CentOS 7

$ cat ~/.gdbinit python import sys sys.path.insert(0, '/usr/share/gcc-4.8.2/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) end

@daverigby
daverigby / mac_os_core_id.cc
Last active January 24, 2018 22:39
get current core number on macOS
#include <atomic>
#if defined(__i386__) || defined(__x86_64__)
#include <cpuid.h>
#endif
#include <cstdio>
#include <chrono>
#include <cinttypes>
static inline uint64_t rdtscp( uint32_t & aux )
{
grep table_file_creation cbcollect_info_ns_1\@172.23.96.117_20180103-232325/kv_rocks.log|cut -d ' ' -f 4- | jq -c '[.cf_name, (.table_properties.raw_key_size + .table_properties.raw_value_size) / .table_properties.data_size]'
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <iostream>
#include <vector>
#include "date.h" // From https://github.com/HowardHinnant/date/blob/master/include/date/date.h
static constexpr const size_t magnitude_bits = 4;
ExternalProject_Add(rocksdb
GIT_REPOSITORY https://github.com/couchbasedeps/rocksdb.git
GIT_TAG ${_git_rev}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
LIST_SEPARATOR " "
BUILD_COMMAND CFLAGS=-Ifoo/include;-Ibar/include $(MAKE)
)