Skip to content

Instantly share code, notes, and snippets.

View haseeb-heaven's full-sized avatar
🏠
Working from home

HeavenHM haseeb-heaven

🏠
Working from home
View GitHub Profile
@haseeb-heaven
haseeb-heaven / interactive_calculator_ui.c
Last active February 19, 2025 02:32
A terminal-based calculator program written in C that simulates a physical calculator. Uses C with classes, handles errors safely, and shows a colorful number pad interface. Supports basic math operations with high decimal precision.
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#ifdef _WIN32
#include <conio.h>
void clear_screen() { system("cls"); }
@haseeb-heaven
haseeb-heaven / crud_file.cpp
Created January 3, 2025 19:43
CRUD Operations with std::print and clean optimised code with binary file support using latest C++ 23.
#include <fstream>
#include <string>
#include <print> # C++ 23 print
#include <stdexcept>
bool is_binary_file(const std::string& filename) {
std::ifstream input_file_stream(filename, std::ios::binary);
if (!input_file_stream) {
throw std::runtime_error("Could not open file '" + filename + "'.");
}
@haseeb-heaven
haseeb-heaven / falling_matrix.cpp
Created January 1, 2025 14:34
Simulation of falling matrix in C++ 20 , modular and robust approach.
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <thread>
#include <chrono>
void initialize_random_seed() {
std::random_device rd;
std::srand(rd());
@haseeb-heaven
haseeb-heaven / void_return.c
Last active January 4, 2025 12:04
An innovative approach to returning values from void/null-based methods using function pointers, ensuring compatibility across all major operating systems.
#include <stdio.h>
#include <stdint.h>
// Define ARCH_NAME based on the detected architecture
#if defined(__x86_64__) || defined(_M_X64)
#define ARCH_NAME "x86_64"
#elif defined(__i386__) || defined(_M_IX86)
#define ARCH_NAME "x86"
#elif defined(__aarch64__) || defined(_M_ARM64)
#define ARCH_NAME "ARM64"
@haseeb-heaven
haseeb-heaven / hex_float_converter_endianness.cpp
Last active December 10, 2024 00:25
A C++17 tool convertes hexadecima into floating-point numbers. It features functions for parsing input, swapping byte order, and converting to float. The code emphasizes clarity, efficiency, and robust error handling to ensure reliable performance. Was actually derived from https://gregstoll.com/~gregstoll/floattohex/
#include <iostream>
#include <iomanip>
#include <string>
#include <stdexcept>
#include <cstdint>
#include <cstring>
#include <limits>
#include <cstdlib>
float parse_hex_to_float(const std::string& hex_str) {
@haseeb-heaven
haseeb-heaven / file_checker.cpp
Created December 1, 2024 18:55
Advanced File Type Detection Program like GNU file type detection tool
// Advanced File Type Detection Program like GNU file type detection tool
// Note: This program is a simplified version and may not cover all possible file types.
// Created by: HeavenHM.
// Date: 2024-01-12
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <algorithm>
@haseeb-heaven
haseeb-heaven / heaven_endianness_checker.cpp
Created March 24, 2024 22:37
Welcome to Heaven's Endianness Number Analyzer!
#include <iostream>
#include <bitset>
#include <stdexcept>
#include <iomanip>
// Function to check if the system is little endian
bool isSystemLittleEndian() {
int testNumber = 1;
return *(char*)&testNumber == 1;
}
@haseeb-heaven
haseeb-heaven / ArgsParserLib.c
Created January 14, 2024 14:25
This is small method library to parse all arguments from command line in C.
#include <stdio.h> // Include header for standard input/output functions
#include <assert.h> // Include header for the assert function
#define NOB_ASSERT assert // Define NOB_ASSERT as an alias for assert
// Function to shift the first argument from argv and update argc
char *nob_shift_args(int *argc, char ***argv) {
NOB_ASSERT(*argc > 0); // Assert that there's at least one argument
char *result = **argv; // Store the first argument in result
(*argv) += 1; // Increment argv to point to the next argument
@haseeb-heaven
haseeb-heaven / CodeRunner.sh
Last active January 4, 2024 00:05
A universal script for compiling and running various programming languages. It supports C, C++, Java, Go, C#, Python, JavaScript, Swift, Scala, Ruby, and Kotlin, identifying the language by file extension and using the appropriate compiler or interpreter, usage: ./CodeRunner.sh program.cpp
#!/bin/bash
# Get the filename from the command line argument
filename=$1
debug=0
cpp_version="c++17"
# Determine the file extension, compiler, and language based on the filename
if [[ $filename == *.c ]]; then
extension=".c"
@haseeb-heaven
haseeb-heaven / MemorySizeDetector.c
Last active December 11, 2023 23:04
Cross-Platform Memory Size Detector in C portable way.
/*
Description: Cross-Platform Memory Size Detector in C
Author: HeavenHM
Language: C
Date: 12-12-2023
Compilers Tested: GCC, Clang, MSVC.
Platforms Tested: Unix,Linux, MacOS, Windows.
*/
// Includes for cross-platform compatibility.