Configure HTML/JavaScript

Sunday, September 24, 2017

Deciding how to approach a negative emotions


We all know that in our life almost every day we see or face many things which are negative to us and we dont like them or its entirely against what we want.

In this situation what shoud be your aproach

Imotions

Its human nature whenever something happens which is entirely against what we want, anger, revenge, rage kind of feelings come to our mind. It's natural as we born with these qualities. I said it quality as these are god given weapons to protect us from external herp like the skin is protecting from many things which can harm body inner parts.

But when these emotions are acting against us who is going to protect us? Are these emotions acting the way it should be? When these emotions act against us, it ultimately pushes towards destruction, death. It's usual that when you suffer depression caused by something not happening what you want, your anger causes blood pressure, being in an unhealthy system will kill you soon and you will totally be pushed to a life where no enjoyment but only negative thoughts.

Approach to Emotion

We should take the positive approach how much big the negative hit we got in life. We should convert that negative energy to positive and use it in favour of us and should not allow that negative energy to harm us rather help us to improve us.

Acting to a social media post


Many times we see some social media post when is entirely again what we wanted to listen. Taking an example, Durga Puja festival is a known famous national and international festival and its rich culture of Bengalis. Now the government is putting some restriction on them because some other festival is coming in the same day! 

Rather than keep commenting negative posts on it and starting a fight with everybody you should keep posting positive thoughts about the festival, its advantages in developing nations, how it is contributing towards society, development and how to protect this years old festival.

When you post or fight against the negative post, somehow you are also promoting the negative post which even does not deserve and you dont even like it. And you ware westing your valuable key energy on that. I would say you should put all your energy to promot and post positive posts about the event like Durga puja rhater finght against bunch of people trying to oppose that got just shake of their personal gain. Its always matters all people when it comes to compair personal/individual gain and humanity gain.





Tuesday, September 12, 2017

Forcing user to add license comment in Code file and preventing users to use specific words in project code

There are many use cases and projects where we want to place license in all the file as comment at the top of the file or bottom file. If one of the file missed or wrong license text is placed, it might be a problem for legal team or any legal action will dependent on this.

In this situation is really good idea to to check before you commit your code to repository that license text is there in all files. Yap! you got it, we need to place a pre-commit hook in our repository so that any file does not have that, we will not allow them to push code to repository.


pre-commit hook 

There is a great module available in npm which does all in perfect way we want. Only thing is we have to tell him what we need to do.

So the idea is to place a pre-commit hook and assign some node script before code can be commited to the repository. so install pre-commit in your project as dependencies

npm install --save-dev pre-commit

https://www.npmjs.com/package/pre-commit


Hooking the script in pre-commit

Finding license test in all files


Now it time to fine license test in all the file. The below node script will happly do that for us and will let us know which file does not have the license text

(function () {
  var fs = require('fs');
  var glob = require('glob-fs')();
  var path = require('path');
  var result = 0;
  var exclude = ['LICENSE',
    path.join('e2e', 'util', 'db-ca', 'rds-combined-ca-bundle.pem'),
    path.join('src', 'favicon.ico')];
  var files = [];
  files = glob.readdirSync('**');
  files.map((file) => {
    try {
      if (!fs.lstatSync(file).isDirectory() && file.indexOf('.json') === -1 
           && exclude.indexOf(file) === -1) {
        var data = fs.readFileSync(file, 'utf8');

        if (data.indexOf('Copyright 2017 candifood contributors') === -1) {
          console.log('Please add License text in coment in the file ' + file);
          result = 1;
        }
      }
    } catch (e) {
      console.log('Error:', e.stack);
    }
  });
  process.exit(result);
})();




Now this script can be executed by node to find the license text in all file. 
Now its time to hook it in the pre-commit.

Hooking the script in pre-commit

To hook the script in pre commit we need to create a script in package.json and tell
the pre-commit to use that before pre-commit.
{
  "name": "project-name",
  "version": 1.0.0",
  "license": "Apache 2.0",
  "scripts": {
    "license-check": "node license-check",
  },
  "private": true,
  "dependencies": {
  },
  "devDependencies": {
    "pre-commit": "1.2.2",
  },
  "pre-commit": [
    "license-check"
  ]
}

Thats all! When we commit the code the pre-commit will call the node script 
and it will stop if any file there is no license test.


Check if company confidential information is placed in code

Now its time to check if any specific company information is there in the code in same pre hook.
So we will add another hook in the pre-commit and to check that.
So the new package.json will be
{
  "name": "project-name",
  "version": 1.0.0",
  "license": "Apache 2.0",
  "scripts": {
    "license-check": "node license-check",
    "license-check": "node prevent-secret",
}, "private": true, "dependencies": { }, "devDependencies": { "pre-commit": "1.2.2", }, "pre-commit": [ "license-check",
    "prevent-secret"
] }

Prevent secret code

Now the below wcript will be executed after license check in pre-commit and will tell us
if any keyword is confidential word is used in our code which may cause problem when the code will go to outside.
(function () {
  var fs = require('fs');
  var glob = require('glob-fs')();
  var path = require('path');
  var result = 0;
  var exclude = [
    'LICENSE',
    path.join('e2e', 'config', 'conf.e2e.json'),
    path.join('src', 'favicon.ico')
  ];
  var files = [];
  files = glob.readdirSync('**');

  var patternString = [
    // 'i am oeky',    // 'famous',    'secret',
    'moana'  ];

  files.map((file) => {
    try {
      if (!fs.lstatSync(file).isDirectory() && exclude.indexOf(file) === -1) {
        fs.readFileSync(file).toString().split(/\r?\n/).forEach(function(line){
          patternString.map((pattern) => {
            if (line.indexOf(pattern) !== -1) {
              console.log('' + file + ': `' + pattern + '` in line [' + line +']');
              // result = 1;            }
          });
        });
      }
    } catch (e) {
      console.log('Error:', e.stack);
    }
  });
  process.exit(result);

})();

So we all set! And its really batter then put a search query  manually and find all these words. Here we will do all them even before our code to go to repository.

if this did not solve your problem, put comment your case and I will try to resolve that.