Skip to content

Instantly share code, notes, and snippets.

View odeblic's full-sized avatar

Olivier de BLIC odeblic

View GitHub Profile
@odeblic
odeblic / dna.cpp
Created July 29, 2017 00:43
DNA encoding and decoding
#include <iostream>
struct Wheel
{
wheel(char initial_escape_symbol) : escape_id(0), left_id(1), right_id(2), switch_id(3) { while(symbols[escape_id] != esc) rotate(); }
void rotate() { escape_id++; left_id++; right_id++; switch_id++; }
char getEscapeSymbol() { return symbols[escape_id]; }
@odeblic
odeblic / head_tail.cpp
Created July 29, 2017 00:42
Head or tail prediction
#include <iostream>
#include <ctime>
inline bool randomBool()
{
return rand() % 2;
}
int heads = 0;
int tails = 0;
@odeblic
odeblic / sampling.py
Created July 29, 2017 00:40
Data sampling for latency measurement
import random
class Sampling(object):
def __init__(self, size_max):
self.__count = 0
self.__samples = list()
self.__size_max = size_max
def sample(self, value):
@odeblic
odeblic / containers.cpp
Created July 29, 2017 00:39
containers
#include <iostream>
#include <list>
#include <chrono>
#include <functional>
MEASURE(ID, STATEMENT)
M_START(ID)
M_STOP(ID)
class Queue
@odeblic
odeblic / fast_logger.cpp
Created July 29, 2017 00:38
fast logger
class FastLogger
{
void registerMessage(int msgId, std::string& )
{
}
void logMessage(enum logType, int msgId)
{
}
@odeblic
odeblic / diamond.cpp
Last active July 28, 2017 11:15
Consequence of diamond inheritance
#include <iostream>
struct X
{
protected:
int i;
};
struct A : X
{
@odeblic
odeblic / size_vtable.cpp
Created July 28, 2017 10:44
Size of classes with and without a vtable
#include <iostream>
struct A
{
};
struct B : A
{
};
@odeblic
odeblic / sfinae.cpp
Created July 28, 2017 09:04
SFINAE in practice
#include <iostream>
struct Object
{
typedef int type;
static void action()
{
std::cout << "Object::action()" << std::endl;
}
@odeblic
odeblic / exchange.cpp
Created July 28, 2017 04:34
Draft of exchange simulator
#include <iostream>
#include <mutex>
#include <functional>
class Price
{
std::uint64_t value;
std::ratio<1, 100> value;
};
@odeblic
odeblic / smart_pointers.cpp
Last active July 28, 2017 03:16
Why we should be careful when deciding to use the factory function std::make_shared
#include <iostream>
#include <memory>
#include <list>
struct Heavy
{
char buffer[1024 * 1024 * 8];
};
std::list<std::weak_ptr<Heavy>> container;