Skip to content

Instantly share code, notes, and snippets.

View xealits's full-sized avatar
🥘

Alex Toldaiev xealits

🥘
View GitHub Profile
#include <iostream>
struct FuncPtr;
typedef FuncPtr(Func)(int);
struct FuncPtr {
void *func;
FuncPtr(Func& f) : func{(void *) &f} {};
FuncPtr operator()(int x) { return ((Func *)func)(x); }
};
@xealits
xealits / specialise_variadic_templates-dd3a0e.cpp
Created June 18, 2025 21:45
clang 18.1.3 bug report Preprocessed source
This file has been truncated, but you can view the full file.
# 1 "<built-in>"
# 1 "specialise_variadic_templates.cpp"
#if defined(__CLANG_REWRITTEN_INCLUDES) || defined(__CLANG_REWRITTEN_SYSTEM_INCLUDES) /* iostream expanded by -frewrite-includes */
#include <iostream>
#else /* iostream expanded by -frewrite-includes */
# 1 "specialise_variadic_templates.cpp"
# 1 "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/iostream" 1 3
// Standard iostream objects -*- C++ -*-
// Copyright (C) 1997-2023 Free Software Foundation, Inc.
@xealits
xealits / duck_typing_static.cpp
Last active May 28, 2025 21:52
Static duck typing in C++
#include <iostream>
#include <source_location>
#include <string>
struct Quack;
template <typename T>
concept Duck = requires(T t) {
{ t.quack() } -> std::convertible_to<Quack>;
// could be -> std::same_as<Quack>;
};
@xealits
xealits / query_examples.md
Created January 11, 2025 15:01
clang-query matches

Find references to non-const pointees:

clang-query -c "set output dump" -c "m varDecl(hasType(referenceType(pointee(unless(isConstQualified())))))" source.cpp
@xealits
xealits / pattern_command_1.cpp
Last active October 12, 2024 01:14
Simple pattern examples in C++
/*
* Just some notes while reading Game Programming Patterns by Robert Nystrom
* https://gameprogrammingpatterns.com
*
* A command or event made with C++ std::variant.
* The idea is to pack some similar-size but different types into the command.
* How to subscribe components to events from each other
* and construct it declaratively, at compile time?
* The components send events or commands (command pattern).
* You want to verify the interfaces, preferably statically, i.e. at link time.
@xealits
xealits / basic_macro.nim
Last active February 18, 2024 21:23
Basic macro in NIM
#[
# the example is from https://peterme.net/metaprogramming-and-read-and-maintainability-in-nim.html
# plus I used `quote` instead of direct tree nodes
# it almost works the same way
# except, it seems you cannot declare an empty `enum` under `quote`
]#
import math, strutils
import macros
@xealits
xealits / keybase.md
Created January 28, 2024 17:21
keybase verification

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@xealits
xealits / factorial.cpp
Created February 20, 2022 21:39
C/C++ doctest with separate implementation file and source with tests
#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#include "doctest.h"
//int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }
int factorial(int number) { return number <= 1 ? 1 : factorial(number - 1) * number; }
TEST_CASE("testing the factorial function") {
CHECK(factorial(0) == 1);
CHECK(factorial(1) == 1);
CHECK(factorial(2) == 2);
What exactly is "iowait"?
To summarize it in one sentence, 'iowait' is the percentage
of time the CPU is idle AND there is at least one I/O
in progress.
Each CPU can be in one of four states: user, sys, idle, iowait.
Performance tools such as vmstat, iostat, sar, etc. print
out these four states as a percentage. The sar tool can
print out the states on a per CPU basis (-P flag) but most
@xealits
xealits / gler.py
Last active August 16, 2017 16:03
pyOpenGL example, extended habr_Ti_Fix_shaders.py from https://habrahabr.ru/post/247123/
# -*- coding: utf-8 -*-
# from
# Импортируем все необходимые библиотеки:
from OpenGL.GL import *
from OpenGL.GLU import gluPerspective
from OpenGL.GLUT import *
#import sys
# Из модуля random импортируем одноименную функцию random
from random import random