Skip to content

Instantly share code, notes, and snippets.

Jean-Bernard Jansen duckie

View GitHub Profile
View 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 Aug 29, 2015
Generate an image in Microsoft BMP format
View write_bmp_image.cc
#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 Jul 26, 2014
Virtuality with a variadic interface.
View virtual_variadic.cpp
#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 Jan 31, 2019
C++11 - make_function : template resolution of a callable (function, lambda or functor) to the corresponding std::function
View make_function.cpp
#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 Jun 10, 2014
Private data member with automatic public read-only through an accessor.
View readonly_member.cpp
#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_; }
View string_list_vs_string_unordered_set.cpp
#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 Jun 4, 2014
Compare performances between different intersection algorithms
View list_intersection_performance.cpp
#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 Jun 3, 2014
Compute intersection of two lists - Method 2
View list_intersection_2.cpp
#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 Jun 3, 2014
Compute intersection of two lists - Method 1
View list_intersection_1.cpp
#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 Jan 1, 2016
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…
View colorscale.cpp
#include <array>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <tuple>
#include <set>
#include <map>
#include <vector>
namespace colorscale {
You can’t perform that action at this time.