Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@corporatepiyush
corporatepiyush / dial-pq-via-ssh.go
Created May 27, 2023 09:02 — forked from vinzenz/dial-pq-via-ssh.go
Use postgres via SSH in Golang
package main
import (
"database/sql"
"database/sql/driver"
"fmt"
"net"
"os"
"time"
@corporatepiyush
corporatepiyush / blockAds-linux.sh
Last active September 8, 2024 12:07
Block ads and malware for MacOS and Linux
# Protection from Malicious Domain (ads, malware, hack scripts, fakenews and gambling )
# You may not be doing it but various apps installed on your system doing it internally, so having ad blocker in Browser does not helps.
# Execute below command in your terminal once every week.
sudo chmod 774 /etc/hosts
curl https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts > hosts
sudo mv hosts /etc/hosts
@corporatepiyush
corporatepiyush / fetchSave.js
Created June 29, 2023 15:07
Taking a day wise backup of large SQL Table incrementally
const pg = require('pg-promise')();
const fs = require('fs');
const db = pg({
user: "****",
password: "*****",
host: "******",
port: 5432,
database: "*****",
ssl: {
@corporatepiyush
corporatepiyush / FileDB.dart
Last active August 15, 2023 14:15
Using File System as Key Value Database
// ignore_for_file: prefer_function_declarations_over_variables
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:basics/basics.dart';
import 'package:quiver/cache.dart';
@corporatepiyush
corporatepiyush / harden-linux.sh
Last active August 24, 2024 06:48
MacOS and Linux Optimisation and hardening
#!/bin/bash
# Array to store user choices
declare -A choices
# Log file
LOGFILE="/var/log/linux_hardening.log"
# Function to log messages
log() {
@corporatepiyush
corporatepiyush / glibc-tuning.sh
Last active August 28, 2024 08:58
Memory optimisations using jemalloc and tcmalloc on Linux
#!/bin/bash
# File: /usr/local/bin/configure_malloc.sh
set_malloc_config() {
local total_ram=$1
local arena_max mmap_threshold trim_threshold top_pad
mmap_threshold=524288 # 512 KB
trim_threshold=524288 # 512 KB
@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;
@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 / 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 / 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