Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Vaibhav Pandey vaibhavpandeyvpz

I may be slow to respond.
View GitHub Profile
vaibhavpandeyvpz / infosec-iq-qa.js
Last active Jun 15, 2022
Complete a InfoSec institute course automatically.
View infosec-iq-qa.js
function getCsrfToken() {
var parts = ('; ' + document.cookie)
.split("; csrf=");
if (parts.length === 2) {
const value = parts.pop().split(";").shift();
return decodeURIComponent(value);
function sendXhr(url, method, data = null, headers = {}) {
vaibhavpandeyvpz / e164_format.php
Last active May 26, 2022
Normalize phone number inputs from user to E.164 format.
View e164_format.php
* @param string|null $number
* @return string|null
function normalize_to_e164(?string $number): ?string
if (empty($number)) {
return null;
vaibhavpandeyvpz /
Created May 13, 2022
Run Meilisearch server on Apple (M1) silicon using Docker, for Laravel
FROM ubuntu
WORKDIR /meilisearch
RUN apt-get update && \
apt-get install -y libc6-dev wget
RUN wget -O exe && \
chmod a+x exe
vaibhavpandeyvpz / Button.jsx
Last active Feb 23, 2022
Creating themed components based on styled.div
View Button.jsx
import { darken, getLuminance } from 'polished';
import styled, { css } from 'styled-components';
const isDarkColor = color => getLuminance(color) <= .5;
const Button = styled.button`
background: white;
border: 1px solid black;
color: black;
cursor: pointer;
vaibhavpandeyvpz / HasUuidAsPrimaryKey.php
Created Feb 4, 2022
Generate and use UUIDs as primary keys in Laravel
View HasUuidAsPrimaryKey.php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
trait HasUuidAsPrimaryKey
public static function bootHasUuidAsPrimaryKey()
static::creating(function (Model $model) {
vaibhavpandeyvpz /
Last active Feb 22, 2022
Common policies for AWS/IAM

This Gist includes some of the common AWS/IAM policy examples to give granular access to users.

vaibhavpandeyvpz /
Last active Dec 2, 2021
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 /
Last active Dec 1, 2021
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 / useStatefulPromise.tsx
Created Oct 13, 2021
Load/preload component data statefully using React hooks.
View useStatefulPromise.tsx
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 / useWindowSize.js
Created Jul 25, 2021
React hook to track window resize events.
View useWindowSize.js
import { useEffect, useState } from 'react';
* @return {{width: Number, height: Number}}
function getWindowSize() {
return {
width: window.innerWidth,
height: window.innerHeight,