This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will prepend or define XPATH with the value unless it already exists | |
# any empty arguments will not be added | |
robust_prepend() | |
{ | |
case ":${XPATH-}:" in | |
*:"${1-}":*) ;; | |
*) XPATH="${1-}${XPATH:+${1:+:}$XPATH}" | |
esac | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_col_widths(table): | |
""" | |
Return a list with the widest column length in | |
each column from the table. | |
""" | |
result = [] | |
for column in zip(*table): | |
max_ = 0 | |
for elem_in_column in column: | |
max_ = max(len(str(elem_in_column)), max_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <exception> | |
#include <iostream> | |
#include <new> | |
#define CATCH_UNHANDLED 0 | |
#define TOOL_NAME "<your tool name here>" | |
char const KToolName[] = TOOL_NAME; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared_ptr<widget> get_widget(int id) { | |
static map<int, weak_ptr<widget>> cache; | |
static mutex m; | |
lock_guard<mutex> hold(m); | |
auto sp = cache[id].lock(); | |
if (!sp) cache[id] = sp = load_widget(id); | |
return sp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
widget& instance() { | |
static widget w; | |
return w; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stopwatch { | |
using clock = std::chrono::high_resolution_clock; | |
bool is_running() const { return stop_time_ == clock::time_point::min(); } | |
clock::time_point end_time() const { return is_running() ? clock::now() : stop_time_; } | |
clock::time_point begin_time_{clock::now()}, stop_time_{clock::time_point::min()}; | |
public: | |
void stop() { if (is_running()) stop_time_ = clock::now(); } | |
clock::duration elapsed() const { return end_time() - begin_time_; } | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaptureStream { | |
private: | |
std::basic_ios<char>& m_stream; | |
std::streambuf* m_orig_streambuf; | |
std::stringstream m_buffer; | |
CaptureStream(CaptureStream const&) = delete; | |
CaptureStream& operator=(CaptureStream const&) = delete; | |
public: | |
CaptureStream(std::basic_ios<char>& stream) : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example of settings to CMake I use | |
Overrides RelWithDebugInfo from '-O2' to '-Og' | |
Also sets TYPE to 'Debug' | |
And example of setting the Eclipse executable path. | |
alias ncmake='CXX=g++ CC=gcc cmake -DCMAKE_C_FLAGS_RELWITHDEBINFO="-Og -g -DNDEBUG" -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-Og -g -DNDEBUG" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-v -DCMAKE_ECLIPSE_EXECUTABLE=/home/bo/eclipse/cpp-mars/eclipse/eclipse -DCMAKE_ECLIPSE_VERSION:STRING="4.5 (Mars)" -G "Eclipse CDT4 - Ninja"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
char int8_err [-1 + 2 * (sizeof(int8_t) == 1)]; | |
char uint8_err [-1 + 2 * (sizeof(uint8_t) == 1)]; | |
char int16_err [-1 + 2 * (sizeof(int16_t) == 2)]; | |
char uint16_err[-1 + 2 * (sizeof(uint16_t) == 2)]; | |
char int32_err [-1 + 2 * (sizeof(int32_t) == 4)]; | |
char uint32_err[-1 + 2 * (sizeof(uint32_t) == 4)]; | |
} throwaway_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original example from https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html | |
#include <cmath> | |
#include <cstdlib> | |
#include <array> | |
#include <exception> | |
#include <iostream> | |
#include <sstream> | |
#include <stdexcept> | |
#include <cxxabi.h> |
OlderNewer