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 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 |
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]); |
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[]; | |
} |
View withCORS.js
//For firebase funtion. | |
/* | |
Usage: | |
exports.foo = functions.https.onRequest(withCORS((req, res) => { | |
res.send("Hello World"); | |
}); | |
*/ |
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') { |
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 GetRandomColorWithRandomOpacity.js
const hexColors = [ | |
'#3366CC', | |
'#DC3912', | |
'#FF9900', | |
'#109618', | |
'#990099', | |
'#3B3EAC', | |
'#0099C6', | |
'#DD4477', | |
'#66AA00', |
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) | |
) |
NewerOlder