Skip to content

Instantly share code, notes, and snippets.

View sagar-gavhane's full-sized avatar
🏠
Working from home

Sagar sagar-gavhane

🏠
Working from home
View GitHub Profile
@sagar-gavhane
sagar-gavhane / pokemon.js
Created October 20, 2018 13:23
pokemon app
const express = require('express')
const serverless = require('serverless-http')
const bodyParser = require('body-parser')
const pool = require('./configs/dbConfig')
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
@sagar-gavhane
sagar-gavhane / cs-module-path.js
Created October 21, 2018 08:17
This code snippet is written during publishing article on "Code Splitting in React". article link: https://dev.to/sagar/increase-user-interactions-by-implementing-code-splitting-in-react-5a1e
const modulePath = './someFile.js'; // path of module
// dynamic import() module
import(modulePath).then(module => {
return module.default; // return default function of es module
});
@sagar-gavhane
sagar-gavhane / sls-api-serverless.yml
Created October 22, 2018 06:08
This code snippets is created during writting article on "Build a RESTful API with the Serverless Framework". article link is here => https://medium.com/@sgavhane70/build-a-restful-api-with-the-serverless-framework-d8cc548f8e0f
# serverless.yml
service: pokemon-service
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
memorySize: 512
@sagar-gavhane
sagar-gavhane / sls-api-serverless.yml
Created October 22, 2018 06:14
This code snippets is created during writting article on "Build a RESTful API with the Serverless Framework". article link is here => https://medium.com/@sgavhane70/build-a-restful-api-with-the-serverless-framework-d8cc548f8e0f
# serverless.yml
service: pokemon-service
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
memorySize: 512
@sagar-gavhane
sagar-gavhane / sls-api-serverless.yaml
Created October 22, 2018 06:16
This code snippets is created during writting article on "Build a RESTful API with the Serverless Framework". article link is here => https://medium.com/@sgavhane70/build-a-restful-api-with-the-serverless-framework-d8cc548f8e0f
# serverless.yml
service: pokemon-service
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
memorySize: 512
@sagar-gavhane
sagar-gavhane / asyncComponent.jsx
Created October 22, 2018 06:19
This code snippets is created during writting article on "Code splitting in React". article link is here => https://medium.com/@sgavhane70/code-splitting-in-react-f475a0da4c3e
// filename: asyncComponent.jsx
import React, { Component } from "react";
const asyncComponent = (getComponent) => {
// return AsyncComponent class component
return class AsyncComponent extends Component {
static Component = null;
state = {
Component: AsyncComponent.Component // first time similar to static Component = null
};
@sagar-gavhane
sagar-gavhane / ContainerComponent.jsx
Last active October 28, 2018 10:46
This code snippets is created during writing article on react component patterns.
import React, { Component, Fragment } from "react"
class CommentList extends Component {
constructor() {
super()
this.state = { comments: [] }
}
componentDidMount() {
fetch("https://jsonplaceholder.typicode.com/comments")
@sagar-gavhane
sagar-gavhane / useElementResizer.jsx
Created November 7, 2018 06:00
Observe for element resize.
import React, { useState, useEffect, useRef, } from "react";
const useElementResizer = (ref) => {
const [contentRect, setContentRect] = useState(ref.current ? ref.current.getBoundingClientRect() : {});
useEffect(() => {
if (!ref.current) return;
const observer = new window.ResizeObserver(entries => setContentRect(entries[0].contentRect));
observer.observe(ref.current);
@sagar-gavhane
sagar-gavhane / PlaygroundComponent.jsx
Created November 7, 2018 07:21
React suspense demo example created by me
import React, { Suspense } from "react";
import { createCache, createResource } from "simple-cache-provider";
const cache = createCache();
const readText = createResource((text) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(text);
}, 1000);
});
@sagar-gavhane
sagar-gavhane / vscode-user-settings.json
Created November 7, 2018 07:37
vscode user settings
{
"editor.fontFamily": "'Source Code Pro', Menlo, Monaco, 'Courier New', monospace",
"terminal.integrated.fontFamily": "'Source Code Pro', 'Inconsolata for Powerline', monospace",
"editor.fontSize": 16,
"editor.fontWeight": "500",
"editor.lineHeight": 24.65,
"editor.letterSpacing": 0.5,
"files.trimTrailingWhitespace": true,
"prettier.eslintIntegration": true,
"editor.cursorStyle": "line",