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
  • 14:10 (UTC +03:00)
View GitHub Profile
@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 / 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 / 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 / CoordinateRounder.java
Last active March 24, 2023 12:24
Coordinate rounder for arenas of Bedwars1058. (mostly written by ChatGPT)
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CoordinateRounder {
@hamza-cskn
hamza-cskn / ft_split.c
Created February 19, 2023 07:15
split exercise for école thirty four
#include <stdlib.h>
#include <printf.h>
int is_seperator(char c) {
return (c == '\0' || c == ' ' || c == '\n');
}
int word_length(char *str) {
int i;