Skip to content

Instantly share code, notes, and snippets.

View Manu343726's full-sized avatar

Manu Sánchez Manu343726

View GitHub Profile
@Manu343726
Manu343726 / cpp14monad.cpp
Last active January 23, 2024 11:41
C++14 tuple continuation monad
//Author: Manu Sánchez (Manu343726). Aug 2014
//Everything started from this: http://stackoverflow.com/questions/25338795/is-there-a-name-for-this-tuple-creation-idiom
//Now, play with C++14!
#include <utility>
#include <iostream>
#include <exception>
template<typename... Ls>
@Manu343726
Manu343726 / cowbasic_string.hpp
Last active November 15, 2023 17:44
(conceptual) COW string implementation
/*
* A simple Copy On Write (COW) string implementation.
*
* Copyright © 2014 Manu Sanchez. @Manu343726 on GitHub, Stack Overflow, etc.
*
* manu343726.github.io
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
@Manu343726
Manu343726 / multiple_variants_run.cmake
Created September 5, 2015 21:14
Run a cmake project multiple times with multiple variants
# Custom target to do all the work with a simple command:
add_custom_target(run_all COMMAND ${CMAKE_COMMAND} -E echo \">>>> Running all variants\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set(common_flags "-DGENERATE_ASSEMBLY=${GENERATE_ASSEMBLY} -DCPU_MODEL=\"${CPU_MODEL}\"")
if(WIN32)
list(APPEND VARIANTS "-G \"Visual Studio 14\" -DCMAKE_BUILD_TYPE=Release")
list(APPEND VARIANTS "-G \"Visual Studio 14\" -DCMAKE_BUILD_TYPE=Debug")
list(APPEND VARIANTS "-G \"Unix Makefiles\" -DCMAKE_BUILD_TYPE=Release")
list(APPEND VARIANTS "-G \"Unix Makefiles\" -DCMAKE_BUILD_TYPE=Debug")
@Manu343726
Manu343726 / gist:ca0ceb224ea789415387
Created September 19, 2015 18:15
Running ARM docker image with QEMU on x86_64 Arch Linux host
# Install quemu, docker, etc
yaourt -S qemu qemu-user-static binfmt-support
# The quemu-user-static AUR package is outdated and broken. The .deb package they pull is no longer in the ubuntu repository.
# Edit the PKGBUILD and use qemu-user-static_2.4+dfsg-3_amd64.deb (With SHA1 sum "84d83a16c60c82b6c579f2f750b04a3ac26c249b")
# Enable ARM emulation
update-binfmts --enable qemu-arm
@Manu343726
Manu343726 / assembly_out.cmake
Created September 5, 2015 21:33
Generating assembly listings with CMake
## Variables:
#
# OUTPUT_DIRECTORY: Directory where the assemblu file will be placed (For example "/home/manu/listings")
# ASSEMBLY_LISTING_FILE: Assembly listing filename (For example "foo.s")
# SOURCE_FILENAME: Name of the sourcefile being compiled (See bellow). For example "foo", from foo.cpp.
# TARGET: Target being compiled (Mostly an executable target). For example "foo".
if(MSVC)
# Trust me, Microsoft docs suck.
target_compile_options(${TARGET} "/Fa${OUTPUT_PATH}/${ASSEMBLY_LISTING_FILE}" /FA)
@Manu343726
Manu343726 / CMakeLists.txt
Created October 26, 2016 14:02
Configure protobuf with cmake
cmake_minimum_required(VERSION 3.4)
project(MyProject)
if(NOT MY_PROJECT_PROTOBUF_VERSION)
set(MY_PROJECT_PROTOBUF_VERSION 2.6.1)
endif()
option(MY_PROJECT_SHARED_LIBS "Build proto modules as shared libraries" OFF)
message(STATUS "Google Protocol Buffers version: ${MY_PROJECT_PROTOBUF_VERSION}")
@Manu343726
Manu343726 / named_tuple.cpp
Created August 22, 2015 18:28
C++ named tuples
#include <tuple>
#include <cstdint>
#include <iostream>
namespace foonathan {
namespace string_id {
namespace detail
{
using hash_type = std::uint64_t;
@Manu343726
Manu343726 / examples.cmake
Last active August 4, 2020 21:22
Promote target to thirdparty
external_dependency(rttr https://github.com/rttrorg/rttr.git v0.9.6) 17 external_dependency(MetaStuff https://github.com/Manu343726/MetaStuff master) + 18 mark_as_external_target(rttr_core)
mark_as_external_target(rttr)
@Manu343726
Manu343726 / test_structs.h
Last active December 1, 2019 20:07
tinyrefl generated code example
#ifndef TEST_STRUCTS_H
#define TEST_STRUCTS_H
#include <string>
#include <vector>
#include <set>
namespace test_structs
{
enum class Enum
@Manu343726
Manu343726 / test_structs.h
Created December 1, 2019 20:00
tinyrefl generated code example
#ifndef TEST_STRUCTS_H
#define TEST_STRUCTS_H
#include <string>
#include <vector>
#include <set>
namespace test_structs
{
enum class Enum