Skip to content

Instantly share code, notes, and snippets.

Jean-Bernard Jansen duckie

View GitHub Profile
@duckie
duckie / initializer_list.cpp
Created Jan 15, 2013
C++11 initiliazer_list example
View initializer_list.cpp
#include <iostream>
#include <initializer_list>
struct Point {
int m_a;
int m_b;
Point() :
m_a(0), m_b(0) {
}
@duckie
duckie / rank_by_field.cpp
Created Feb 20, 2013
C++11 : Compute a rank with a map.
View rank_by_field.cpp
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
struct guy
{
std::string name_;
float mark_;
@duckie
duckie / gist:5012381
Last active Dec 14, 2015
C++11 trick to create some classes by their ID names.
View gist:5012381
#include <string>
#include <map>
#include <iostream>
#include <utility>
#include <functional>
struct Interface {
virtual void method() = 0; // May be a visitor pattern
};
@duckie
duckie / shrunken_dir.sh
Created Apr 9, 2013
A simple function to shrunken a Unix path to a descriptive fixed size string. I use this for my prompt.
View shrunken_dir.sh
function shrunken_dir(){
SEP="/"
ESC_SEP="\\$SEP"
HEADER_SIZE=5
SIZE_MAX=$1
current_disp=`pwd`
seen_path_max_length=$((SIZE_MAX-HEADER_SIZE))
current_seen_path=$(echo "$current_disp"|tr -s "$SEP")
nb_dirs=0
seen_path_length=$(expr length "$current_seen_path")
@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 {
@duckie
duckie / data_sort_by_member.cpp
Created Jun 27, 2012
C++ : How to sort a vector of a user struct/class by using one of its members
View data_sort_by_member.cpp
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
struct Donnees
{
int m_1;
std::string m_2;
float m_3;
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 / 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 / timer.cpp
Created Sep 26, 2013
A C++11 example of a timer in a thread. This is one way in thousands to do it.
View timer.cpp
#include <iostream>
#include <chrono>
#include <thread>
#include <ctime>
#include <atomic>
void called() {
std::cout << "Coucou !" << std::endl;
}
You can’t perform that action at this time.