Skip to content

Instantly share code, notes, and snippets.

View dpacmittal's full-sized avatar
🏠
Working from home

Deepak Mittal dpacmittal

🏠
Working from home
View GitHub Profile
@dpacmittal
dpacmittal / vaccine.js
Last active June 10, 2021 16:16
Ping co-win vaccine api to check for availability and show notification using zenity
const fetch = require('node-fetch');
const { exec } = require("child_process");
async function main(){
const districts = [
{ district_id: 294, district_name: 'BBMP' },
{ district_id: 265, district_name: 'Bangalore Urban' },
{ district_id: 276, district_name: 'Bangalore Rural' },
// { district_id: 363, district_name: "Pune" },
// { district_id: 270, district_name: 'Bagalkot' },
// { district_id: 264, district_name: 'Belgaum' },
@dpacmittal
dpacmittal / useLazySWR.ts
Last active February 25, 2021 12:38
React hook to send requests lazily with SWR
import { useState } from "react";
import useSWR, { ConfigInterface, keyInterface } from "swr";
import { fetcherFn } from "swr/dist/types";
export const useLazySWR = <T, U>(
key: keyInterface,
fn?: fetcherFn<T>,
config?: ConfigInterface<T, U>
) => {
const [shouldFetch, setShouldFetch] = useState(false);
@dpacmittal
dpacmittal / wp-graphql-swr-cache.php
Last active December 5, 2020 05:36
WP Graphql Stale-While-Revalidate Caching With Redis Object Cache
<?php
function get_request_hash($query, $vars)
{
return md5($query . json_encode($vars));
}
function should_cache($query, $op, $vars)
{
global $wp_object_cache;
@dpacmittal
dpacmittal / bootstrap-docker.sh
Created October 19, 2019 17:47
Bash script to install docker on debian based distros
#!/bin/bash
GREEN='\033[0;32m'
NC='\033[0m' # No Color
if [[ $# -ne 1 ]]; then
echo "Usage: bootstrap.sh <username>"
exit
fi
@dpacmittal
dpacmittal / fix-web-permissions.sh
Last active October 25, 2017 08:19
Fix web root dir permissions
#!/bin/bash
#Print before executing (so we can know which commands take how long)
set -x
if [ $# -ne 3 ]; then
echo Usage: fix-web-permissions.sh webserver-group username /root/web/dir
echo Eg: fix-web-permissions.sh www-data deepak /var/www
exit 1
fi
WEBSERVER=$1
@dpacmittal
dpacmittal / screencast-audio-webcam.sh
Created December 6, 2016 15:13
Create a screencast using ffmpeg with audio recording and webcam capture on bottom right
#!/bin/bash
T="$(date +%d-%m-%Y-%H-%M-%S)".mkv
if [ $# -gt 0 ]; then
if echo $1 | grep '\....$' > /dev/null; then
T=$1
else
T=$1.mkv
fi
fi
# echo $T
@dpacmittal
dpacmittal / custom-variations-select.css
Created April 6, 2016 08:31 — forked from codescribblr/custom-variations-select.css
Custom Select Box Replacements for Woocommerce Variations
.woocommerce.single-product .product .summary .variations {
width: 100%;
}
.woocommerce.single-product .product .summary .variations td {
display: block;
width: 100%;
}
.woocommerce.single-product .product .summary .variations td label {
font-family: 'Nunito', Helvetica, Arial, sans-serif;
letter-spacing: 0px;
@dpacmittal
dpacmittal / gist:2318637
Created April 6, 2012 10:12
Dynamic state dropdown on selecting country as USA
<?php
function get_countries(){
return array("AF" => "Afghanistan", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", "AO" => "Angola", "AI" => "Anguilla", "AQ" => "Antarctica", "AG" => "Antigua and Barbuda", "AR" => "Argentina", "AM" => "Armenia", "AW" => "Aruba", "AU" => "Australia", "AT" => "Austria", "AZ" => "Azerbaijan", "BS" => "Bahamas", "BH" => "Bahrain", "BD" => "Bangladesh", "BB" => "Barbados", "BY" => "Belarus", "BE" => "Belgium", "BZ" => "Belize", "BJ" => "Benin", "BM" => "Bermuda", "BT" => "Bhutan", "BO" => "Bolivia", "BA" => "Bosnia and Herzegovina", "BW" => "Botswana", "BV" => "Bouvet Island", "BR" => "Brazil", "IO" => "British Indian Ocean Territory", "BN" => "Brunei Darussalam", "BG" => "Bulgaria", "BF" => "Burkina Faso", "BI" => "Burundi", "KH" => "Cambodia", "CM" => "Cameroon", "CA" => "Canada", "CV" => "Cape Verde", "KY" => "Cayman Islands", "CF" => "Central African Republic", "TD" => "Chad", "CL" => "Chile", "CN" => "China", "CX" => "Christmas Island", "C