Skip to content

Instantly share code, notes, and snippets.

Nitish Phanse nitish24p

View GitHub Profile
@nitish24p
nitish24p / Javascript immutable Operations es6Array.md
Last active Oct 16, 2017
es6 Array immutable Array Actions
View Javascript immutable Operations es6Array.md

I have an array by the name students and a student object

let students = []

let student = {
  name: '',
  rollNumber: '',
  age: '',
  rank: ''
}
View initAva.js
import test from 'ava';
function sum (a, b) {
return a + b;
}
test('foo is being tested', t => {
t.pass();
})
test('bar is being tested', async t => {
const bar = Promise.resolve('bar');
@nitish24p
nitish24p / app.js
Last active Nov 20, 2017
Qucikfire node server
View app.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}))
app.get('/status', (req , res) => {
res.send({
View server.js
const app = require('./app.js');
const http = require('http')
const server = http.createServer(app);
const PORT = process.env.NODE_ENV || 5000;
server.listen(PORT, () => {
console.log(`Listening to port ${PORT}`);
})
View index.test.js
import test from 'ava';
const request = require('supertest');
const app = require('./../app.js');
test('check status', async t => {
const response = await request(app)
.get('/status');
t.is(response.status, 200);
t.deepEqual(response.body, {
@nitish24p
nitish24p / appClient.js
Last active Jan 18, 2018
Code splitting with Higher order Components
View appClient.js
import * as RoutingConstants from './constants/RoutingConstants';
import { Route, Switch } from 'react-router-dom';
import AboutUs from './pages/AboutUs';
import Products from './pages/Products';
import Homepage from './pages/Homepage';
import React, { Component } from 'react';;
class App extends Component<{}, {}> {
render() {
return (
View AsyncClientSplit.js
import * as RoutingConstants from './constants/RoutingConstants';
import { Route, Switch } from 'react-router-dom';
import LoadingComponent from './pages/LoadingComponent';
import React, { Component } from 'react';
function asyncComponent(importComponent: Function, LoadingComponent: Function) {
class AsyncComponent extends Component {
constructor(props) {
super(props);
@nitish24p
nitish24p / server.js
Created Jan 18, 2018
Code split react loadable
View server.js
/// Somewhere on your express server
import Loadable from 'react-loadable';
Loadable.preloadAll().then(() => {
server.listen(port, function () {
console.log('Express server listening on port ' + server.address().port);
});
});
@nitish24p
nitish24p / Server markup.js
Last active Apr 15, 2018
Markup for server side render
View Server markup.js
/* @flow */
import { StaticRouter } from 'react-router-dom';
import { getBundles } from 'react-loadable/webpack';
import App from './../App';
import Loadable from 'react-loadable';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import bundleStats from './../../dist/build/react-loadable.json';
@nitish24p
nitish24p / index.js
Last active Jun 26, 2018
index.js for sever
View index.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const userController = require('./userController');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/user', userController.createOrAddUser);
You can’t perform that action at this time.