Skip to content

Instantly share code, notes, and snippets.

View abhagsain's full-sized avatar
💻
Building

Anurag Bhagsain abhagsain

💻
Building
View GitHub Profile
@abhagsain
abhagsain / README.md
Created June 16, 2023 14:40
Use Google OAuth to create token for fetching data from Google Sheets
  • Create a service account, I don't exactly remember but I think you'll get an email after creating a service account.
  • Add this email as an editor to your Google Sheet (Please research on this, I don't exactly remember)

Below code can be used on Edge (Cloudflare Workers)

You probably get the expiry time of the token in the token itself, you can use that to refetch new token again.

@abhagsain
abhagsain / Affiliate.js
Last active March 17, 2023 07:58
Ignore Rewardful affiliate tracking if the user came from Google Ads
// Credit @michaelkoper - https://twitter.com/michaelkoper/status/1633836513359441924
class Affiliates {
constructor() {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('via') && !urlParams.get('gclid')) {
const script = document.createElement('script')
script.src = 'https://r.wdfl.co/rw.js'
script.setAttribute('async', '')
script.setAttribute('data-rewardful', '_ADD_YOUR_AFFILIATE_ID_HERE')
document.head.appendChild(script)
@abhagsain
abhagsain / getGoogleAuthToken.js
Created January 17, 2023 13:10 — forked from markelliot/getGoogleAuthToken.js
Converts Google service user OAuth2 credentials into an access token in Cloudflare-compatible JS
/**
* Get a Google auth token given service user credentials. This function
* is a very slightly modified version of the one found at
* https://community.cloudflare.com/t/example-google-oauth-2-0-for-service-accounts-using-cf-worker/258220
*
* @param {string} user the service user identity, typically of the
* form [user]@[project].iam.gserviceaccount.com
* @param {string} key the private key corresponding to user
* @param {string} scope the scopes to request for this token, a
* listing of available scopes is provided at
@abhagsain
abhagsain / .vimrc
Last active April 21, 2024 16:19
Install OhMySh, PowerLeve10K, Autosuggestion and Syntax highlighting On Ubuntu
# set relative line number in vim
set number
set rnu
@abhagsain
abhagsain / serverless.yml
Created May 22, 2022 06:19
How to use Lambda Layer With Serverless Framework
org: abhagsain
app: abhagsain-app
service: abhagsain-app
frameworkVersion: "3"
provider:
name: aws
runtime: python3.8
httpApi:
cors: true
@abhagsain
abhagsain / install-docker.sh
Last active January 13, 2022 02:02
Install Docker On Ubuntu
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt install docker.io -y
systemctl start docker
systemctl enable docker
docker --version
@abhagsain
abhagsain / getStringDotRefFromObject.js
Created October 12, 2021 15:19
Convert Object Reference to String dot Notation JavaScript
function getStringDotRefFromObject(obj, arr = [], objPath = '') {
const isObject = typeof obj === 'object' && !Array.isArray(obj) && obj !== null;
if (!isObject) return objPath;
return Object.keys(obj).reduce((acc, curr) => {
const path = obj[curr];
return acc.concat(
// eslint-disable-next-line prefer-template
getStringDotRefFromObject(path, arr, `${objPath ? objPath + '.' : ''}${curr}`)
);
}, []);
@abhagsain
abhagsain / deleteProcessWindows.sh
Last active August 16, 2023 05:14
How to kill process on port in Windows
```
# Run this in CMD only and not in bash
netstat -ano | findstr :3001
# This will give
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING 24928 👈
TCP [::]:3001 [::]:0 LISTENING 24928
@abhagsain
abhagsain / currencies.js
Created March 23, 2021 19:51
List of World Currencies with Code, Symbol and Name
const currencies = {
ADP: {
code: 'ADP',
name: 'Andorran peseta',
currencySymbol: 'ADP',
symbol: 'ADP',
},
AED: {
code: 'AED',
name: 'UAE dirham',
@abhagsain
abhagsain / getFuzzyTime.js
Created February 20, 2021 13:15
Get fuzzy time from JS Date.
// 1hr ago, 2 days ago etc
const getFuzzyTime = (millisec) => {
let res = "";
const t_second = 1000;
const t_minute = t_second * 60;
const t_hour = t_minute * 60;
const t_day = t_hour * 24;
const t_week = t_day * 7;
const t_month = Math.floor(t_day * 30.4);