Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Ritwick Dey ritwickdey

💭
I may be slow to respond.
View GitHub Profile
View lodash-import-modified.js
//https://astexplorer.net/#/gist/6fa8fbfbc299ba7dcf27a83d50d89c26/3af7743eac480fd64e4b9013c9e0969097470959
export default function (babel) {
const { types: t } = babel;
return {
name: "ast-transform", // not required
visitor: {
ImportDeclaration(importPath) {
if (importPath.node.source.value !== "lodash") return;
View .vscode.json
{
"eslint.autoFixOnSave": true,
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "One Dark Pro",
"editor.fontSize": 14,
"window.zoomLevel": 0,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
View facebook_auto_comment.js
/***
*
* @author Ritwick Dey (https://github.com/ritwickdey)
* @license MIT
*
* What is the hell?
* - This is a automated script to do n numbers of facebook comments.
*
* Perpose of the hell?
* You may seen such kind of post
@ritwickdey
ritwickdey / face-detection-chrome-api.js
Last active Oct 18, 2019
Face Detection using Google Chrome API (Experimental)
View face-detection-chrome-api.js
const detectFace = () => {
if(!window.FaceDetector) return console.log('Unsupported Version or Feature is not enabled')
const img = document.querySelector('#targetImg');
const faceDetector = new FaceDetector();
const scale = img.width / img.naturalWidth;
faceDetector
.detect(img)
.then(faces =>
faces.map(face => face.boundingBox)
)
@ritwickdey
ritwickdey / useLocalStorage.js
Created Jun 27, 2019
useLocalStorage React Hook
View useLocalStorage.js
import { useState, useEffect } from 'react';
export const useLocalStorage = (storageKey, initialValue) => {
const [storageVal, setStorageVal] = useState(getFromLocalStorage(storageKey));
useEffect(() => {
setToLocalStorage(storageKey, storageVal);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [storageVal]);
@ritwickdey
ritwickdey / github-auto-close.js
Last active Apr 12, 2019
Auto Close Github issue by issue name (e.g. "Extension causes high cpu load" )
View github-auto-close.js
const comment = `Hello. few questions!!,
When you're getting this issue? after load of vscode or after clicking to Go Live ?
Is this happen every-time ? or random ?
Please reply here https://github.com/ritwickdey/vscode-live-server/issues/278
Duplicate of https://github.com/ritwickdey/vscode-live-server/issues/278
View MakeUnique.ts
function makeUnique<T>(arr: T[], idSelector: (e: T) => string | number) {
const obj = {};
arr.forEach(e => {
obj[idSelector(e)] = e;
});
return Object.keys(obj).map(key => obj[key]) as T[];
}
@ritwickdey
ritwickdey / withCORS.js
Last active Dec 27, 2018
CORS Middleware (Higher Order Function) for firebase function // Just Nice Syntax
View withCORS.js
//For firebase funtion.
/*
Usage:
exports.foo = functions.https.onRequest(withCORS((req, res) => {
res.send("Hello World");
});
*/
@ritwickdey
ritwickdey / cors.js
Last active Nov 21, 2018
CORS Setup for Node.js
View cors.js
const express = require('express');
const app = express();
//CORS Setup
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*'); // Allowed Origins.
res.header('Access-Control-Allow-Headers', '*'); // Allowed Headers.
res.header('Access-Control-Expose-Headers', 'token'); // Exposed Headers - means client only can access those headers.
if (req.method === 'OPTIONS') {
@ritwickdey
ritwickdey / GetRandomColorWithRandomOpacity.js
Last active Aug 6, 2018
Get Random Color with Random Opacity (Useful for Charts)
View GetRandomColorWithRandomOpacity.js
const hexColors = [
'#3366CC',
'#DC3912',
'#FF9900',
'#109618',
'#990099',
'#3B3EAC',
'#0099C6',
'#DD4477',
'#66AA00',