Skip to content

Instantly share code, notes, and snippets.

Michael Bartnett michaelbartnett

Block or report user

Report or block michaelbartnett

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View enumflags.hpp
#include <type_traits>
#include <cstdint>
#include <iostream>
template<typename T_ENUM>
class EnumFlags
{
static_assert(std::is_enum<T_ENUM>::value, "T_ENUM must be an enum type");
public:
@michaelbartnett
michaelbartnett / enumshit.cpp
Created Feb 6, 2019
enums with max and string
View enumshit.cpp
template<typename Enum>
constexpr Enum get_enum_max()
{
//static_assert(false, "missing get_enum_max implementation");
return ~0;
}
template<typename Enum>
const char *get_enum_member_name(Enum val);
// {
@michaelbartnett
michaelbartnett / better_narrowing.cpp
Last active Jan 17, 2019
truly horrible constepxr function template for narrowing numeric conversions. doesn't allow conversions between integral and floating point. -std=c++11 and -fno-exceptions compatible. the worst.
View better_narrowing.cpp
// what a mess
#if NDEBUG
template<typename TOut, typename TIn>
constexpr TOut narrowed(TIn&& inp) noexcept
{
return static_cast<TOut>(inp);
}
#define NARROWED(TOut, expr) static_cast<TOut>(expr)
View meh_narrowing.hpp
#include <type_traits>
#include <assert>
// debug = gsl::narrow, release = gsl::narrow_cast
namespace util
{
template <class T, class U>
constexpr T narrowcast(U&& u) noexcept
View prototype_tool_screenshot.png
I tried to make a thing once that could ingest a folder of json/xml/whatever files, infer
a type schema from them, and then give you a spreadsheet style table editor.
The idea was it would infer a schema from the data, or from analyzing your game's source
code (like running reflection over C# assemblies, or parsing C++ headers), and then you
could use that do really complex and wide-reaching "data refactoring."
I didn't move past prototyping because I didn't have enough brainergy after work, but I
think something like this could be made that feels has the good stuff spreadsheets have:
@michaelbartnett
michaelbartnett / hidusage_keys.tsv
Last active Sep 24, 2018
hid usage key codes table cleaned up
View hidusage_keys.tsv
dec hex name typical AT-101position Mac HIToolbox/Events.h Constant
0 0 Reserved (no event indicated) N/A
1 1 Keyboard ErrorRollOver N/A
2 2 Keyboard POSTFail N/A
3 3 Keyboard ErrorUndefined N/A
4 4 Keyboard a and A 31 kVK_ANSI_A
5 5 Keyboard b and B 50 kVK_ANSI_B
6 6 Keyboard c and C 48 kVK_ANSI_C
7 7 Keyboard d and D 33 kVK_ANSI_D
8 8 Keyboard e and E 19 kVK_ANSI_E
View strweird.cpp
#include <string>
#define STR1 "Hello"
//#define STR2 "World"
#define STR2 "12345678123456781234567812345678"
//#define STR2 "Worlda"
#define METHOD 3
std::string get_value(const bool b)
@michaelbartnett
michaelbartnett / launch.json
Created Jul 31, 2018
getting vscode to do c++ stuff, using ms-vscode.cpptools-0.17.7
View launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
@michaelbartnett
michaelbartnett / closures_exceptions.js
Created Oct 13, 2017
Looking for tricky interactions between closures and exceptions
View closures_exceptions.js
let print = console.log
let closure = null
try {
let x = 42
let y = null
closure = (msg) => {
x = x + 1
@michaelbartnett
michaelbartnett / README.md
Last active Jul 27, 2017
clang-shebang. frankensteined shell script and c++ code plus projectile and emacs equals ugly-cute build system
View README.md

Clang-Shebang

Terminal Usage

$ cp clangshebang.cpp myprogram.cpp
$ chmod +x myprogram.cpp
$ ./myprogram.cpp
hello shell
You can’t perform that action at this time.