Skip to content

Instantly share code, notes, and snippets.

/**
* \file
* Trace and log functions and macros
*/
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2007 - 2023 Vladimir Ivanov <knebekaizer@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
template <typename T1, typename T2>
typename std::enable_if<std::is_same<T1,T2>::value, bool>::type
test(T1 a = {}, T2 b = {}) {
log_trace << "Not implemented, or template parameter types are not supported: "
"T1: " << typeid(T1).name() << "; T2: " << typeid(T2).name();
return false;
}
template <typename T1, typename T2>
typename std::enable_if<!std::is_same<T1,T2>::value, bool>::type
@knebekaizer
knebekaizer / term_colors.c
Created October 12, 2023 13:10
terminal colors
#include <stdio.h>
int main(void)
{
int i, j, n;
for (i = 0; i < 11; i++) {
for (j = 0; j < 10; j++) {
n = 10 * i + j;
if (n > 108) break;
# output binary
BIN := x
# source files
SRCS := \
x.c
# files included in the tarball generated by 'make dist' (e.g. add LICENSE file)
DISTFILES := $(BIN)
template <bool retainAutorelease>
static ALWAYS_INLINE id Kotlin_ObjCExport_refToObjCImpl(ObjHeader* obj) {
if (obj == nullptr) return nullptr;
if (obj->has_meta_object()) {
id associatedObject = GetAssociatedObject(obj);
if (associatedObject != nullptr) {
return retainAutorelease ? objc_retainAutoreleaseReturnValue(associatedObject) : associatedObject;
}
}
Also, please write good git commit messages. A good commit message
looks like this:
Header line: explain the commit in one line (use the imperative)
Body of commit message is a few lines of text, explaining things
in more detail, possibly giving some background about the issue
being fixed, etc etc.
The body of the commit message can be several paragraphs, and
/#include <thread>
#include <future>
#include <iostream>
#include <chrono>
#include <vector>
#include <array>
#include <cassert>
#include <cstdlib> // _Exit() "stdlib.h"
#include <unistd.h> // sleep()
@knebekaizer
knebekaizer / stacktrace.cxx
Created June 3, 2020 08:17 — forked from fmela/stacktrace.cxx
A C++ function that produces a stack backtrace with demangled function & method names.
/*
* Copyright (c) 2009-2017, Farooq Mela
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@knebekaizer
knebekaizer / ExtVector_hack.cpp
Last active November 11, 2019 19:00
The hack to convert ExtVector to CXType_Vector
namespace clng {
// All the types below are POD and bitwise compatible with corresponding clang classes
struct PointerIntPair {
intptr_t Value = 0;
};
struct QualType {
PointerIntPair Value; // llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>, Qualifiers::FastWidth> Value;
};