Skip to content

Instantly share code, notes, and snippets.

View ghostgato's full-sized avatar
👻

Darren ghostgato

👻
  • Ether
View GitHub Profile
@ghostgato
ghostgato / signalhandling.md
Created March 10, 2026 14:50
Signal Handling

Linux Signal Handling — TL;DR

Remember: signals come from the OS. The kernel decides a signal is pending for your process or thread, and when your code gets CPU time again, delivery happens according to the handling rules you previously told the OS to use.
Almost every signal-related function is a variation of: “kernel, for signal X, do Y.”

Core setup / registration

  • sigaction()
    Register with the OS that you want a specific way of handling a signal, such as running your handler function, ignoring it, or restoring default behavior.
  • sigemptyset(): Clear set
@ghostgato
ghostgato / unittest_assertions.md
Last active August 20, 2025 17:58
Python unittest Assertions

Python unittest Assertions

Equality and Identity

self.assertEqual(a, b)          # a == b
self.assertNotEqual(a, b)       # a != b
self.assertIs(a, b)            # a is b
self.assertIsNot(a, b)         # a is not b
@ghostgato
ghostgato / assertions.py
Created August 20, 2025 17:28
Python unittest Cheat Sheet
self.assertEqual(a, b) # a == b
self.assertNotEqual(a, b) # a != b
self.assertTrue(x) # bool(x) is True
self.assertFalse(x) # bool(x) is False
self.assertIs(a, b) # a is b
self.assertIsNot(a, b) # a is not b
self.assertIsNone(x) # x is None
self.assertIsNotNone(x) # x is not None
self.assertIn(a, b) # a in b
self.assertNotIn(a, b) # a not in b
@ghostgato
ghostgato / unity_asserts.md
Last active August 14, 2025 18:10
Unity Testing Assert Functions

Unity Test Framework Asserts Cheat Sheet 📋

Language: C
Testing framwork: Unity

This cheat sheet provides an overview of key assertions in the Unity Test Framework, commonly used for unit testing in C. Each assertion includes a description, syntax, and practical examples to help you write effective tests. 🚀

Basic Assertions 🧪

@ghostgato
ghostgato / ProcessingOps.md
Created August 12, 2025 19:12
Processing Operations Ranked

🔴 Most Expensive Operations (High Cost) Memory Allocations (malloc, calloc, realloc, free)

These involve system calls or interactions with the heap manager.

Slow because they may require searching free lists, splitting blocks, or coalescing memory.

Disk or I/O Operations (fread, fwrite, etc.)

Extremely slow compared to CPU-bound code.

@ghostgato
ghostgato / Getopt.c
Created August 5, 2025 14:59
Getopt template
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
// Structure to hold all parsed options
typedef struct {
int verbose;
int debug;
int quiet;
@ghostgato
ghostgato / doublearr.c
Last active July 23, 2025 14:10
Double array allocation
static char **
create_matrix (int rows, int columns)
{
if (!rows || !columns)
{
return NULL;
}
char **pp_matrix = malloc(rows * sizeof(char *));
if (!pp_matrix)
@ghostgato
ghostgato / convert_endian.c
Created May 17, 2025 22:10
Convert Endianess, Swaps Bytes
// swaps bytes to change endianess
// void pointer to be used for any data type to swap bytes
void reverse_bytes(const void *src, void *dest, size_t size)
{
const uint8_t *s = src;
uint8_t *d = dest;
for (size_t i = 0; i < size; i++)
{
@ghostgato
ghostgato / swap_endian_double.c
Last active May 17, 2025 22:08
Swap Endianess of a Double
// able to be used both ways, to go little to big or big to little.
double swap_double_endian(const uint8_t *in)
{
uint8_t reversed_bytes[8];
for (int i = 0; i < 8; i++)
{
reversed_bytes[i] = in[7 - i];
}
@ghostgato
ghostgato / Makefile
Last active April 30, 2025 20:30
Makefile Template
.PHONY: debug clean all tidy tsan asan
BIN := TEST
OBJ_DIR := obj
SRC_DIR := src
INC_DIR := include
STANDARD := -std=c99