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 / reactLogger2.jsx
Created September 19, 2018 13:12
reactLogger2
export default (
label,
componentName,
prevProps,
nextProps,
prevState,
nextState
) => {
const groupLabel =
(componentName && `[${label || "react-logger"} - <${componentName} />]`) ||
@sagar-gavhane
sagar-gavhane / Car.jsx
Created September 19, 2018 13:12
Car component
import React, { Component } from 'react';
import reactLogger from './reactLogger';
const cars = [
{ id: 1, brand: 'Maruti Suzuki', model: 'Alto', year: '2017' },
{ id: 2, brand: 'Honda', model: 'City', year: '2018' },
{ id: 3, brand: 'Tata', model: 'Bolt', year: '2015' },
{ id: 4, brand: 'Ford', model: 'Classic', year: '2013' },
{ id: 5, brand: 'BMW', model: '5 Series', year: '2018' },
];
@sagar-gavhane
sagar-gavhane / authorize.js
Created September 2, 2018 10:05 — forked from kndt84/authorize.js
Sample code: how to refresh session of Cognito User Pools with Node.js and Express
const AWS = require('aws-sdk');
const CognitoUserPool = require('amazon-cognito-identity-js-node').CognitoUserPool;
const CognitoUserSession = require('amazon-cognito-identity-js-node').CognitoUserSession;
const CognitoUser = require('amazon-cognito-identity-js-node').CognitoUser;
const CognitoIdToken = require('amazon-cognito-identity-js-node').CognitoIdToken;
const CognitoAccessToken = require('amazon-cognito-identity-js-node').CognitoAccessToken;
const CognitoRefreshToken = require('amazon-cognito-identity-js-node').CognitoRefreshToken;
const cfg = require('config').config;
const COGNITO_IDENTITY_POOL_ID = cfg.COGNITO_IDENTITY_POOL_ID;
@sagar-gavhane
sagar-gavhane / InfiniteScrollbar.js
Last active August 8, 2018 14:06
Simple infinite scrollbar with react
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
posts: [],
isLoading: false,
offset: 0,
@sagar-gavhane
sagar-gavhane / difference.js
Created July 27, 2018 09:15 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@sagar-gavhane
sagar-gavhane / preventDuplicateToast.js
Created July 27, 2018 05:49
Prevent duplicate toast notification
if (!toast.isActive(this.toastId)) {
const { message } = response.data;
this.toastId = toast.success(message);
}
@sagar-gavhane
sagar-gavhane / API.md
Created July 26, 2018 09:27 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@sagar-gavhane
sagar-gavhane / package.json
Created July 23, 2018 13:07 — forked from adamreisnz/package.json
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Buczynski",
"url": "http://adambuczynski.com"
},
"license": "UNLICENSED",
@sagar-gavhane
sagar-gavhane / config.js
Created July 22, 2018 15:06
environment-dependent-node-js-configuration
// var config = require('./config.js').get(process.env.NODE_ENV);
var config = {
production: {
session: {
key: 'the.express.session.id',
secret: 'something.super.secret'
},
database: 'mongodb://<user>:<pwd>@apollo.modulusmongo.net:27017/db',
twitter: {
@sagar-gavhane
sagar-gavhane / reactLogger.jsx
Last active July 27, 2018 09:21
React logger
// component
shouldComponentUpdate(nextProps, nextState) {
console.group('react-logger');
console.log('[prevProps]', this.props);
console.log('[nextProps]', nextProps);
console.log('[prevState]', this.state);
console.log('[nextState]', nextState);
console.log('[propsChange]', difference(this.props, nextProps));
console.log('[stateChange]', difference(this.state, nextState));
console.groupEnd('react-logger');