Skip to content

Instantly share code, notes, and snippets.

@halfelf
halfelf / type_name.cpp
Created May 14, 2019 05:02
Get C++ type name
template <class T>
constexpr std::string_view type_name() {
#ifdef __clang__
std::string_view p = __PRETTY_FUNCTION__;
return std::string_view(p.data() + 34, p.size() - 34 - 1);
#elif defined(__GNUC__)
std::string_view p = __PRETTY_FUNCTION__;
# if __cplusplus < 201402
return std::string_view(p.data() + 36, p.size() - 36 - 1);
# else
@peterspackman
peterspackman / mingw-w64-x86_64.cmake
Last active July 3, 2024 03:20
cmake toolchain file for mingw-w64 x86_64 builds on Ubuntu
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake ..
# This is free and unencumbered software released into the public domain.
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
def urldecode:
def unhex:
if 48 <= . and . <= 57 then . - 48 elif 65 <= . and . <= 70 then . - 55 else . - 87 end;
def bytes:
def loop($i):
if $i >= length then empty else 16 * (.[$i+1] | unhex) + (.[$i+2] | unhex), loop($i+3) end;
[loop(0)];
def codepoints:
@daniel-j-h
daniel-j-h / expand_pack.cc
Last active April 20, 2020 13:10
expand_pack --- shortcut for parameter pack expansion into swallowing initializer_list
#include <cstdlib>
#include <iostream>
#include <initializer_list>
#define expand_pack(...) (void) std::initializer_list<int>{((void)(__VA_ARGS__), 0)...};
template <typename... Iter>
void increment_all(Iter&... iters) {
expand_pack(++iters);
}
@coderofsalvation
coderofsalvation / export_process
Last active February 22, 2022 15:38
updates an environment variable of a running process
# updates an environment variable of a running process (needs sudo)
# example: sudo export_pid <variable=value> <pid>
export_process(){
script=/tmp/.gdb.$2
echo -e "attach $2\ncall putenv (\"$1\")\ndetach\n" > $script
gdb -q -batch -x $script &>/dev/null
rm $script
}
@andref
andref / main.cpp
Created May 30, 2012 19:47
Calling QMetaMethods with QVariant arguments and best-effort type conversion
#include <QtCore>
#include <QtDebug>
QVariant call(QObject* object, QMetaMethod metaMethod, QVariantList args)
{
// Convert the arguments
QVariantList converted;
// We need enough arguments to perform the conversion.