Skip to content

Instantly share code, notes, and snippets.

View corporatepiyush's full-sized avatar

Piyush Katariya corporatepiyush

View GitHub Profile
@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;
@corporatepiyush
corporatepiyush / glibc-tuning.sh
Last active May 29, 2024 12:49
Memory optimisations using jemalloc and tcmalloc on Linux
#!/bin/sh
# touch /etc/profile.d/malloc_config.sh
# Get total RAM size in MB
total_ram=$(free -m | awk '/^Mem:/{print $2}')
if [ "$total_ram" -lt 8192 ]; then
# Low RAM settings
export MALLOC_ARENA_MAX=2
@corporatepiyush
corporatepiyush / harden-linux.sh
Last active July 1, 2024 10:37
MacOS and Linux Optimisation
#!/bin/bash
# Function to set sysctl values with error handling
set_sysctl() {
sysctl -w $1=$2
if [ $? -ne 0 ]; then
echo "Failed to set $1 to $2"
else
echo "$1 set to $2"
echo "$1=$2" | sudo tee -a /etc/sysctl.conf
@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 / 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 / blockAds-linux.sh
Last active June 13, 2024 10:57
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 / 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 / rollups.sql
Created November 14, 2019 18:27 — forked from marcocitus/rollups.sql
Efficient real-time rollups with backfilling in Citus
CREATE TABLE rollups (
name text,
rolled_up_generation bigint default -1
);
-- Create a stub on workers to allow usage as a default in distributed tables
SELECT run_command_on_workers($$
CREATE OR REPLACE FUNCTION current_rollup_generation(rollup_name text)
RETURNS bigint LANGUAGE sql
AS $function$
@corporatepiyush
corporatepiyush / example.sql
Created November 7, 2019 13:19 — forked from marcocitus/example.sql
Safe incremental rollups on Postgres and Citus
-- Create the raw events table
CREATE TABLE page_views (
site_id int,
path text,
client_ip inet,
view_time timestamptz default now(),
view_id bigserial
);
-- Allow fast lookups of ranges of sequence IDs