Skip to content

Instantly share code, notes, and snippets.

View OlivierLDff's full-sized avatar

Olivier Le Doeuff OlivierLDff

View GitHub Profile
@OlivierLDff
OlivierLDff / (QtQml) Outline Rectangle
Created December 12, 2018 14:40
Qml Rectangle to outline the size of a qml object. Really useful when debugging
Rectangle
{
width: parent.width
height: parent.height
border.color: "red"
border.width: 1
color: "transparent"
}
if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
# do stuff
endif()
if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug")
# do stuff
endif()
@OlivierLDff
OlivierLDff / DumpByteArrayToQString.cpp
Created December 4, 2018 21:01
(C++/Qt) Dump QByteArray as QString
QString DumpByteArray(QByteArray& rawData)
{
QString res = "{ ";
for (int i = 0; i<rawData.size(); ++i)
{
res += "0x";
res += QString::number((rawData[i] >> 4) & 0xF, 16);
res += QString::number((rawData[i]) & 0xF, 16);
if (i != rawData.size() - 1)
res += ", ";
@OlivierLDff
OlivierLDff / bin2c.c
Last active October 29, 2018 16:23 — forked from albertz/bin2c.c
bin2c
// https://gist.github.com/albertz/1551304
#include <stdio.h>
#include <assert.h>
int main(int argc, char** argv) {
assert(argc == 2);
char* fn = argv[1];
FILE* f = fopen(fn, "r");
printf("char a[] = {\n");
SET(EREIFLASH_VERSION_MAJOR 1)
SET(EREIFLASH_VERSION_MINOR 0)
SET(EREIFLASH_VERSION_PATCH 0)
IF( EXISTS "${CMAKE_SOURCE_DIR}/.git" )
EXECUTE_PROCESS(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${EREIFLASH_SOURCE_DIR}
OUTPUT_VARIABLE EREIFLASH_VERSION_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
#ifdef __GNUC__
/*code for GNU C compiler */
#define PRE_PACKED_ENUM_DEF
#define POST_PACKED_ENUM_DEF __attribute__((packed));
#elif _MSC_VER
/*code specific to MSVC compiler*/
#define PRE_PACKED_ENUM_DEF __pragma(pack(push, 1))
#define POST_PACKED_ENUM_DEF __pragma(pack(pop));
#elif __MINGW32__
/*code specific to mingw compilers*/
#ifdef WIN32
#ifdef LIB_SHARED // Shared build
#define LIB_API __declspec(dllexport)
#elif LIB_STATIC // No decoration when building staticlly
#define LIB_API
#else // Link to lib
#define LIB_API __declspec(dllimport)
#endif
#else
#define LIB_API
#define ANSI_FG_RED "\x1b[31m"
#define ANSI_FG_BRIGHT_RED "\x1b[91m"
#define ANSI_FG_GREEN "\x1b[32m"
#define ANSI_FG_BRIGHT_GREEN "\x1b[92m"
#define ANSI_FG_YELLOW "\x1b[33m"
#define ANSI_FG_BRIGHT_YELLOW "\x1b[93m"
#define ANSI_FG_BLUE "\x1b[34m"
#define ANSI_FG_BRIGHT_BLUE "\x1b[94m"
#define ANSI_FG_MAGENTA "\x1b[35m"
#define ANSI_FG_BRIGHT_MAGENTA "\x1b[95m"
size_t getline(char **lineptr, size_t *n, FILE *stream) {
char *bufptr = nullptr;
size_t it = 0;
int c;
if (lineptr == nullptr) {
return -1;
}
if (stream == nullptr) {
return -1;