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 / 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.
@haseeb-heaven
haseeb-heaven / PyPiano.py
Created November 24, 2023 23:26
Turn your keyboard to Piano using Python.
import io
from pydub import AudioSegment
from pydub.generators import Sine
from pydub.playback import play
from pynput.keyboard import Key, Listener
import threading
from math import log2
# Function to generate a sine wave tone
def generate_tone(frequency, duration=500):
@haseeb-heaven
haseeb-heaven / heaven_gpt.py
Last active September 18, 2023 18:07
Heaven-GPT a free GPT by Heaven using free GPT 4 API.
import os
import logging
from litellm import completion
## set ENV variables
os.environ["OPENAI_API_KEY"] = "set anything here - key is not used for proxy"
logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s',level=logging.INFO)
def get_chat_completion(messages,model, api_base, custom_llm_provider, temperature, max_tokens, stream):
@haseeb-heaven
haseeb-heaven / ChatGPT-Plugin-Template.py
Created May 26, 2023 10:53
This is ChatGPT Plugin Template for FastAPI shows directory structure and necessary FastAPI request component initialized.
"""
Description: This is ChatGPT Plugin for [YOUR_APP_NAME]
Server API : FastAPI.
Language: Python.
Date: 26/05/2023.
Author : HeavenHM
"""
# Importing the required libraries.
from fastapi import FastAPI, Request, Depends,Response
@haseeb-heaven
haseeb-heaven / NumberBaseValidator.c
Created March 3, 2023 23:10
This C program detects the base of an input number and validates it. The program examines the first few characters of the input string to detect the base (binary, octal, decimal, or hexadecimal) and validates the input number to ensure that it contains only valid digits for the detected base
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
bool IsValidNumber(char *p_input, int base);
int DetectBase(char *p_input);
int main() {
@haseeb-heaven
haseeb-heaven / PrintContainer.cpp
Last active November 22, 2023 00:14
C++ General way of printing data of container including List,Sets,Maps,Stack,Queues etc.
/*
Info: C++ General way of printing data of container including List, Sets, Maps, Stack, Queues, etc.
Author: Haseeb Mir @2022.
*/
#include <iostream> // For input/output operations
#include <map> // For std::map
#include <stack> // For std::stack
#include <queue> // For std::queue
@haseeb-heaven
haseeb-heaven / ResolveType.cpp
Created June 16, 2022 15:06
C++ Data type resolve in Compile-Time using T-Template and Runtime using TypeId.
/*
Info: C++ Data type resolve in Compile-Time using T-Template and RunTime using TypeId.
Author: Haseeb Mir @2022.
*/
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <string_view>