Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@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)
@corporatepiyush
corporatepiyush / maControl.sh
Created July 28, 2024 09:14
Memory allocation control for Linux OS process and managing overflow with swap files
#!/bin/bash
# Configuration
NODE_APP="your-app.js"
CGROUP_NAME="nodejs_group"
MEMORY_LIMIT="4G"
SWAP_SIZE="8G"
SWAPFILE="/swapfile"
SWAPPINESS=60
ZSWAP_ENABLED=1
@corporatepiyush
corporatepiyush / ChunkArrayDataFrame.py
Last active July 27, 2024 10:58
Disk backed in-memory chunked array DataFrame wrapper for Polars
import polars as pl
import os
import time
from threading import Thread, Event, RLock, Lock
from typing import List
import uuid
def synchronized(lock):
"""Synchronization decorator."""
@corporatepiyush
corporatepiyush / installSSL.sh
Last active June 13, 2024 12:54
SSH Key generation
#!/bin/bash
# Set variables for key files
PRIVATE_KEY_FILE="/etc/ssh/ecdh_private_key.pem"
PUBLIC_KEY_FILE="/etc/ssh/ecdh_public_key.pem"
SSH_CONFIG_FILE="/etc/ssh/sshd_config"
# Function to handle errors
handle_error() {
echo "Error: $1"