Skip to content

Instantly share code, notes, and snippets.

View Silent-Watcher's full-sized avatar
⚒️

Ali nazari Silent-Watcher

⚒️
View GitHub Profile
@Silent-Watcher
Silent-Watcher / AGENT.md
Last active October 19, 2026 23:53
Dependency Evaluation

Dependency and Utility Evaluation

Before introducing any new dependency, package, helper, utility, or external tool, you MUST follow the Dependency Evaluation Skill.

  • Evaluate whether the requirement can be implemented reliably with no more than 200 lines of production code, excluding tests.
  • Identify relevant edge cases and write tests before integrating a new internal implementation.
  • Prefer existing project capabilities or a small internal implementation over unnecessary dependencies.
  • Evaluate security, maintenance status, compatibility, licensing, and supply-chain risks before installing any external package.
  • Verify and select the latest stable release compatible with the project.
  • Document every newly introduced external dependency or tool in DECISIONS.md using the established Architecture Decision Record (ADR) format.
@Silent-Watcher
Silent-Watcher / Mutex.ts
Created December 28, 2025 05:26
implementing Mutex pattern in node.js
class Mutex {
constructor(private locked: boolean = false, private queue: any[] = []) { }
public async runExclusive(task: () => Promise<any>) {
try {
await this.lock()
return await task()
} finally {
this.unlock()
@Silent-Watcher
Silent-Watcher / CircuitBreaker.ts
Created December 23, 2025 10:25
implementing circuit breaker pattern in node.js
import EventEmitter from "node:events";
enum CircuitState {
Open,
Closed,
HalfOpen
}
interface HealthBucket {
successes: number;
@Silent-Watcher
Silent-Watcher / BulkHead.ts
Last active December 18, 2025 14:00
BulkHead class implementation
import EventEmitter from "node:events";
export class BulkHead extends EventEmitter {
private queue: Array<() => void> = [];
private concurrencyLimit: number;
private activeCount: number = 0;
private queueLimit: number;
private totalAccepted = 0;
@Silent-Watcher
Silent-Watcher / fetchWithTimeout.ts
Created November 3, 2025 17:20
fetch with timeout
async function fetchWithTimeout(url: string, timeout: number) {
const controller = new AbortController();
const signal = controller.signal;
const requestPromise = fetch(url, { signal });
const timeoutPromise = new Promise((_, rej) => {
const timer = setTimeout(() => {
rej(new Error(`Timeout: Request took longer than ${timeout}ms`));
controller.abort();
@Silent-Watcher
Silent-Watcher / docker-compose.dev.yml
Created October 7, 2025 18:52
Kafka docker local service
version: "3.8"
services:
kafka:
image: apache/kafka:4.0.1-rc2
container_name: kafka
ports:
- "9092:9092"
environment:
CLUSTER_ID: mkqv8X5vRla7PzR8bKqfHk
@Silent-Watcher
Silent-Watcher / docker-compose.dev.yml
Created October 7, 2025 16:45
local ElasticSearch and Kibana setup with docker compose
version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:9.0.3
container_name: elasticsearch
environment:
- node.name=es-node
- discovery.type=single-node
- cluster.name=es-cluster
@Silent-Watcher
Silent-Watcher / process.ts
Created June 30, 2025 20:13
process handler in node.js
export function setupProcessHandlers(options?: {
exitOnError?: boolean;
onError?: (type: 'uncaughtException' | 'unhandledRejection', error: any) => void;
}) {
const exit = options?.exitOnError ?? true;
const onError = options?.onError;
process.on('uncaughtException', (err) => {
console.error('[🔥 Uncaught Exception]:', err);
onError?.('uncaughtException', err);
@Silent-Watcher
Silent-Watcher / jose.md
Created May 30, 2025 10:04
jose vs jsonwebtoken
Feature jose jsonwebtoken
TypeScript Support ✅ Native ☑️ Partial
ESM Support ✅ Yes ❌ No
Browser Compatibility ✅ Yes ❌ No
Algorithm Support ✅ Broad (EdDSA, ES, PS, etc.) ⚠️ Limited
Maintenance ✅ Active (Panva) 💤 Slow
Crypto Security ✅ Uses native Web Crypto API ⚠️ Custom crypto
API Style ✅ Promise-based, functional ❌ Callback/Sync
@Silent-Watcher
Silent-Watcher / recaptchaFraud.ts
Created May 18, 2025 09:15
reCaptcha fraud detector
import { safeIncrWithTTL } from "#app/common/helpers/redis";
import { unwrap } from "#app/config/db/global";
import type { MultiExecResult } from "#app/config/db/redis.config";
import { redis } from "#app/config/db/redis.config";
import { logger } from "../logger.util";
const FAILURE_PREFIX = "recaptcha:fail:ip-";
const THRESHOLD = 5; // max allowed failures
const WINDOW_SEC = 60 * 60; // rolling window for failures (1h)
const BLOCK_PREFIX = "recaptcha:block:ip-";