RSS

Author Archives: Creators

About Creators

Yet another starters in the field of IT who have just started their journey and progressing through crossing each and every hurdle successfully.

npm install bcrypt fails on Windows 7 / windows7 64

Step1: Download and install visual studio(2013 or 2015) in your machine.

Step2: Go to the project folder and execute the following command. It will try to install bcrypyt plugin.

npm install --msvs_version=2013

Step3:start your application now

npm start

 

 

 
Leave a comment

Posted by on January 18, 2016 in nodejs

 

Tags: , , , , , ,

Enable Crontab Job in ubuntu/Centos

Step1:

List crontab jobs

crontab -l

Step2:

Open and edit crontab

crontab -e

Step3:

copy and past the following comment and replace the exact path.

Example to run every 1 min:

*/1 * * * * /home/user/fileToStart.sh >> /home/user/logfile.log 2>&1

Example to run on 4:01am on January:

01 04 * * * /home/user/fileToStart.sh >> /home/user/logfile.log 2>&1

Layout example:

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday)

01 04 1 1 1 /home/user/fileToStart.sh >> /home/user/logfile.log 2>&1

 

 
Leave a comment

Posted by on December 31, 2015 in CentOS, shellscript, Ubuntu

 

R script – Error in UseMethod(“meta”, x) : TermDocumentMatrix.VCorpus

Ever got this error when running R script with tm package??

Error in UseMethod(“meta”, x) :
  no applicable method for ‘meta’ applied to an object of class “try-error”
Calls: source … TermDocumentMatrix.VCorpus -> meta -> meta.VCorpus -> lapply -> FUN
Just try this line before using the TermDocumentMatrix,
textvectors <- Corpus(VectorSource(textvectors))
And then proceed with the TermDocumentMatrix which uses the textvectors
 
1 Comment

Posted by on February 4, 2015 in R

 

Tags: , , ,

Install R in Ubuntu

Add the following to /etc/apt/sources.list

deb http://cran.rstudio.com/bin/linux/ubuntu precise/

Then execute these commands

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys E084DAB9

sudo add-apt-repository ppa:marutter/rdev

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install r-base

 
Leave a comment

Posted by on February 4, 2015 in R

 

Tags: , , ,

Gradle ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java

When using gradle build, we would have faced this error

JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java though we have already set the JAVA_HOME correctly

The reason might be gradle itself tries to export java home once again

Just open /usr/bin/gradle file and find the line

export JAVA_HOME = /usr/lib/jvm/default-java and comment it out

Now it should work fine

 
Leave a comment

Posted by on October 14, 2014 in Gradle

 

Tags: , , ,

Git Keep only recent commits in history

Ever faced a situation to cleanup the history in git where you do not need to retain very older commits in history that you never will rollback or do any operation??

I faced this where i need only recent 700 commits in my history.

Here is the work around i did.

Let branch1 be the one which has some 5k+ commits committed years ago

Now i need branch2 with just recent 700 commits in the history, that is the 700th commit from present to past should be the initial one of the repo

I used the fast-export and import feature of git along with the linux sed command combined together for this

git fast-export branch1~700..branch1 | sed “s|refs/heads/branch1|refs/heads/branch2|” | git fast-import

  1. Use fast-export to export the recent 700 commits in branch1 branch
  2. sed – way to create a new branch called branch2 out of branch1 branch
  3. Import the exported 700 commits alone into the branch2 branch

Now you will have your desired branch2 in your local repo which you can push to github

 
Leave a comment

Posted by on October 9, 2014 in Git

 

Tags: , , ,

Insert dynamic regular expression to replace string in javascript

Insert Regular Expression dynamically to replace string in javascript.

var regex = new RegExp('nornaml_'+(dynamicValue), 'g');
replaceString.replace(regex, "Replace Value");
 
Leave a comment

Posted by on May 27, 2014 in General

 

Insert Content in Cursor position using jquery

HTML Content:

<input type="button" value="Paste HTML" onclick="document.getElementById('contDiv').focus(); pasteHtmlAtCaret('<b>INSERTED</b>'); "> 

<div id="contDiv" contenteditable="true">  
Place to Past Content
</div>

Javascript method to print the content in cursor position:

function pasteHtmlAtCaret(html) {
  var sel, range;
  if (window.getSelection) {
    
    // IE9 and non-IE
    sel = window.getSelection();
    if (sel.getRangeAt && sel.rangeCount) {
      range = sel.getRangeAt(0);
      range.deleteContents();
    
      // Range.createContextualFragment() would be useful here but is
      // non-standard and not supported in all browsers (IE9, for one)
      var el = document.createElement("div");
      el.innerHTML = html;
      var frag = document.createDocumentFragment(), node, lastNode;
      while ( (node = el.firstChild) ) {
        lastNode = frag.appendChild(node);
      }
      range.insertNode(frag);
   
      // Preserve the selection
      if (lastNode) {
        range = range.cloneRange();
        range.setStartAfter(lastNode);
        range.collapse(true);
        sel.removeAllRanges();
        sel.addRange(range);
      }
    }
   } else if (document.selection && document.selection.type != "Control") {
     // IE < 9
     document.selection.createRange().pasteHTML(html);
   }
}

 

 

 

 
Leave a comment

Posted by on May 21, 2014 in jquery

 

Tags: ,

Clone row using javascript

Create element and add that in to table row using javascript.

Create Element Syntax: 

document.createElement(nodename)

Create Element Example:

var txtNode=document.createTextNode(“Hello World”);
var head1=document.createElement(“H1”);
var para=document.createElement(“p”);
var text=document.createElement(‘input’);
var textarea=document.createElement(“textarea”);
var label=document.createElement(‘label’);

Example HTML table Clone:

<body>
 <table id="exampleDataTable" cellpadding="0" cellspacing="0" width="100%" border="0"></table>
<br/>
 <input type="button" id="" onclick="getData('exampleDataTable')" value="submit" />
</body>

Java script methods:

<script type="text/javascript">

 //initially create new table
 addRow('exampleDataTable');
 //delete table row delete button
 function tableDeleteRow(tabObj) {
    var rowsIndex=tabObj.parentElement.parentElement.rowIndex;
    var table = document.getElementById('exampleDataTable');
    try {
       if(rowsIndex!=0){
          table.deleteRow(rowsIndex); 
       }
    }catch(e) {
       alert(e);
    }
 }
 //add table row using add button
 function addRow(tableID) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var cell1 = row.insertCell(0);
    var element1 = document.createElement("select");
    cell1.style.padding="3px";
    element1.style.width = "200px";
    element1.style.marginBottom = "0px";
    element1.id="option_example";
    var element1_relation =["Option1","Option2","Option3"];

    for (var i=0;i<element1_relation.length;i++){
       var option;
       option = document.createElement("option");
       option.setAttribute("value", element1_relation[i]);
       option.innerHTML = element1_relation[i];
       element1.appendChild(option);
    }
    cell1.appendChild(element1);

    var cell2 = row.insertCell(1);
    var element2 = document.createElement('input');
    cell2.style.padding="3px";
    element2.style.width = "200px";
    element2.style.marginBottom = "0px";
    element2.id="input_example";
    cell2.appendChild(element2);

    var cell3 = row.insertCell(2);
    var element3 = document.createElement("textarea");
    cell3.style.padding="3px";
    element3.style.width = "200px";
    element3.style.marginBottom = "0px";
    element3.id="textarea_example";
    cell3.appendChild(element3);

    var cell4 = row.insertCell(3);
    var element4 = document.createElement("BUTTON");
    cell4.style.padding="3px";
    element4.appendChild(document.createTextNode("Add"));
    element4.setAttribute("onClick", "addRow('exampleDataTable')");
    cell4.appendChild(element4);

    var cell5 = row.insertCell(4);
    var element5 = document.createElement("BUTTON");
    cell5.style.padding="3px";
    element5.appendChild(document.createTextNode("Delete"));
    element5.setAttribute("onClick", "tableDeleteRow(this)");
    cell5.appendChild(element5);
 }

 //get all the row data
 function getData(tableID){
    try {
       var table = document.getElementById(tableID);
       var rowCount = table.rows.length;
       var jsonArray = new Array();
       for(var index=0; index < rowCount; index++) {
          var mapObj = {};
          var row = table.rows[index];
          var name1 = row.cells[0].childNodes[0];
          var name2 = row.cells[1].childNodes[0];
          var name3 = row.cells[2].childNodes[0];

          mapObj['name1'] = name1.value;
          mapObj['name2'] = name2.value;
          mapObj['name3'] = name3.value;
      }
    }catch(e) {
       alert(e);
    }
 }

</script>

 

 
3 Comments

Posted by on September 20, 2013 in General, Javascript

 

Tags: ,

Replace Input HTML tags

Replace input html tag to span tag using javascript recursion function. “getFormchildren(startNode,output)” method contain startNode and output div.

Following methods replace tag and its child tag upto end child tag using recursion. We can differentiate value field,non value field, checkbox, radio button, and textarea.

function getFormChildren(startNode, output){
     var nodes;
     if(startNode.childNodes){
          nodes = startNode.childNodes;
          childrenNode(nodes, output);
     }else{
          alert("The Doesnot Have any Child");
     }
}
function childrenNode(nodes, output){
     var node;
     for(var i=0;i<nodes.length;i++){
          node = nodes[i];
          if(output){
               childNode(node);
          }
          if(node.childNodes){
               getFormChildren(node, output);
          }
     }
}
function childNode(node){
 var isCheckBoxChecked = 0;
 var isRadioChecked = 0;
 if(node.nodeType == 1){
 if((node.getAttribute('value') == null || node.getAttribute('value') == "") || (node.id == null || node.id == "")){
 if((node.tagName == 'INPUT' || node.tagName == 'input')&&(node.type != "radio" || node.type != "RADIO")&& (node.type != "checkbox" || node.type != "CHECKBOX")){ 
 $('input[type=button]').each(function(){
 $(this).remove();
 });
 $('input[type=submit]').each(function(){
 $(this).remove();
 }); 
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onClick'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onFocus'));
 htmlSourceViewObj.setAttribute("class",node.getAttribute('class'));
 var value=document.createTextNode(node.value);
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else if(node.id == null || node.id == "") {

 }else if(node.tagName == "SELECT" || node.tagName == 'select'){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onClick'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onFocus'));
 htmlSourceViewObj.setAttribute("class",node.getAttribute('class'));
 var value=document.createTextNode(node.value);
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else if((node.tagName == 'textarea' || node.tagName == 'TEXTAREA')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onClick'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onFocus'));
 htmlSourceViewObj.setAttribute("class",node.getAttribute('class'));
 var value=document.createTextNode(node.value);
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else if((node.tagName == 'img' || node.tagName == 'IMG')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.name);
 htmlSourceViewObj.setAttribute("src",node.getAttribute('src'));
 htmlSourceViewObj.setAttribute("gridName",node.getAttribute('gridName'));
 htmlSourceViewObj.setAttribute("height",node.getAttribute('height'));
 htmlSourceViewObj.setAttribute("width",node.getAttribute('width'));
 var value=document.createTextNode(node.getAttribute('src'));
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else{

 }
 }else{
 if((node.tagName == 'INPUT' || node.tagName == 'input')&&(node.type == "checkbox" || node.type == "CHECKBOX")){ 
 if(isCheckBoxChecked == 0){
 $('input[type=checkbox]').each(function(){
 if($(this).is(':checked')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",this.id);
 htmlSourceViewObj.setAttribute("name",this.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",this.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("class",this.getAttribute('class'));
 var value=document.createTextNode("True ");
 htmlSourceViewObj.appendChild(value);
 $(this).replaceWith(htmlSourceViewObj);
 }
 if ($(this).is(':not(:checked)')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",this.id);
 htmlSourceViewObj.setAttribute("name",this.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",this.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("class",this.getAttribute('class'));
 var value=document.createTextNode("False ");
 htmlSourceViewObj.appendChild(value);
 $(this).replaceWith(htmlSourceViewObj);
 }
 });
 isCheckBoxChecked = 1;
 } 
 }else if((node.tagName == 'INPUT' || node.tagName == 'input')&&(node.type == "radio" || node.type == "RADIO")){
 if(isRadioChecked == 0){
 $('input[type=radio]').each(function(){
 if($(this).is(':checked')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",this.id);
 htmlSourceViewObj.setAttribute("name",this.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",this.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("class",this.getAttribute('class'));
 var value=document.createTextNode("True ");
 htmlSourceViewObj.appendChild(value);
 $(this).replaceWith(htmlSourceViewObj);
 }
 if ($(this).is(':not(:checked)')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",this.id);
 htmlSourceViewObj.setAttribute("name",this.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",this.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("class",this.getAttribute('class'));
 var value=document.createTextNode("False ");
 htmlSourceViewObj.appendChild(value);
 $(this).replaceWith(htmlSourceViewObj);
 }
 });
 isRadioChecked = 1;
 } 
 }else if((node.tagName == 'INPUT' || node.tagName == 'input')&&(node.type != "radio" || node.type != "RADIO")&& (node.type != "checkbox" || node.type != "CHECKBOX")){
 $('input[type=button]').each(function(){
 $(this).remove();
 });
 $('input[type=submit]').each(function(){
 $(this).remove();
 });
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.getAttribute('name'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onchange'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onClick'));
 htmlSourceViewObj.setAttribute("onchange",node.getAttribute('onFocus'));
 htmlSourceViewObj.setAttribute("class",node.getAttribute('class'));
 var value=document.createTextNode(node.getAttribute('value'));
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else if((node.tagName == 'img' || node.tagName == 'IMG')){
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.name);
 htmlSourceViewObj.setAttribute("src",node.getAttribute('src'));
 htmlSourceViewObj.setAttribute("gridName",node.getAttribute('gridName'));
 htmlSourceViewObj.setAttribute("height",node.getAttribute('height'));
 htmlSourceViewObj.setAttribute("width",node.getAttribute('width'));
 var value=document.createTextNode(node.getAttribute('src'));
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }else{
 var htmlSourceViewObj = document.createElement("span");
 htmlSourceViewObj.setAttribute("id",node.id);
 htmlSourceViewObj.setAttribute("name",node.getAttribute('name'));
 htmlSourceViewObj.setAttribute("class",node.getAttribute('class'));
 var value=document.createTextNode(node.value);
 htmlSourceViewObj.appendChild(value);
 $("#"+node.id).replaceWith(htmlSourceViewObj);
 }
 }
 } 
}
 
Leave a comment

Posted by on September 20, 2013 in General, Javascript, jquery

 

Tags: , , ,