Skip to content

Instantly share code, notes, and snippets.

@diffstorm
diffstorm / concurrent_circular_buffer.c
Last active June 14, 2025 09:11
Multi-threaded circular buffer library in C that supports simultaneous reading and writing operations
/*
Multi-threaded circular buffer library in C that supports simultaneous
reading and writing operations. It provides options to overwrite the oldest data
when the buffer is full or to skip new data based on a flag. The library includes
functions to initialize, write, read, and clean up the circular buffer, and also
demonstrates concurrent access with multiple writer and reader threads.
The code is written in standard C and can be compiled and executed on various platforms, including Linux, Windows, and macOS. The code does not inherently depend on any specific platform-dependent features, libraries, or APIs. It uses standard C libraries and pthreads for multithreading, which are commonly available on many systems.
Author : Eray Ozturk | [email protected]
@diffstorm
diffstorm / Makefile
Created May 25, 2024 16:49
Example makefile to compile applications and bootloaders with various toolchains
# Purpose:
# This makefile is designed to compile applications and bootloaders with various toolchains.
#
# Features:
# - Supports compiling applications and bootloaders separately or together.
# - Allows specifying different compilers for applications and bootloaders within the same configuration.
# - Supports skipping compilation for specific applications or bootloaders using the "none" keyword.
#
# Configuration Format:
# Configurations are specified in the format:
@diffstorm
diffstorm / StaticMemoryAllocator.c
Created August 13, 2023 13:57
Static memory allocator for embedded systems in C with auto fragmentation where malloc is unwanted
/*
Static memory allocator for embedded systems in C with auto fragmentation where malloc is unwanted
Author : Eray Ozturk | [email protected]
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
struct BlockHeader {
size_t size;
@diffstorm
diffstorm / StaticMemoryAllocator.cpp
Created August 13, 2023 13:51
Static memory allocator for embedded systems in C++ with auto fragmentation where malloc/new is unwanted
/*
Static memory allocator for embedded systems in C++ with auto fragmentation where malloc/new is unwanted
Author : Eray Ozturk | [email protected]
*/
#include <iostream>
#include <cstddef>
class StaticMemoryAllocator {
public:
StaticMemoryAllocator(char* buffer, size_t bufferSize) : buffer_(buffer), bufferSize_(bufferSize), head_(nullptr) {
@diffstorm
diffstorm / filelib.cpp
Created August 13, 2023 13:12
Simple file operations class to write into and read from files in a few formats (CSV, JSON, XML, Plain text) with error handling
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <nlohmann/json.hpp>
#include <tinyxml2.h>
enum class FileFormat {
PlainText,
CSV,
@diffstorm
diffstorm / fractaltree.cpp
Created August 10, 2023 18:52
C++ code drawing a fractal tree into bitmap image on Linux X11
/*
Fractal tree generation/drawing excercise in C++ on Linux X11 with native bitmap format support
Author : Eray Ozturk | [email protected]
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <string>
#include <iostream>
#include <cstring>
#include <cmath>
@diffstorm
diffstorm / binance_BTCUSDT_relative-strength-index.rs
Created June 10, 2023 08:44
Rust code example which prints 1D relative strength index value of Bitcoin on Binance
/*
This program uses the binance crate in Rust to interact with the Binance API. It fetches the 1-day klines (candlestick data) for the BTCUSDT pair and calculates the RSI (Relative Strength Index) using the compute_rsi function. Finally, it prints the calculated RSI for BTCUSDT on Binance.
Note that you'll need to add the binance crate to your Cargo.toml file to use the Binance API in Rust:
[dependencies]
binance = "0.16.0"
Make sure to replace "your_api_key" and "your_secret_key" with your actual Binance API key and secret key.
*/