Skip to content

Instantly share code, notes, and snippets.

View virtualsafety's full-sized avatar

virtualsafety virtualsafety

View GitHub Profile
@hatarist
hatarist / pg_get_table_sizes.sql
Created September 8, 2017 15:48
PostgreSQL: get table size (data & index & toast)
SELECT
*,
pg_size_pretty(table_bytes) AS table,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(total_bytes) AS total
FROM (
SELECT
*, total_bytes - index_bytes - COALESCE(toast_bytes, 0) AS table_bytes
FROM (
SELECT
@jtbr
jtbr / endianness.h
Last active October 14, 2025 08:31
cross-platform / cross-compiler standalone endianness conversion
/**
* @file endianness.h
* @brief Convert Endianness of shorts, longs, long longs, regardless of architecture/OS
*
* Defines (without pulling in platform-specific network include headers):
* bswap16, bswap32, bswap64, ntoh16, hton16, ntoh32 hton32, ntoh64, hton64
*
* Should support linux / macos / solaris / windows.
* Supports GCC (on any platform, including embedded), MSVC2015, and clang,
* and should support intel, solaris, and ibm compilers as well.
@HertzDevil
HertzDevil / enum_traits.hpp
Last active December 25, 2023 06:31
safer enums in c++
#pragma once
#include <type_traits>
#include <limits>
// The default enumeration category. Conversion is equivalent to static_cast.
// Unspecialized enumeration traits use this category.
struct enum_default { };
// The standard-layout enumeration category. Values outside the given range are
@YahiaBakour
YahiaBakour / SkipList.h
Created May 24, 2018 18:28
SkipList Implementation, C++
// By your BOI : Yahia B
// feel free to take whatever you would like
#ifndef SkipList_H
#define SkipList_H
#include <iostream>
#include <cstdlib>
#include <limits>
#include <random>
#include <ctime>
#include <vector>
@SubCoder1
SubCoder1 / RB-Tree.cpp
Created August 22, 2018 17:26
Red Black Tree implementation in C++
#include <bits/stdc++.h>
using namespace std;
struct node {
int data{};
node* left = nullptr;
node* right = nullptr;
node* parent = nullptr;
string color;
};
@olibre
olibre / cpp_legacy_inheritance_vs_std_variant.md
Last active June 6, 2025 07:27 — forked from GuillaumeDua/cpp_legacy_inheritance_vs_std_variant.md
C++ legacy inheritance vs CRTP + std::variant
@Kielx
Kielx / CPP colors
Created May 3, 2021 06:50
c++ terminal output colors
You need the terminal color codes. For linux it's the following (your system might be different, look it up):
//the following are UBUNTU/LINUX, and MacOS ONLY terminal color codes.
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
@GuillaumeDua
GuillaumeDua / Concept-based polymorphism in modern Cpp.md
Last active December 7, 2025 15:15
Concept-based polymorphism in modern C++

Concept-based polymorphism in modern C++

Date 05-05-2021 - 10-17-2023
Revision R3
Author Guillaume Dua
Reviewers Loïc Joly, Antoine Morrier
@MangaD
MangaD / perf.md
Created February 27, 2025 06:31
Comprehensive Guide to Using `perf` for C++ Applications

📌 Comprehensive Guide to Using perf for C++ Applications

CC0

Disclaimer: ChatGPT generated document.

Linux’s perf is a powerful profiling tool that helps analyze CPU usage, cache misses, function call costs, branch mispredictions, and more in C++ applications. This guide will cover:

Installing and setting up perfBasic and advanced profiling commands