Skip to content

Instantly share code, notes, and snippets.

View oNddleo's full-sized avatar
🎯
Focusing

Nguyα»…n Đức Long oNddleo

🎯
Focusing
  • Thanh Oai, HΓ  Nα»™i
  • 07:40 (UTC +07:00)
  • LinkedIn in/longnd1
  • Facebook 9u6u07
View GitHub Profile
@oNddleo
oNddleo / redis-kafka.md
Created March 7, 2025 04:04
Redis stream vs Kafka

Lựa chọn giữa Kafka và Redis Streams cho Event Driven Architecture

Khi xΓ’y dα»±ng hệ thα»‘ng Event Driven, việc lα»±a chọn cΓ΄ng nghệ stream phΓΉ hợp lΓ  quyαΊΏt Δ‘α»‹nh quan trọng. DΖ°α»›i Δ‘Γ’y lΓ  phΓ’n tΓ­ch để giΓΊp bαΊ‘n quyαΊΏt Δ‘α»‹nh giα»―a Kafka vΓ  Redis Streams:

TiΓͺu chΓ­ chΓ­nh để lα»±a chọn

Chọn Kafka khi:

  1. Hệ thα»‘ng cΓ³ quy mΓ΄ lα»›n vΓ  phα»©c tαΊ‘p
  • Nhiều microservices (10+ services)
@oNddleo
oNddleo / redis-stream.md
Created March 7, 2025 02:14
Redis stream

VΓ­ dα»₯ Producer vΓ  Consumer Redis Stream vΓ  Đo Hiệu NΔƒng 100K Request

DΖ°α»›i Δ‘Γ’y lΓ  vΓ­ dα»₯ về cΓ‘ch triển khai Producer vΓ  Consumer vα»›i Redis Stream, cΓΉng vα»›i cΓ‘ch Δ‘o hiệu nΔƒng khi xα»­ lΓ½ 100K request:

1. CΓ i Δ‘αΊ·t Redis

TrΖ°α»›c khi bαΊ―t Δ‘αΊ§u, hΓ£y Δ‘αΊ£m bαΊ£o bαΊ‘n Δ‘Γ£ cΓ i Δ‘αΊ·t Redis (phiΓͺn bαΊ£n 5.0+)

# Vα»›i Docker
@oNddleo
oNddleo / kafka.md
Created March 6, 2025 06:23
Producer consumer

Here are examples of Kafka producer and consumer in Go (Golang) that connect to a Bitnami Kafka instance in Kubernetes via port forwarding:

Kafka Producer in Go

package main

import (
	"context"
	"fmt"
@oNddleo
oNddleo / prevent-spam-registration.md
Last active March 4, 2025 01:50
Prevent spam registration
-- IP-based rate limiting table
CREATE TABLE ip_rate_limits (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
ip_address VARCHAR(45) NOT NULL, -- IPv4 or IPv6 address
endpoint VARCHAR(100) NOT NULL, -- Which endpoint was accessed
request_count INTEGER NOT NULL DEFAULT 1,
first_request_at TIMESTAMP NOT NULL,
last_request_at TIMESTAMP NOT NULL,
blocked_until TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@oNddleo
oNddleo / audit.md
Created March 3, 2025 07:13
Audit design

RPC Log Audit System Design

I'll design a log audit system for RPC services that can track login actions (requests and responses) and integrate with other services. We'll use the go-zero framework as requested.

Overall Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             β”‚         β”‚             β”‚         β”‚             β”‚
β”‚ RPC Client β”œβ”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚ RPC Service β”œβ”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚ Audit Store β”‚
@oNddleo
oNddleo / librechat.yml
Last active February 19, 2025 01:56
LibreChat Deployment
---
# ConfigMap for environment variables
apiVersion: v1
kind: ConfigMap
metadata:
name: librechat-config
data:
HOST: "0.0.0.0"
MONGO_URI: "mongodb://mongodb:27017/LibreChat"
MEILI_HOST: "http://meilisearch:7700"
@oNddleo
oNddleo / hard2softdelete.md
Created November 13, 2024 15:31
Different hard delete and soft delete

Let me break down the comparison between soft delete and hard delete in PostgreSQL, with specific contexts where each approach makes more sense.

Soft Delete vs Hard Delete in PostgreSQL - A Comprehensive Analysis

Soft Delete

@oNddleo
oNddleo / sync-account.go
Created November 13, 2024 15:12
Sync account template
package sync
import (
"context"
"database/sql"
"time"
)
// Account represents the account data structure
type Account struct {
@oNddleo
oNddleo / .wezterm.lua
Last active November 7, 2024 01:12
wezterm config
-- Pull in the wezterm API
local wezterm = require 'wezterm'
-- This table will hold the configuration.
local config = {}
-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
config = wezterm.config_builder()
end
@oNddleo
oNddleo / rebalance.go
Created October 14, 2024 07:20
rebalance
package main
import (
"fmt"
"math"
)
// TickerAllocation represents a ticker symbol and its allocation percentage.
type TickerAllocation struct {
Ticker string