Skip to content

Instantly share code, notes, and snippets.

View keyboardsmoke's full-sized avatar
🏴‍☠️
yarg

Andrew Artz keyboardsmoke

🏴‍☠️
yarg
View GitHub Profile
@keyboardsmoke
keyboardsmoke / metaprogramming.cpp
Created August 11, 2021 18:34
Insane, that's me bud
#include <iostream>
#include <vector>
#include <cinttypes>
#pragma pack(1)
class ParentRegister
{
public:
struct InitializationTrick
{
#pragma once
namespace Framework
{
#pragma pack(push, 1)
// TODO: Float16, not really.... needed
// https://github.com/facebookincubator/gloo/blob/master/gloo/types.h
#pragma once
#include "platform.h"
#pragma pack(push, 1)
// TODO: Float16, not really.... needed
// https://github.com/facebookincubator/gloo/blob/master/gloo/types.h
enum class IEEEClass
//
void print_bytes(void *p, size_t size)
{
unsigned char *c = (unsigned char *)p;
printf("B [0x%X] { ", size);
for (size_t i = 0; i < size; i++)
{
if (i == (size - 1))
{
#pragma once
template<typename T>
class SafeBuffer
{
public:
SafeBuffer(size_t size) : m_size(size) {
m_buffer = new T[size];
if (!m_buffer)
throw;
@keyboardsmoke
keyboardsmoke / gist:9dce8a5fa5ca13f0225e130ea7c54e99
Last active September 29, 2016 14:47
Convert byte string into full byte
#include <iostream>
#include <string>
#include <math.h>
unsigned char chrtob(char c) {
if (c >= 'A' && c <= 'F') return c - 55;
else if (c >= 'a' && c <= 'f') return c - 87;
else if (c >= '0' && c <= '9') return c - 0x30;
return 0;
}
@keyboardsmoke
keyboardsmoke / getMainThreadId.cpp
Created November 21, 2015 16:35
Get Main Thread Id
#include "stdafx.h"
#include <conio.h>
#include <TlHelp32.h>
typedef NTSTATUS(WINAPI *NtQueryInformationThread_t)(HANDLE ThreadHandle, THREADINFOCLASS ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength, PULONG ReturnLength);
NtQueryInformationThread_t pNtQueryInformationThread = NULL;
BOOL GetMainThreadId(DWORD *pdwThreadId)
{
@keyboardsmoke
keyboardsmoke / ConstRandom.cpp
Created August 11, 2015 02:50
C++14 Compile-time Random
#pragma once
namespace ConstRandom
{
// It's T time
template<typename T> constexpr T time() {
return (T)
(
(__TIME__[7] - '0') * 0x0001 + (__TIME__[6] - '0') * 0x000A +
(__TIME__[4] - '0') * 0x003C + (__TIME__[3] - '0') * 0x0258 +