Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@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"
@corporatepiyush
corporatepiyush / GenericPivot.sql
Created June 13, 2024 04:19
Dynamic Pivot for SQL result sets
CREATE PROCEDURE GenericPivot(
IN tableName VARCHAR(255),
IN pivotColumn VARCHAR(255),
IN pivotValues VARCHAR(255),
IN aggregateColumn VARCHAR(255),
IN groupByColumn VARCHAR(255)
)
BEGIN
DECLARE columnsList TEXT;
DECLARE sql_query TEXT;