Skip to content

Instantly share code, notes, and snippets.

View rgabs's full-sized avatar
❄️
¯\_(ツ)_/¯ ‏‏‎

Rahul Gaba rgabs

❄️
¯\_(ツ)_/¯ ‏‏‎
View GitHub Profile
// ==UserScript==
// @name DVSA finder - This scripts find the slots on or before the specified date/month around a postcode, every 50seconds
// @namespace Script Runner Pro
// @match https://driverpracticaltest.dvsa.gov.uk/manage*
// @grant none
// ==/UserScript==
const MAX_NO_OF_MONTH = 2; // Alert will be triggered when the available month is atleast Feb.
const MAX_DATE = 27; // Example: 27/2
const TIMEOUT = 50000; // Search will be triggered 50 seconds after the page load.
// ==UserScript==
// @name Prefill dvsa data - This prefills the form data on the login page and clicks on the login btn
// @namespace Script Runner Pro
// @match https://driverpracticaltest.dvsa.gov.uk/login
// @grant none
// ==/UserScript==
(function() {
'use strict';
const PROVISIONAL_NO = "GABAXXXXXXXXX";
@rgabs
rgabs / throttle-debounce.js
Created April 22, 2019 18:36
simple throttle and debounce
const debounce = (fn, delay) => {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
fn(...args);
}, delay);
}
};
const add = (a,b, c) => {
return a + b + c;
}
function curriedFn(fn) {
const argsToCall = []; // [1]
return function returnedFn (...args) { // 1, 2
argsToCall.push(...args);
if(argsToCall.length < fn.length) {
return returnedFn;
@rgabs
rgabs / proxifiedArray.js
Last active January 31, 2019 12:10
Implement array like data structure using objects and proxies in JavaScript.
// Implement array like data structure using objects and proxies in JavaScript.
function CustomArray(...args) {
const proxyobj = {
get length() {
const indices = Object.keys(proxyobj).map(Number).filter(n => !isNaN(n));
if(indices.length === 0) return 0;
const maxIndex = Math.max(...indices);
return maxIndex + 1;
}
@rgabs
rgabs / fibaonacci.js
Created January 29, 2019 12:14
tail recursion fibonacci series
function fibTCO(n) {
function f(n, va, a) {
if(n === 0) {
return a;
}
return f(n-1, va+a, va);
}
return f(n, 1, 0);
}
@rgabs
rgabs / promise-from-scratch.js
Created January 14, 2019 15:09
A custom implementation of Promises using callbacks.
// Callback version of the async task
const someApi = (url, onSuccess, onError) => {
setTimeout(() => {
url === "someURL" ? onSuccess("success") : onError("some error");
});
};
someApi(
"someURL",
@rgabs
rgabs / greedy.js
Last active January 7, 2019 02:16
Tiny Greedy algorithm in JS using recursion (7 lines);
const getCoinsNoV1 = (amount) => {
const coinTypes = [0.25, 0.10, 0.05, 0.01];
let coinCount = 0;
for (let i = 0; i < coinTypes.length;) {
if (coinTypes[i] <= amount) {
coinCount++;
amount = amount - coinTypes[i];
}
else {
i++;
@rgabs
rgabs / clean_remote_branches.sh
Last active January 12, 2019 13:41 — forked from skeep/clean_remote_branches.sh
Delete stale branches from both origin and local using the CLI. This script will prompt the user before deleting a branch.
# Usage:
# bash <(curl -L https://gist.githubusercontent.com/rgabs/a6461243956238d9d6255c4bb9a889f5/raw/12fcf6163538cdc35707f87b9ff7a3c2dc62ef59/clean_remote_branches.sh)
# Running the above script will ask the developer for confirmation before deleting any branch.
#!/bin/bash
set -e
GREEN='\033[0;32m';
RED='\033[0;31m';
@rgabs
rgabs / compare-pkg-version.sh
Last active December 28, 2018 10:29
A small script to compare the node package version of local project with the npm respository
# This example does the following:
# + Get the latest published version(live version) of react-native-modal-overlay.
# + If the version specified in local package.json is:
# 1. Less than the live version, it runs npm publish command to publish the newer verion.
# 2. Greater or equal than the live version, then it logs a message saying: "Not publishing since version hasn't increased"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Use-case with CI/CD: