Skip to content

Instantly share code, notes, and snippets.

View hamza-cskn's full-sized avatar
🎯
Focusing

Hamza Coşkun hamza-cskn

🎯
Focusing
  • Türkiye/Kocaeli
  • 07:58 (UTC +03:00)
View GitHub Profile
@hamza-cskn
hamza-cskn / inline_memory_debugger.c
Created March 16, 2025 02:32
memory debugger.c
⁠ void z(char c,int n){while (n--> 0)printf("%c",c);}void y(void *q,int k){while(k-->0)if(*(unsigned char*)q>=32&&*(unsigned char*)q<=126)printf("%c ",*(unsigned char*)q++);else printf(". ");}void x(void *q,int k){while(k-->0)printf("%02x ",*(unsigned char*)q++);}void print_memory(void *q,int k){unsigned char*mem=(unsigned char*)q;int n,d=8,f=0;while(f<=k/d){n=d<k-f*d?d:k-f*d;printf("%p: ",mem);x(mem,n);z(' ',(d - n)*3);printf("-> ");y(mem, n);printf("\n");mem += n;f++;}} ⁠
@hamza-cskn
hamza-cskn / logs.sh
Created February 2, 2026 12:05
Docker logs but only important ones. No fuzzy/exact duplicates.
docker logs containername | grep -ie error | sed 's/^[^ ]* //' | awk '!seen[$0]++' | awk '
function sim(a,b, i,c) {
if (length(a)!=length(b)) return 0
c=0
for (i=1;i<=length(a);i++)
if (substr(a,i,1)==substr(b,i,1)) c++
return c/length(a)
}
{
for (i in buf)
@hamza-cskn
hamza-cskn / period_utils.go
Created January 15, 2025 18:02
a util file to help periodical time calculations.
package utils
import (
"time"
)
// Period type to represent a point in modularized time.
/**
* e.g: Every monday at 10:00.
* duration: period duration is one week.
@hamza-cskn
hamza-cskn / K8sHpaSimulation.java
Last active August 23, 2024 09:50
Replica of Kubernetes HPA algorithm and auto scale simulation.
class K8sHpaSimulation {
public static void main(String[] args) {
final double tolerance = 0.1; // 0 < x < 1
final double targetUtilization = 50; // 0 < x < 100
final double requestedMetricPerPod = 40;
final double limitMetricPerPod = 80;
final int podScaleUpPolicyCount = 16;
final int podScaleDownPolicyCount = 2;
@hamza-cskn
hamza-cskn / output_capturing.c
Created February 15, 2024 17:56
Output capturing for tests in c.
#include <unistd.h>
#include <fcntl.h>
#define OUTPUT_BUFFER_SIZE 1024
struct listen_data
{
int fd_copy;
int fd;
int *pipe_fd;
@hamza-cskn
hamza-cskn / sum-and-multiply.c
Last active December 2, 2023 16:55
Multiply and sum implementations using only bitwise operators. (negative numbers are not supported.)
int get_bit(int val, int bit) {
return (val >> bit) & 1;
}
/* sets ith bit to zero*/
int set_zero_bit(int val, int i) {
return val & (~(1 << i));
}
/* sets ith bit to one*/
@hamza-cskn
hamza-cskn / delimiter-validation.js
Created November 7, 2023 19:26
Finite State Machine Delimiter Validation
const State = {
next: undefined,
isLookingFor(char) {
throw new Error('Not implemented');
}
};
const assert = (ensureTrue, message="Validation failed.") => {
if (!ensureTrue)
throw new Error(message);
@hamza-cskn
hamza-cskn / binarytest.c
Created June 25, 2023 07:08
bit to string, string to bit serialization.
#include <stdio.h>
void right_shift_bit(char *c, int last_bit) {
if (last_bit)
*c = (*c >> 1) | 0b10000000;
else
*c = (*c >> 1) & 0b01111111;
}
int get_bit(char c, int bit_index) {
@hamza-cskn
hamza-cskn / Gradient.java
Last active May 23, 2023 02:43
Gradient Colored Text Animation API
import net.md_5.bungee.api.ChatColor;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Gradient {
List<String> gradient;
private int getSnakeSlot(int slot) {
final int horizontalLength = 2;
final int verticalLength = 5;
final int patternLength = 2 * (horizontalLength + verticalLength);
final int patternNo = slot / (patternLength + 1); // 10 -> 1, 8/10 -> 1, 12/10 -> 2
int slotNoInPattern = slot % (patternLength + 1); // 8/10 -> 8, 12/10 -> 2
final boolean isInReversedPattern = slotNoInPattern > patternLength / 2;