Skip to content

Instantly share code, notes, and snippets.

View samilkorkmaz's full-sized avatar

Şamil Korkmaz samilkorkmaz

  • Ankara / Turkey
View GitHub Profile
@samilkorkmaz
samilkorkmaz / freeRTOSSensorActuator.c
Created August 23, 2025 11:51
Low level handling of DHT22 and servo with FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
#include "semphr.h"
// Hardware abstraction layer includes (adjust for your platform)
#include "gpio.h"
#include "timer.h"
#include "uart.h"
@samilkorkmaz
samilkorkmaz / doubleBitShift.java
Last active July 11, 2025 08:38
Comparison of different double to int conversions with bit shifting
/*
* Comparison of different double to int conversions with bit shifting
* Şamil Korkmaz, 10.07.2025
*/
class Main {
public static void main(String[] args) {
//double t = 123.456;
//double t = 256.4321e6;
double t = 258788556.8;
@samilkorkmaz
samilkorkmaz / latencyUDP_TCP.py
Last active April 12, 2025 19:16
This script tests the latency of UDP DNS queries and TCP connections to a web server.
# This script tests the latency of UDP DNS queries and TCP connections to a web server.
# See this post for more: https://simulinkforsoftwareengineers.blogspot.com/2025/04/udp-vs-tcp.html
# Şamil Korkmaz, 12.04.2025
import socket
import time
def udp_dns_test():
server = ("8.8.8.8", 53)
query = b'\xaa\xbb' + b'\x01\x00' + b'\x00\x01' + b'\x00\x00' + b'\x00\x00' + b'\x00\x00' # Header
query += b'\x03www\x06google\x03com\x00' + b'\x00\x01' + b'\x00\x01' # "www.google.com" A record
@samilkorkmaz
samilkorkmaz / intOverflow.cpp
Last active May 7, 2025 12:13
C/C++ integer overflow demo
// C/C++ integer overflow demo showing why compiler overflow warnings should be taken seriously.
// Example of possible overflow: If you have a uint32_t variable that holds time values in microseconds (us),
// the max amount of time it can hold is UINT32_MAX = (2^32 - 1) us = 71.6 minutes.
// A famous overflow example from 1996 caused by casting a 64bit float to 16bit signed int: https://en.wikipedia.org/wiki/Ariane_flight_V88
// 12.04.2025, Şamil Korkmaz
#include <iostream>
#include <cstdint>
int main() {
uint32_t a = 2000000000; // less than max uint32_t value (UINT32_MAX) of 2^32 - 1 = 4294967295
@samilkorkmaz
samilkorkmaz / keepUAVInCenter.py
Last active April 7, 2025 17:06
Skeleton code to generate commands for ArduPilot so that the the target UAV stays in the center of the camera
#!/usr/bin/env python3
"""
UAV Target Tracking with ArduPilot
----------------------------------
This script keeps a detected target UAV centered in the camera view
by sending appropriate commands to ArduPilot using attitude target control.
To install the required libraries, run:
pip install pymavlink opencv-python numpy
"""
@samilkorkmaz
samilkorkmaz / kalmanIMUGPS.py
Created March 1, 2025 15:44
IMU + GPS Kalman filter with 1D motion
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import cumulative_trapezoid
from scipy.stats import norm
class KalmanFilter:
"""
Kalman Filter for 1D position/velocity estimation using IMU and GPS
"""
def __init__(self, dt, accel_noise_std, gps_noise_std):
@samilkorkmaz
samilkorkmaz / puanLGS.py
Last active January 31, 2025 09:45
Liseye Geçiş Sınavı (LGS) puan hesaplama
# Liseye Geçiş Sınavı (LGS) puan hesaplama
# Şamil Korkmaz, 31.01.2025
# Öğrencinin yanlış ve boşları [2,1] = 2 yanlış, 1 boş
yanlis_bos = {
"Türkçe": [2, 1],
"Tarih": [0, 0],
"Din": [0, 0],
"Dil": [0, 0],
"Matematik": [1, 0],
@samilkorkmaz
samilkorkmaz / dequeuWithSearch.cpp
Last active January 22, 2025 11:38
Thread safe dequeue with binary search, C++17
/* Demo of deque (double-ended queue) with size limit and binary search to find closest value.
Şamil Korkmaz, 20.01.2025 */
#include <deque>
#include <vector>
#include <mutex> // std::unique_lock blocks all other threads, used for write operations
#include <shared_mutex> // std::shared_lock allows multiple threads to read simultaneously
#include <thread>
#include <optional> // for std::optional
#include <stdexcept> // for std::runtime_error
@samilkorkmaz
samilkorkmaz / fixedMemoryPool.cpp
Created January 9, 2025 11:43
simple fixed-size memory pool
// This code demonstrates a simple fixed-size memory pool implementation.
// Memory is allocated and managed statically, avoiding heap allocation overhead.
// The implementation uses static storage for the pool and a boolean array to track usage.
//
// Key Features:
// - Allocate and deallocate fixed-size blocks from a pre-allocated pool.
// - Suitable for systems with strict memory constraints, like embedded systems.
// - Provides an example of avoiding dynamic memory (heap) allocation.
// Şamil Korkmaz, 09.01.2025
@samilkorkmaz
samilkorkmaz / fillRectWithSquares.html
Last active December 26, 2024 16:59
Fill a rectangle with minimum number of squares while covering the whole area
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Rectangle Tiling</title>
<style>
body {
font-family: sans-serif;
margin: 20px;
}