Skip to content

Instantly share code, notes, and snippets.

Jean-Bernard Jansen duckie

Block or report user

Report or block duckie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / cpp_file_simulatneous_read_write.cpp
Created Jun 27, 2012
C++ : How to write and read with only one file open for both operations
View cpp_file_simulatneous_read_write.cpp
#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <string>
std::ostream & format_2_l0(std::ostream & iStream)
{
return iStream << std::setw(2) << std::setfill('0');
}
@duckie
duckie / french_number_writer.cpp
Created Aug 2, 2012
Converts a number into its litteral french translation
View french_number_writer.cpp
#include <iostream>
#include <map>
#include <sstream>
/**
* Converts a number into its french representation
*
* @see http://fr.wikipedia.org/wiki/Adjectif_num%C3%A9ral
*/
class Convertisseur
@duckie
duckie / errors.h
Created Aug 3, 2012
Utility to parse a header, extract error codes and store them into a *.map re-usable from C++ code.
View errors.h
#ifndef IBM_ERRORS
#define IBM_ERRORS
/**
* C'est un peu la fête du slip les codes d'erreurs en macros
*/
#define ERREUR_MARCEL_A_TROP_BU 1
#define ERREUR_ROBERT_A_TROP_MANGE 2
# define ERREUR_Y_A_PLUS_DE_PASTIS 3
You can’t perform that action at this time.