Skip to content

Instantly share code, notes, and snippets.

@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 | erayozturk1@gmail.com
*/
#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 | erayozturk1@gmail.com
*/
#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 | erayozturk1@gmail.com
*/
#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.
*/