Skip to content

Instantly share code, notes, and snippets.

View kevinkreiser's full-sized avatar

Kevin Kreiser kevinkreiser

  • osm.org/node/158543009
  • 03:06 (UTC -04:00)
View GitHub Profile
@kevinkreiser
kevinkreiser / json_serializer.cpp
Last active April 4, 2017 19:59
Serialize Json with C++11 Initializer List Syntax
//Build this with something like: g++ json_serializer.cpp -std=c++11 -I/usr/include
//Requires you at least have boost base library
#include <ostream>
#include <boost/variant.hpp>
#include <memory>
#include <string>
#include <cinttypes>
#include <cstddef>
#include <unordered_map>
@kevinkreiser
kevinkreiser / logging.hpp
Last active April 17, 2024 13:25
Thread-safe logging singleton c++11
#ifndef __LOGGING_HPP__
#define __LOGGING_HPP__
/*
Test this with something like:
g++ -std=c++11 -x c++ -pthread -DLOGGING_LEVEL_ALL -DTEST_LOGGING logging.hpp -o logging_test
./logging_test
*/
#include <string>
@kevinkreiser
kevinkreiser / testing.hpp
Last active August 29, 2015 14:14
Unit testing framework for c++
#ifndef __TESTING_HPP__
#define __TESTING_HPP__
/*
* Test this with something like:
* g++ -std=c++11 -x c++ -DTEST_TESTING testing.hpp -o testing_test
* ./testing_test
*/
@kevinkreiser
kevinkreiser / pretty_print_gdb.sh
Last active August 18, 2017 13:58
gdb pretty print stl containers
cat <<EOF > ~/.gdbinit
set history save
set history size 10000
set history filename ~/.gdb_history
define f
finish
end
document f
Step out of a function, finish it
@kevinkreiser
kevinkreiser / memory_status.cpp
Last active August 29, 2015 14:15
Programmatically Get at Memory Usage via Proc Status
#include <fstream>
#include <string>
#include <iostream>
#include <cinttypes>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <list>
@kevinkreiser
kevinkreiser / kyotocabinet_hash_map_test.cpp
Last active August 29, 2015 14:15
Kyotocabinet File Based Hash Map Tests for Reading and Writing
/*
sudo apt-get install libkyotocabinet-dev
g++ kyotocabinet_hash_map_test.cpp -o kyotocabinet_hash_map_test -std=c++11 -O2 -lkyotocabinet
./kyotocabinet_hash_map_test 500000
./kyotocabinet_hash_map_test 500000 threaded_read
*/
#include <fstream>
#include <string>
#include <iostream>
@kevinkreiser
kevinkreiser / sequence.cpp
Last active October 12, 2016 15:39
memory map backed stl vector like container for fixed sized structures (PODs)
/*
g++ sequence.cpp -o sequence -std=c++11 -O2
./sequence_t 100000000
*/
#include <iostream>
#include <cstring>
#include <chrono>
#include <fstream>
@kevinkreiser
kevinkreiser / spmc.cpp
Last active October 3, 2022 05:31
Single Producer Multiple Consumer with ZeroMQ/ZMQ/ØMQ Butterfly Pattern
/* install libzmq-dev:
*
* wget http://download.zeromq.org/zeromq-4.1.0-rc1.tar.gz
* tar pxvf zeromq-4.1.0-rc1.tar.gz
* cd zeromq-4.1.0
* ./autogen.sh
* ./configure
* make
* sudo make install
*
@kevinkreiser
kevinkreiser / memc.cpp
Created March 20, 2015 16:03
Memcached Benchmark which Caches a Directory and Reads it Back
/*
* sudo apt-get install memcached libmemcached-dev libboost-all-dev
* have a look in /etc/memcached.conf and set some reasonable defaults
* changed the following:
* -m 4096m -I 10m
*
* sudo service memcached restart
*
* g++ memc.cpp -o memc -std=c++11 -g -O2 -lboost_system -lboost_filesystem -lmemcached
* memc /some/directory/with/files 2147483648
@kevinkreiser
kevinkreiser / blob_cache.cpp
Last active August 29, 2015 14:17
A Data Blob Cache with Configurable Eviction Policies
/*
* sudo apt-get install libboost-all-dev
* #if you want to mmap more files than what `sysctl vm.max_map_count` says
* sudo sysctl -w vm.max_map_count=some_larger_number
* g++ blob_cache.cpp -o blob_cache -std=c++11 -g -O2 -lboost_system -lboost_filesystem
* blob_cache /some/directory/with/files 1073741824
* blob_cache /some/directory/with/files 1073741824 mm
*/
#include <boost/filesystem.hpp>