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 / exception.filter.ts
Created September 11, 2026 05:56
rfc 9457 in nestjs
import {
ArgumentsHost,
Catch,
ExceptionFilter,
HttpException,
HttpStatus,
} from '@nestjs/common';
import type { Request, Response } from 'express';
interface ProblemDetails {
@Silent-Watcher
Silent-Watcher / nestjs.Dockerfile
Created July 3, 2026 10:51 — forked from patharanordev/nestjs.Dockerfile
Reduce size of Dockerized NestJS from 7XXMB to 185MB
# -------------------------------------------
# Prepare runner
FROM node:18-alpine AS runner
RUN apk update && \
apk add curl bash g++ make && \
rm -rf /var/cache/apk/*
# Install node-prune (https://github.com/tj/node-prune)
@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 / retry.ts
Created December 17, 2025 16:32
retry logic helper in node.js
async function withRetry<T>(operation: () => Promise<T>, opts: {
maxRetries: number;
baseDelayMs: number;
capDelayMs: number;
}) {
const { baseDelayMs, capDelayMs, maxRetries } = opts
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
@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 / index.ts
Created December 6, 2025 08:33
True Immutability in TypeScript
export type DeepReadonly<T> = {
readonly [K in keyof T]: T[K] extends object
? DeepReadonly<T[K]>
: T[K];
};
// DeepReadonly<IConfig>
@Silent-Watcher
Silent-Watcher / req.socket.md
Created November 9, 2025 16:30
req.socket properties
Property Type Description
remoteAddress string IP address of the client.
remotePort number Client port.
localAddress string Server’s IP address used for this connection.
localPort number Server’s listening port.
destroyed boolean Indicates whether the socket is closed.
readyState string TCP connection state: open, readOnly, writeOnly, closed.
@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();