Skip to content

Instantly share code, notes, and snippets.

View nitish24p's full-sized avatar

Nitish Phanse nitish24p

View GitHub Profile

Kubernetes Commands and Resources

Components

Any kubernetes cluster has 3 main components

  1. Control Plane
  2. Proxy network
@nitish24p
nitish24p / WithoutClick.js
Created May 10, 2020 19:52
TwoWayBinding.js
const Binding = (function () {
function initialise(appNode, callback) {
const model = {};
const nodes = appNode.querySelectorAll('[data-bind]');
/** ============== Two way bind =============== */
nodes.forEach(function (element) {
const key = element.getAttribute('data-bind');
hookElementToModel(key);
if (element.type === 'text' || element.type === 'textarea') {
/*
* Copyright (c) 2011-2015 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
@nitish24p
nitish24p / AsyncUser.js
Created June 26, 2018 17:42
Async await
exports.createOrAddUserAsync = async (req, res, next) => {
try {
const user = await User.findUserPromise(req.body);
if (user) {
const existingUser = new User(user);
const data = await existingUser.updatePromise(req.body);
return res.send(data);
}
const newUser = new User();
@nitish24p
nitish24p / UserPromise.js
Created June 26, 2018 17:23
User promise
exports.createOrAddUserPromise = (req, res, next) => {
User.findUserPromise(req.body)
.then(user => {
if (user) {
const existingUser = new User(user);
return newUser.updatePromise(req.body)
}
const newUser = new User();
return newUser.savePromise(req.body);
})
@nitish24p
nitish24p / UserCallback.js
Created June 26, 2018 17:14
User callback
exports.createOrAddUser = (req, res, next) => {
User.findUser(req.body, (err, data) => {
if (err) {
return next(err)
};
if (data) {
const existingUser = new User(data);
existingUser.update(req.body, (err, data) => {
if (err) {
@nitish24p
nitish24p / User.js
Created June 26, 2018 16:35
User Model
const user = {
id: 1,
username: 'Nitish',
age: 25,
profession: 'dev'
}
const error = new TypeError('Something broke in the db');
class User {
@nitish24p
nitish24p / index.js
Last active June 26, 2018 16:33
index.js for sever
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);
@nitish24p
nitish24p / Server markup.js
Last active April 15, 2018 15:45
Markup for server side render
/* @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 / server.js
Created January 18, 2018 09:31
Code split react loadable
/// 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);
});
});