Skip to content

Instantly share code, notes, and snippets.

View vaibhavpandeyvpz's full-sized avatar
🐢
I may be slow to respond.

Vaibhav Pandey vaibhavpandeyvpz

🐢
I may be slow to respond.
View GitHub Profile
@vaibhavpandeyvpz
vaibhavpandeyvpz / guide.md
Last active December 2, 2021 08:17
Send SSH login notifications to Slack

Setting up notifications for successful SSH logins to Slack on a Linux server is pretty easy. Before everything, please make sure to create a Slack app (if not already), add a Webhook and keep its URL handy.

To get started, login to your instance as root (or as a sudoer user) and run below commands:

# create a directory in /opt
sudo mkdir -p /opt/ssh2slack

# paste the contents from file included and save it with Ctrl+O and Ctrl+X
sudo nano /opt/ssh2slack/slack_message.json
@vaibhavpandeyvpz
vaibhavpandeyvpz / metabase.md
Last active December 1, 2021 20:05
Running Metabase + Nginx + SSL on Ubuntu

First get Docker installed and setup on machine. Once installed, create a new user e.g., metabase for your installation using following command:

sudo adduser metabase

Now add the newly created user to docker group, you won't need sudo for docker ... commands:

sudo usermod -aG docker metabase
@vaibhavpandeyvpz
vaibhavpandeyvpz / useStatefulPromise.tsx
Created October 13, 2021 19:15
Load/preload component data statefully using React hooks.
import { useEffect, useState } from "react";
export default function useStatefulPromise(
callback: () => Promise<any>,
autoload = true
) {
const [error, setError] = useState<any>();
const [pending, setPending] = useState(true);
const [preload] = useState<boolean>(autoload);
const [result, setResult] = useState<any>();
@vaibhavpandeyvpz
vaibhavpandeyvpz / useWindowSize.js
Created July 25, 2021 11:36
React hook to track window resize events.
import { useEffect, useState } from 'react';
/**
* @return {{width: Number, height: Number}}
*/
function getWindowSize() {
return {
width: window.innerWidth,
height: window.innerHeight,
};
@vaibhavpandeyvpz
vaibhavpandeyvpz / jira-tasks-auto-update.gs
Last active July 23, 2021 14:03
Enumerates all rows, find current status of Jira task ID and updates it into adjacent cell. - For Google Docs Spreadsheets & App Scripts
// Base64 encoded username:password/pat
const credentials = "dmFpYmhhdnBhbmRleXZwejpjbGVhcmx5X25vdF9zZWNyZXQ=";
const defaults = {
contentType: "application/json",
headers: {"Authorization": "Basic " + credentials},
muteHttpExceptions: true
};
const server = "example.atlassian.net";
@vaibhavpandeyvpz
vaibhavpandeyvpz / lumen-storage-link.bat
Created July 15, 2021 18:15
Create symlink to "public" storage folder manually.
@vaibhavpandeyvpz
vaibhavpandeyvpz / useDataLoader.js
Last active January 13, 2022 10:23
Reusable hook to load asynchronous data in React.
import { useEffect, useState } from 'react';
function useDataLoader(promise, options) {
const { autoload } = { autoload: true, ...options };
const [error, setError] = useState(null);
const [loading, setLoading] = useState(!!autoload);
const [result, setResult] = useState(null);
function action() {
setLoading(true);
setError(null);
@vaibhavpandeyvpz
vaibhavpandeyvpz / mybak.sh
Last active June 18, 2023 17:17
Shell script to backup MySQL/MariaDB database to Dropbox.
#!/bin/bash
localBackupDir=${LOCAL_BACKUP_DIR:-$HOME/backup}
remoteBackupDir=${REMOTE_BACKUP_DIR:-backups}
dbHost=${DB_HOST:-localhost}
dbPort=${DB_PORT:-3306}
echo "Changing to '$localBackupDir'..."
cd "$localBackupDir"
@vaibhavpandeyvpz
vaibhavpandeyvpz / array_diff.js
Last active May 29, 2021 13:17
Find the difference in two array.
var array1 = [1, 3, 4];
var array2 = [5, 4, 2];
var existing = [];
for (var i = 0; i < array1.length; i++) {
var key = array1[i];
existing[key] = true;
}
@vaibhavpandeyvpz
vaibhavpandeyvpz / certificates.sh
Last active October 6, 2021 06:34
Generate SHA-256 hashes from SSL's chain of trust for a domain.
#!/bin/bash
CERTIFICATES=`openssl s_client -servername $1 -host $1 -port 443 -showcerts </dev/null 2>/dev/null | sed -n '/Certificate chain/,/Server certificate/p'`
CURSOR=$CERTIFICATES
while [[ "$CURSOR" =~ '-----BEGIN CERTIFICATE-----' ]]
do
CERTIFICATE="${CURSOR%%-----END CERTIFICATE-----*}-----END CERTIFICATE-----"
CURSOR=${CURSOR#*-----END CERTIFICATE-----}
echo `echo "$CERTIFICATE" | grep 's:' | sed 's/.*s:\(.*\)/\1/'`