Skip to content

Instantly share code, notes, and snippets.

View odeblic's full-sized avatar

Olivier de BLIC odeblic

View GitHub Profile
#include <readline/history.h>
#include <readline/readline.h>
#include <iostream>
#include <vector>
std::vector<std::string> commandList =
{
"start",
"status",
"stop",
import hashlib
import os
from PIL import Image
import struct
class Synanceia(object):
def __init__(self, original_image_file=None, modified_image_file=None):
self.__image_file = modified_image_file
if original_image_file is None:
@odeblic
odeblic / smart_dtor.cpp
Last active October 7, 2018 21:10
Smart destructor
#include <iostream>
#include <memory>
struct Base
{
~Base()
{
std::cout << "~Base()" << std::endl;
}
};
@odeblic
odeblic / hash_pair.cpp
Last active May 6, 2020 13:58
Add the missing hash function for pairs in the standard.
#include <string>
#include <unordered_map>
namespace std {
template <typename F, typename S>
struct hash<std::pair<F, S>>
{
std::size_t operator()(std::pair<F, S> const &p) const
{
@odeblic
odeblic / exceptions.cpp
Last active August 2, 2018 13:03
Simultaneous exceptions
#include <iostream>
#include <exception>
struct bar
{
~bar()
{
std::cout << std::uncaught_exceptions() << " uncaught exceptions (bar 1)\n";
try
@odeblic
odeblic / flush.cpp
Created August 24, 2017 08:20
Cost of flushing files
#include <chrono>
#include <cstdio>
#include <iostream>
void write_file(std::FILE* fd)
{
for (int i=0; i<1000000; i++)
{
std::fprintf(fd, "iteration no %d (last bit=%d)\n", i, i % 2);
}
@odeblic
odeblic / finance.cpp
Created August 19, 2017 04:27
Financial tools
class Price
{
public:
Price(double val)
{
mValue = val * 1000;
}
operator double()()
{
@odeblic
odeblic / monitoring.cpp
Created August 11, 2017 09:02
Monitoring and heartbeat
#include <thread>
#include <chrono>
class Monitor
{
public:
void onHeartbeat(int id, int status)
{
lastTimestamp = std::chrono::system_clock::now();
}
@odeblic
odeblic / bytes.cpp
Created August 2, 2017 14:51
Representations of bytes
#include <iostream>
#include <cstddef>
void action(char arg)
{
std::cout << "char arg -> " << (int)arg << "\n";
}
void action(signed char arg)
{
@odeblic
odeblic / jinja2.py
Last active August 2, 2017 14:57
To be tested...
#pragma once
{% block title %}
{% endblock %}
{% for this_class in all_classes %}
class {{ this_class.name }}
{
{% for this_class in this_class.private %}