Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@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
@corporatepiyush
corporatepiyush / mySqlMigrate.py
Last active August 8, 2024 09:12
Migrate schema and data from mysql/mariadb to other mysql/mariadb server
import pymysql
import traceback
import logging
from concurrent.futures import ThreadPoolExecutor, as_completed
from contextlib import contextmanager
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
@corporatepiyush
corporatepiyush / pg-install-linux.sh
Last active August 16, 2024 05:23
PostgreSQL Custom build
#!/bin/bash
# Configuration variables
POSTGRES_VERSION="16.3"
POSTGRES_PREFIX="$HOME/pgsql"
DATA_DIR="$POSTGRES_PREFIX/data"
LOGFILE="$POSTGRES_PREFIX/logfile"
BUILD_DIR="$HOME/postgresql-build"
PYTHON3_PATH=$(which python3)