Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@corporatepiyush
corporatepiyush / http2.js
Last active September 15, 2025 08:09
HTTP 2 implementation
'use strict';
process.title = 'http2server';
console.error('SERVER PID', process.pid);
/* ---------- Linux early tuning ------------------------------ */
if (process.platform === 'linux') {
try {
require('fs').writeFileSync('/proc/sys/net/core/somaxconn', '65535');
@corporatepiyush
corporatepiyush / rsa.dart
Created September 11, 2025 10:29
RSA 2048 Key Algo
import 'dart:typed_data';
import 'dart:math';
// SIMD-optimized big integer operations using Float32x4 and Int32x4
class SIMDBigInt {
static final _rng = Random.secure();
// Convert regular int to SIMD-friendly chunks
static Float32x4List toFloat32x4List(List<int> values) {
final padded = List<int>.from(values);
@corporatepiyush
corporatepiyush / ecs.go
Last active September 10, 2025 15:51
Entity Component System
package main
import "fmt"
// --- CORE TYPES ---
// Entity is a unique identifier.
type Entity uint32
// ComponentType is the identifier for a component type, used for bitmasking.
@corporatepiyush
corporatepiyush / lruCache.js
Created September 6, 2025 07:03
Highly Optimized in memory Cache with Data-Oriented Design
export class LRUCache<K, V> {
private readonly keys: K[];
private readonly values: V[];
private readonly accessOrder: number[]; // Index-based linked list
private readonly keyToIndex = new Map<K, number>();
private readonly maxSize: number;
private head = 0;
private tail = 0;
private size = 0;
@corporatepiyush
corporatepiyush / RLE.js
Created September 6, 2025 07:01
Fast Compression / Decompression Algorithms
const { Buffer } = require("buffer");
// Run length encoding
// O(n) for both compression and decompression, O(1) additional space during processing
// A,A,A,A,B,B,C,C,C,C,C => (A,4),(B,2),(C,5)
export function compressRLE(buffer: Buffer) {
if (!buffer.length) return Buffer.alloc(0);
const out = [];
let val = buffer[0],
@corporatepiyush
corporatepiyush / PerfGuide.md
Last active September 15, 2025 09:59
General guide to tune CPU, Memory and IO

A Language-Agnostic Guide to High-Performance Software Refactoring

1. CPU Optimization: From Microarchitecture to Application Logic

1.1. Low-Level CPU and Cache Optimization

1.1.1. Understanding CPU-Bound vs. I/O-Bound Workloads

@corporatepiyush
corporatepiyush / MemoryOptimizedWebSocketServer.dart
Last active August 29, 2025 06:59
Optimized Web Socket Server for Millions of connections with miminum memory allocation
import 'dart:convert';
import 'dart:typed_data';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_web_socket/shelf_web_socket.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
// Message types, same as in the JS version.
enum MessageType {
statusUpdate(0x01),
@corporatepiyush
corporatepiyush / rforest.clj
Last active July 14, 2025 09:41
Random forest with decision Tree (Generated by kimi.ai)
(ns random-forest
(:require [clojure.java.io :as io]
[clojure.string :as str])
(:import [java.util Arrays Random]
[jdk.incubator.vector FloatVector VectorSpecies VectorOperators]))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@corporatepiyush
corporatepiyush / SandboxProxyGeneratorForNsjail.sh
Created May 11, 2025 18:07
This script creates a true binary-compatible proxy that preserves all the binary interfaces of the original executable while adding nsjail sandboxing. This approach is more sophisticated than a simple wrapper, as it maintains full binary compatibility.
#!/bin/bash
# binary-compatible-proxy-generator.sh
# Creates a binary-compatible sandboxed proxy for ELF executables using nsjail
set -e
if [ $# -lt 1 ]; then
echo "Usage: $0 <original-binary> [nsjail-options]"
@corporatepiyush
corporatepiyush / setup_iptables_from_ufw.sh
Created September 23, 2024 12:07
Convert all UFW to iptables rules for faster perf
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Function to check if the script is run as root
check_root() {
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1