Skip to content

Instantly share code, notes, and snippets.

View ubombar's full-sized avatar
🏗️
Building tech

Ufuk Bombar ubombar

🏗️
Building tech
  • Sorbonne University
  • Paris
  • X @ububfr
View GitHub Profile
@ubombar
ubombar / main.go
Created May 27, 2025 09:14
Ants v2 Example for Creating a Thread Pool
package main
import (
"fmt"
"github.com/panjf2000/ants/v2"
"sync"
)
func task(i int) {
fmt.Printf("Processing task %d\n", i)
@ubombar
ubombar / main.py
Last active May 7, 2025 14:08
Compute the accuracy of Longest Common Prefix
import ipaddress
from collections import defaultdict
from matplotlib import pyplot as plt
import matplotlib.ticker as mtick
def longest_common_prefix_length(ip_list: list[int]):
if not ip_list:
return 0
min_ip = min(ip_list)
@ubombar
ubombar / main.go
Created March 26, 2025 23:36
Example go pipeline code
package main
import (
"context"
"fmt"
"sync"
)
// A worker consumes elements type T and produces elements type K.
type Worker[T any, K any] interface {
@ubombar
ubombar / main.go
Created March 23, 2025 01:26
Recursive solution of Hanoi problem after I saw it on Lex's podcast
package main
import "fmt"
type Pair struct {
i, j int
}
func Hanoi() []Pair {
return hanoi(3, 0, 2)
@ubombar
ubombar / main.c
Created March 8, 2025 11:37
Arduino vcc tester
#define VCC_THRESHOLD 13.0 // Voltage threshold in volts
#define OUTPUT_PIN 7 // Pin to control VCC output
void setup() {
pinMode(OUTPUT_PIN, OUTPUT);
}
void loop() {
float vcc = readVcc(); // Read the actual VCC voltage
@ubombar
ubombar / brute-force.py
Created February 14, 2025 23:51
MindYourDecisions Puzzle Solver
from itertools import permutations
def satisfied(x: list[int]) -> bool:
return (x[0] + x[1] - x[2] == x[3]) and (x[4] - x[5] == x[6]) and (x[7] + x[8] == x[9])
def generate(n: int):
digits = list(range(0, 10))
# digit_digits = [digits for _ in range(n)]
for comb in permutations(digits, n):
yield list(comb)
@ubombar
ubombar / next-hop.sql
Last active December 16, 2024 13:57
Next hop calculation using the results table.
-- Create the results table since combination is not supported in materialized views.
CREATE TABLE results_0bffc356_a59b_4a9b_92e9_e579996e1506
ENGINE = MergeTree()
ORDER BY probe_src_addr AS (SELECT * FROM merge('cleaned_results__0bffc356_a59b_4a9b_92e9_e579996e1506__.*') LIMIT 0)
-- Create Materlialized View for the next opts
CREATE MATERIALIZED VIEW nexthops_0bffc356_a59b_4a9b_92e9_e579996e1506
ENGINE = SummingMergeTree
ORDER BY (src_addr, dst_addr, next_hop) AS (
SELECT
@ubombar
ubombar / copy.sh
Created December 16, 2024 11:36
Clickhouse data copier script
#!/bin/bash
# set -x
source .env
# Variables
# DEV_CH_USER=""
# DEV_CH_PASSWD=""
# DEV_CH_DB=""
# DEV_CH_URL=""
# PROD_CH_USER=""
#!/bin/bash
mkdir install
cd install
sudo apt update && sudo apt upgrade -y
echo "Installing containerd"
# wget https://github.com/containerd/containerd/releases/download/v1.7.0/containerd-1.7.0-linux-amd64.tar.gz
# sudo tar Czxvf /usr/local containerd-1.7.0-linux-amd64.tar.gz
# wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

Go Unit Testing Best Practices

There are some tips to increase the code quality and maintainability:

  • Apply clean code philosophy for example implement functions short and give them a single task.

  • Write functions as agnostic as possible. Use abstractions, interfaces and mocks.

  • Measure performance of the code through benchmarks and load tests.

  • Understand business logic better by testing regular and edge cases.