Skip to content

Instantly share code, notes, and snippets.

@duckie
duckie / keybase.md
Created December 30, 2017 16:21
keybase.md

Keybase proof

I hereby claim:

  • I am duckie on github.
  • I am jeanbernard (https://keybase.io/jeanbernard) on keybase.
  • I have a public key whose fingerprint is 346F 5503 D0C9 EB26 F52A 9559 7F04 A869 ACD6 A71F

To claim this, I am signing this object:

@duckie
duckie / write_bmp_image.cc
Last active August 29, 2015 14:15
Generate an image in Microsoft BMP format
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
#include <cstdint>
#include <array>
using UChar = uint8_t;
using Color = std::array<UChar, 3>;
using Image = std::vector<Color>;
@duckie
duckie / virtual_variadic.cpp
Created July 26, 2014 14:36
Virtuality with a variadic interface.
#include <string>
#include <sstream>
#include <iostream>
#include <memory>
struct Serializer {
virtual ~Serializer() {}
virtual void StartRecord() = 0;
virtual void EndRecord() = 0;
@duckie
duckie / make_function.cpp
Last active December 6, 2020 14:07
C++11 - make_function : template resolution of a callable (function, lambda or functor) to the corresponding std::function
#include <functional>
namespace functional {
template <typename Function> struct function_traits;
template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType(ClassType::*)(Args...) const> {
using function = const std::function<ReturnType(Args...)>;
};
@duckie
duckie / readonly_member.cpp
Created June 10, 2014 01:33
Private data member with automatic public read-only through an accessor.
#include <memory>
template <class Parent, typename T> class readable final {
friend Parent;
T value_;
operator T& () { return value_; }
public:
readable(T const& v) : value_(v) {}
readable(T&& v) : value_(std::move(v)) {}
T const& operator () () { return value_; }
#include <iostream>
#include <chrono>
#include <vector>
#include <set>
#include <list>
#include <unordered_set>
#include <random>
#include <string>
#include <sstream>
@duckie
duckie / list_intersection_performance.cpp
Created June 4, 2014 13:08
Compare performances between different intersection algorithms
#include <iostream>
#include <string>
#include <unordered_set>
#include <set>
#include <list>
#include <algorithm>
#include <random>
#include <chrono>
#include <sstream>
@duckie
duckie / list_intersection_2.cpp
Created June 3, 2014 16:14
Compute intersection of two lists - Method 2
#include <iostream>
#include <string>
#include <set>
#include <unordered_set>
#include <list>
#include <algorithm>
using namespace std;
template <typename T> using intersection_set = set<reference_wrapper<T const>, less<T>>;
@duckie
duckie / list_intersection_1.cpp
Created June 3, 2014 16:07
Compute intersection of two lists - Method 1
#include <iostream>
#include <string>
#include <unordered_set>
#include <list>
#include <algorithm>
using namespace std;
list<string> compare_list_warning(list<string> const& list_one, list<string> const& list_two)
{
list<string> const& small_list = list_one.size() < list_two.size() ? list_one : list_two;
@duckie
duckie / colorscale.cpp
Last active January 1, 2016 03:38
C++11 - Associate a RGB color to a given unsigned integral number in order to maximize local contrast. Two algorithms are given. The second is called in the main loop. With no arguments, a consistency check verifies that every possible color in the context are used, with no overlap. With 1 arguments, it outputs the colors from index 0 to ARG (in…
#include <array>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <tuple>
#include <set>
#include <map>
#include <vector>
namespace colorscale {