Skip to content

Instantly share code, notes, and snippets.

View pulkitsinghal's full-sized avatar

Pulkit Singhal pulkitsinghal

View GitHub Profile
@pulkitsinghal
pulkitsinghal / release-candidate.mermaid
Last active February 19, 2019 13:03
Workflow for a Release Candidate in Git
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pulkitsinghal
pulkitsinghal / hotfix.mermaid
Last active July 22, 2018 12:26
Workflow for a Hotfix in Git
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pulkitsinghal
pulkitsinghal / testMap.js
Last active July 19, 2018 17:48
How does promise.map() implementation behave in bluebird?
var Promise = require('bluebird');
var tests = [
"hell",
"hell",
"hell",
"heaven",
"hell"
];
@pulkitsinghal
pulkitsinghal / testAll.js
Created July 19, 2018 17:46
How does promise.all() implementation behave in bluebird?
var Promise = require('bluebird');
var a=0, b=0, c=0, d=0, e=0;
var tests = [
Promise.delay(5000).then(function(){a++; return Promise.resolve("hell5");}),
Promise.delay(1000).then(function(){b++; return Promise.resolve("hell4");}),
Promise.delay(3000).then(function(){c++; return Promise.resolve("hell3");}),
Promise.delay(2000).then(function(){d++; return Promise.reject("heaven2");}),
Promise.delay(1000).then(function(){e++; return Promise.resolve("hell1");})
];
@pulkitsinghal
pulkitsinghal / 01-attach-roles-to-custom-user-model.js
Last active February 13, 2018 18:43
Raw source for the steps in add-multi-tenancy.md
module.exports = function(app){
var RoleMapping = app.models.RoleMapping;
var UserModel = app.models.UserModel;
var Role = app.models.Role;
RoleMapping.belongsTo(UserModel);
UserModel.hasMany(RoleMapping, {foreignKey: 'principalId'});
UserModel.hasMany(Role, {as:'roles', through: RoleMapping, foreignKey: 'principalId'});
Role.hasMany(UserModel, {through: RoleMapping, foreignKey: 'roleId'});
};
@pulkitsinghal
pulkitsinghal / test.1.sh
Last active February 13, 2018 18:51
Test for multi tenancy in a loopback starter project
#!/bin/sh
#1.0 setup HOST_URL && make sure that HOST_URL is setup
export HOST_URL=http://localhost:3000 && echo "HOST_URL=$HOST_URL"
#2.0 orgAdminA signs-up
export ORG_ADMIN_A=`curl -X POST \
"$HOST_URL/api/1.0/UserModels/signup" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
@pulkitsinghal
pulkitsinghal / README.md
Last active November 9, 2017 18:35
Simplify management by unifying projects using submodules in git

Unify

  1. Create a unified project

    mkdir ~/dev/parentProjectName && \
    cd ~/dev/parentProjectName && \
    git init && \
    git submodule add git@github.com:orgName/projA.git projA && \
    git submodule add git@github.com:orgName/projA.git projB
    
@pulkitsinghal
pulkitsinghal / README.md
Last active September 20, 2017 04:17
Why is my NodeJS process hanging in Docker?

Establish the directory structure

  • README.md
    • docker-compose.yml
    • worker/package.json
    • worker/src/utils.js
    • worker/src/sampleNodeProcess.js

Run the experiment

@pulkitsinghal
pulkitsinghal / setenv.sh
Last active June 16, 2018 06:16
Read the .env file and setup the environment variables for local testing
#!/bin/sh
# This script is used to read the .env file and setup the enviroment variables for local testing
echo "###"
echo Its best to invoke this script as: '. ./setenv.sh' rather than './setenv.sh'
echo "###"
while read kv
do
key=${kv%%=*}
@pulkitsinghal
pulkitsinghal / sample.js
Created September 7, 2017 21:55
Replace empty headers with misc. header names in PapaParse
// References:
// https://stackoverflow.com/questions/35113926/change-csv-headers-while-processing-papaparse
// https://github.com/mholt/PapaParse/issues/196
// https://github.com/mholt/PapaParse/pull/192/files
// https://github.com/mholt/PapaParse/issues/413
beforeFirstChunk: function(chunk) { // replace empty headers with misc. header names
var rows = chunk.split( /\r\n|\r|\n/ );
//console.log(rows[0]);
var headings = rows[0]; //var headings = '"Item Number","Vend Reorder Number","Description","Item Category","Price-1","Last Cost","Account Code","Attribute-1","","Attribute-2","Attribute-3","Attribute-4","Attribute-5","Attribute-6","Category/Subcategory","Default cost of sale %","Eccomerce Item"," ","Item Type","Long Description","Price Desimal","Quantity Desimal","Regular Price","","Status","Subcategory","Primary Vendor"';