Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@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
@corporatepiyush
corporatepiyush / linux-ipr.sh
Last active August 28, 2024 06:49
Rust based command line primitives
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
# Configuration
APT_PACKAGES="fd-find ripgrep bat exa procs zoxide git-delta hyperfine dust-zsh broot lsd bottom"
SHELL_CONFIG_FILES=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.zshrc")
# Logging functions
log_info() {
@corporatepiyush
corporatepiyush / pg-practices.md
Last active August 27, 2024 06:04
PostgreSQL Best Practices

Technical Guide: PostgreSQL and Stored Procedure Best Practices

Schema and Data Management

  1. Schema Organization: Description: Organize your database objects into logical schemas to improve manageability and security.

    CREATE SCHEMA auth;

CREATE SCHEMA billing;

@corporatepiyush
corporatepiyush / linux-aliases.sh
Last active August 27, 2024 08:59
Useful command line aliases
## Colorize the ls output ##
alias ls='ls --color=auto'
alias ll='ls -lA --color=auto'
alias la='ls -la --color=auto'
alias lt='ls -ltr --color=auto'
# update hosts file
alias update_dns_hosts='sudo chmod 774 /etc/hosts && \
curl https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts > hosts && \
sudo mv hosts /etc/hosts && \
echo 'export DEB_CFLAGS_MAINT_APPEND="-O3 -march=native -ftree-vectorize -flto -fprefetch-loop-arrays"' | sudo tee -a /etc/dpkg/buildflags.conf
echo 'export DEB_CXXFLAGS_MAINT_APPEND="-O3 -march=native -ftree-vectorize -flto -fprefetch-loop-arrays"' | sudo tee -a /etc/dpkg/buildflags.conf