Skip to content

Instantly share code, notes, and snippets.

View Innokentiy-Alaytsev's full-sized avatar

Innokentiy Alaytsev Innokentiy-Alaytsev

View GitHub Profile
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / has_member.cpp
Created May 24, 2020 22:33
"Has member" traits for member variables and functions, and nested types
#include <memory>
#include <type_traits>
#include <iostream>
enum class MemberAccess { kProtected, kPublic };
#define GENERATE_MEMBER_ACCESSOR(...) \
template < class, AccessRequirement > \
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / has_member.hpp
Last active May 19, 2020 15:32
Check if a type has a member function
#include <type_traits>
#include <iostream>
// The general idea is stollen from here:
// https://stackoverflow.com/questions/44229676/how-to-decide-if-a-template-specialization-exist
template< class T >
struct FunSig;
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / file.hpp
Created May 18, 2020 17:05
Constexpr type name
#include <iostream>
#include <memory>
#include <string_view>
#if defined (__clang__) || defined (__GNUG__)
template<class TString>
constexpr auto FindTypeNameBegin (TString&& i_str) {
int index = 0;
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / has_member.hpp
Created June 25, 2018 19:11 — forked from maddouri/has_member.hpp
Checking the Existence of a C++ Class Member at Compile Time
// A compile-time method for checking the existence of a class member
// @see https://general-purpose.io/2017/03/10/checking-the-existence-of-a-cpp-class-member-at-compile-time/
// This code uses "decltype" which, according to http://en.cppreference.com/w/cpp/compiler_support
// should be supported by Clang 2.9+, GCC 4.3+ and MSVC 2010+ (if you have an older compiler, please upgrade :)
// As of "constexpr", if not supported by your compiler, you could try "const"
// or use the value as an inner enum value e.g. enum { value = ... }
// check "test_has_member.cpp" for a usage example
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / PostMortemCollectible.hpp
Last active June 3, 2018 07:25
Post mortem object handler
#include <functional>
#include <iostream>
template < class Payload, class ActualPayload = Payload >
class PostMortemCollectible {
public:
struct GetPayloadRawPtr {
static ActualPayload *GetPayloadPtr (const Payload &i_payload) {
return &i_payload;
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / GridStream.js
Created March 16, 2018 14:39 — forked from psi-4ward/GridStream.js
NodeJS MongoDB-GridFS Video range stream example Lets your browser seek/jump wihin the video-playback.
var app = require('express')();
var GridStore = require('mongodb').GridStore;
var ObjectID = require('mongodb').ObjectID;
var MongoClient = require('mongodb').MongoClient;
var Server = require('mongodb').Server;
var dbConnection;
MongoClient.connect("mongodb://localhost:27017/ersatz?auto_reconnect", {journal: true}, function(err, db) {
dbConnection = db;
app.listen(3000);
@Innokentiy-Alaytsev
Innokentiy-Alaytsev / bindPropertyEditors.cpp
Last active July 6, 2017 03:02
Qt UI binding to the QObject properties
#include "PropertiesEditorsBinding.h"
#include <QCheckBox>
#include <QHash>
#include <QLineEdit>
#include <QMap>
#include <QMetaObject>
#include <QMetaProperty>
#include <QObject>
#include <QRegularExpression>
// Bresenham3D
//
// A slightly modified version of the source found at
// http://www.ict.griffith.edu.au/anthony/info/graphics/bresenham.procs
// Provided by Anthony Thyssen, though he does not take credit for the original implementation
//
// It is highly likely that the original Author was Bob Pendelton, as referenced here
//
// ftp://ftp.isc.org/pub/usenet/comp.sources.unix/volume26/line3d
//