Skip to content

Instantly share code, notes, and snippets.

View StrikerX3's full-sized avatar

Ivan Roberto de Oliveira StrikerX3

View GitHub Profile
@StrikerX3
StrikerX3 / lifetime_checker.hpp
Created January 2, 2024 18:16
C++ lifetime checker struct
#pragma once
#include <cstdio>
// A simple object lifetime checker.
// Use this to figure out if/when your objects are being created, destroyed, copied or moved.
struct LifetimeChecker {
LifetimeChecker() {
printf("LifetimeChecker()\n");
}
@StrikerX3
StrikerX3 / list_critical_processes.cpp
Created December 13, 2023 01:27
List all critical processes on Windows
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
void PrintProcessNameAndID(DWORD processID) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID);
if (NULL != hProcess) {
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
DWORD size = sizeof(szProcessName) / sizeof(TCHAR);
@StrikerX3
StrikerX3 / 1_tsc_exact.cpp
Last active October 13, 2023 16:36
Get TSC frequency on Windows
#include <stdio.h>
#include <intrin.h>
#pragma intrinsic(__cpuid)
int main() {
int id[4];
__cpuid(id, 0x15);
auto tscFreq = (__int64)id[2] * id[1] / id[0];
printf("TSC frequency: %I64d Hz (%I64d MHz)\n", tscFreq, tscFreq / 1000000ULL);
#pragma once
#include <functional>
#include <type_traits>
#include <utility>
namespace util {
namespace detail {
@StrikerX3
StrikerX3 / place.png
Last active April 4, 2022 21:27
r/MysteryDungeon template
place.png
@StrikerX3
StrikerX3 / enum_bitmask.hpp
Last active March 10, 2023 13:40
Type-safe enum bitmasks
/*
Type-safe enum class bitmasks.
Based on work by Andre Haupt from his blog at
http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/
To enable enum classes to be used as bitmasks, use the ENABLE_BITMASK_OPERATORS
macro:
enum class MyBitmask {
None = 0b0000,
One = 0b0001,
Two = 0b0010,
@StrikerX3
StrikerX3 / tsc.cpp
Last active March 22, 2022 03:15
Get approximate TSC frequency on Windows
#include <stdio.h>
#include <intrin.h>
#pragma intrinsic(__rdtsc)
#include <Windows.h>
int main() {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
@StrikerX3
StrikerX3 / circular_buffer.cpp
Created March 16, 2018 20:55
DirectSound buffer example
#include "stdafx.h"
#include "circular_buffer.h"
CircularBuffer::CircularBuffer(int size)
{
init(size, false);
}
CircularBuffer::CircularBuffer(int size, bool filled)
{