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 / infosec-iq-qa.js
Last active June 15, 2022 16:08
Complete a InfoSec institute course automatically.
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
vaibhavpandeyvpz / 00-common-aws-policies.md
Last active February 22, 2022 05:01
Common policies for AWS/IAM

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

@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 / 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/'`
@mirmilad
mirmilad / debounce.kt
Last active June 21, 2023 22:46
Simple debounce extension for LiveData by using Coroutines
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
fun <T> LiveData<T>.debounce(duration: Long = 1000L, coroutineScope: CoroutineScope) = MediatorLiveData<T>().also { mld ->
val source = this
@vaibhavpandeyvpz
vaibhavpandeyvpz / center-element.js
Last active November 8, 2019 03:09
Center an element horizontally and/or vertically using JavaScript.
function resize($el) {
const data = $el.data('center');
if (data.x) {
const w_width = $(window).width();
const e_width = $el.width();
const margin = (w_width - e_width) / 2;
$el.css('left', margin)
}
if (data.y) {
const w_height = $(window).height();
@vaibhavpandeyvpz
vaibhavpandeyvpz / Example.js
Last active January 7, 2022 23:45
Laravel, Axios & Logout Over AJAX
import React from 'react';
import ReactDOM from 'react-dom';
const handleLogout = () => {
axios.post('/logout')
.then(() => location.href = '/home')
};
function Example() {
return (
@vaibhavpandeyvpz
vaibhavpandeyvpz / escape.js
Created May 15, 2019 03:53
Escape HTML tags in JS before rendering to DOM.
const e = str => {
const replacements = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#039;',
'"': '&quot;',
};
return str.replace(/[&<>"']/g, match => replacements[match])
};
@vaibhavpandeyvpz
vaibhavpandeyvpz / ActiveExtension.php
Created May 15, 2019 03:48
Twig extension for rendering 'active' class depending on path or route.
<?php
namespace App\Twig;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class ActiveExtension extends AbstractExtension
{
@vaibhavpandeyvpz
vaibhavpandeyvpz / bootstrap_4_horizontal_layout_fix.html.twig
Last active July 29, 2021 06:11
Moving form errors in Symfony 4 form label to below input.
{% extends 'bootstrap_4_horizontal_layout.html.twig' %}
{% block form_label_errors %}{% endblock %}
{% block form_row -%}
{%- if expanded is defined and expanded -%}
{{ block('fieldset_form_row') }}
{%- else -%}
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
{{- form_label(form) -}}