Skip to content

Instantly share code, notes, and snippets.

View gaurangrshah's full-sized avatar
💭
🚀

gshah2020 gaurangrshah

💭
🚀
View GitHub Profile
@gaurangrshah
gaurangrshah / shadesofpurple_custom.json
Created March 28, 2021 00:25
vscode #shadesofpurple theme customizations
"editor.tokenColorCustomizations": {
"[Shades of Purple]": {
"comments": "#675a72",
"functions": "#ffa996",
"keywords": "#bdafb9"
},
"textMateRules": [
{
/* handles jsx props & module names */
"name": "[Entity] — The main Entity color",
export function handlePromises(promises = []) {
return Promise.all(promises)
.then((responses) => {
console.log('handlePromises Success', responses);
return responses;
})
.catch((error) =>
console.log(
`handlePromises Error ${JSON.stringify(error, null, 2)}`
)
function injectField (obj, { name, value }) {
return {...obj, [name]: value}
}
@gaurangrshah
gaurangrshah / isEmpty.js
Last active March 18, 2021 16:05
Random helpers
function isEmpty(value){
return value === undefined ||
value === null ||
(typeof value === "object" && Object.keys(value).length === 0) ||
(typeof value === "string" && value.trim().length === 0)
}
@gaurangrshah
gaurangrshah / downlaodAsJson.js
Created March 14, 2021 18:19
Download javascript Object as JSON
function downloadAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
@gaurangrshah
gaurangrshah / use-states.js
Last active March 4, 2021 04:31
@react #useStates #simple-state-machine
import { useEffect, useState } from "react";
export function useStates(defaultState) {
const [states, setStates] = useState({});
//SCOPE: used as a make-shift logger, triggers on each state change
useEffect(() => console.log("states monitor", states), [states]);
useEffect(() => {
// SCOPE: set initial state - or - throw if no defaultState
@gaurangrshah
gaurangrshah / jslike.code-snippets
Created March 4, 2021 00:49 — forked from kourge/jslike.code-snippets
a VS Code snippet for typing in JS imports module-first, like the order in Python
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
"Named import": {
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"prefix": "from",
@gaurangrshah
gaurangrshah / .gitignore
Created January 14, 2021 04:53
#node #minimal #2021
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules/
/.pnp
.pnp.js
# testing
/coverage
@gaurangrshah
gaurangrshah / xgit-cms.js
Created December 15, 2020 17:35
github based database/cms
import { Octokit } from '@octokit/rest';
import { nanoid } from 'nanoid';
export class GitCMS {
constructor(o) {
this.rootOptions = o;
this.octokit = new Octokit({
auth: this.rootOptions.token
});
}
@gaurangrshah
gaurangrshah / fs-cms.js
Created December 15, 2020 17:35
local-markdown-cms
import { promises as fsPromises } from 'fs';
import os from 'os';
import path from 'path';
// used to render and work with local markdown files
export async function pathExists(filePath) {
try {
const stat = await fsPromises.stat(filePath);
return stat.isFile();