Skip to content

Instantly share code, notes, and snippets.

export const StaticHtml = (props)=>{
const ref = useRef();
useEffect(() =>{
var elm = document.getElementById('some-static-html');
ref.current.appendChild(elm);
}, []);
return (<div ref={ ref }>
some div
@aniljaangra
aniljaangra / mongodb-s3-backup.sh
Created May 31, 2018 10:09 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@aniljaangra
aniljaangra / mongodb-aggregation-interview-question.js
Last active March 30, 2018 07:20
Basic MongoDB Aggregation Question for Interview Purpose
// There is a bonus collection where following properties are present
// { year , month , bonusAmount , empId }
// fetch total bonus for given year , monthwise and form following result
// // {
// "_id" : ......,
// "month" : <Month Name>,
// "avgBonus" : <Average Bonus for This Month Per Employee>,
// "totalBonus" : <Total Bonus for This Month>,
// "totalEmp" : <Total Number of Bonus Given This Month>,
// "empList" : [ <Employee Id List> ]
@aniljaangra
aniljaangra / better-nodejs-require-paths.md
Created February 23, 2018 08:58 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

const google = require('googleapis');
const drive= google.drive('v2');
const API_KEY = ''
const { OAuth2 } = google.auth;
const config = { clientId : '', clientSecret : '' }
const oauthClient = new OAuth2(config.clientId, config.clientSecret);
const credentials = {
"access_token": "",
"token_type": "Bearer",
"expires_in": 3600,
@aniljaangra
aniljaangra / react-redux-app-structure.txt
Last active September 28, 2017 06:27
React Redux Saga App Structure
app/
Header.js
Header-spec.js
Sidebar.js
Sidebar-spec.js
App.js
App-spec.js
reducers.js
reducers-spec.js
if( promo.discountOffPercentage ){
//if promotion type is percentage off
product.discountOffPercentage+=parseFloat(promo.discountOffPercentage);
discountOffAmount = ( parseFloat(product.qtyFulfilled) * parseFloat(product.supplierPTR) * parseFloat(promo.discountOffPercentage)) / 100;
} else if(promo.discountOffAmount ){
//if promotion type is amount off
discountOffAmount = parseInt(product.qtyFulfilled) * parseFloat(promo.discountOffAmount);
product.discountOffAmount += discountOffAmount;
}
if( promo.discountOffPercentage ){
//if promotion type is percentage off
product.discountOffPercentage+=parseFloat(promo.discountOffPercentage);
discountOffAmount = ( parseFloat(product.qtyFulfilled) * parseFloat(product.supplierPTR) * parseFloat(promo.discountOffPercentage)) / 100;
} else if(promo.discountOffAmount ){
//if promotion type is amount off
discountOffAmount = parseInt(product.qtyFulfilled) * parseFloat(promo.discountOffAmount);
product.discountOffAmount += discountOffAmount;
}