Monday, August 22, 2016

Replace command

<-------------------------------------- Replace command -------------------------------------------------------->


sudo find /home/ngit/tomcat/webapps/mrb/js/ -type f -print0 | xargs -0 sed -i 's/KisanBazaar/KisanPoint/g';


Replace kisanbazar with kisanpoint

Thursday, July 28, 2016

Query to display whole data upto the previous day.

select XXXXX, SSSSSSSS, DDDDDD , CAST(date(h_date) as CHAR) as h_date from TABLENAME where h_date < (CURDATE()) order by h_date desc  ";

ie., If the current date is 22-08-2016 , It will display data upto 21-08-2016 .
Example:
+--------------+
| h_date |
+--------------+
| 2016-07-27   |
| 2016-07-27   |
| 2016-07-23   |
| 2016-07-20   |
| 2016-07-18   |
| 2016-07-15   |
| 2016-07-13   |
| 2016-07-13   |
| 2016-07-12   |
| 2016-07-10   |
+--------------+

Wednesday, July 20, 2016

Convert amount to indian rupees :

Convert amount to indian rupees : 

double totalinvestmentabilityamount = Double.parseDouble(totalamount);
String totalinvestmentabilityamount1=formatt(totalinvestmentabilityamount);


we should add this methods in our servlet:


public static String formatt(double value) {
 LogLevel.DEBUG(5,new Throwable(),"jhansi value:"+value );

    if(value < 1000) {
        return formatt("###", value);
    } else {
        double hundreds = value % 1000;
        int other = (int) (value / 1000);
        return formatt(",##", other) + ',' + formatt("000", hundreds);
    }
}

private static String formatt(String pattern, Object value) {
    return new DecimalFormat(pattern).format(value);
}

If total amount is 2003763714 it will display in indian rupee format as 2,00,37,63,714 

Saturday, July 16, 2016

How do you tell if caps lock is on using JavaScript?


<input autocomplete="off"  type="text" id="username" title="login" name="username" onkeypress="isCapLockOn(event)" class="width_100"><div id='username_error'style="display:none;"></div>


function isCapLockOn(e)
{
var charKeyCode = e.keyCode ? e.keyCode : e.which; // To work with both MSIE & Netscape
var shiftKey = e.shiftKey ? e.shiftKey : ((charKeyCode == 16) ? true : false);
// Check both the condition as described above
if (((charKeyCode >= 65 && charKeyCode <= 90) && !shiftKey)
|| ((charKeyCode >= 97 && charKeyCode <= 122) && shiftKey))
{
// Caps lock is on
document.getElementById('username_error').innerHTML = "Caps lock : <b>On</b>";
}
else
{
// Caps lock is off.
document.getElementById('username_error').innerHTML = "Caps lock : <b>Off</b>";
}

}

How to capitalize the first letter of a String in Java?

WordUtils.capitalize(str)

For Example:

<tr><th><p class='result_title'>Name</p> </th><td>:&nbsp;&nbsp;"+WordUtils.capitalizeFully(stragriname)+"</td></tr>

Monday, July 11, 2016

characters countfor description in jsp

<div class="form-group clear">
<label class="col-lg-3 col-md-3 col-xs-12 control-label">Description *:</label>
<div class="col-lg-9 col-md-9 col-xs-12">
<textarea rows="5" cols="5" class="form-control"  id='description1' name='description1' placeholder='Enter your Description' ></textarea><div id="textarea_feedback"></div><div class ="help-block" id='description1-error'style="display:none;"></div></div></div>



$(document).ready(function() {
var text_max = 500;
$('#textarea_feedback').html(text_max + ' characters remaining');

$('#description1').keyup(function() {
    var text_length = $('#description1').val().length;
    var text_remaining = text_max - text_length;

    $('#textarea_feedback').html(text_remaining + ' characters remaining');
});

});

Thursday, June 30, 2016

How do I make a field autofocus?

<form action="demo_form.asp">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form>

Wednesday, June 29, 2016

How to expire page on back button click in browser?

<%response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-store"); response.setHeader("Expires","0"); response.setDateHeader("Expires",-1); %>

Thursday, June 23, 2016

To restart httpd , mysql and tomcat series:

To restart httpd series:

1) login as root

# sudo su -
]$ cd /opt/Empt-Time-Mgmt-WebServ/bin
]$ ./apachectl -k restart
]$ exit



To restart mysql series :

]$ sudo su -

]$ /etc/init.d/mysql restart



To restart tomcate series:

]$ source /home/ngit/tomcat/webapps/myvillage/lib/bprofile
]$ cd ./home/ngit/tomcta/bin
]$ cd ../logs
]$ rm -rf *.log
]$ >cataina.out
]$ cd ../work
]$ rm -rf Catalina
]$ cd ../bin
]$ ./startup.sh

Wednesday, June 22, 2016

code for inline search



Step 1 : In JSP Need to place the below mentioned code

Note : In this code snippet i have placed autocomplete="false" to avoid autofill chrome settings

<div id="areadiv">
<input type='text' autocomplete="off" id='area' name='area' placeholder='Enter Area' style='width:96%;margin-left:5px;height:40px;border: 2px solid #CCC;font-size:14px;    font-weight: 600;font-family: ;border-radius: 4px 4px 4px 4px;background:white url(/tyres/images/searchhome.png) no-repeat 365px 9px;  padding-left:20px;' maxlength='50' onkeyup="getinlinesearch(event,'onkeyup');"><input autocomplete="false" class="enter_email_input"  name="whereever6" id="location6" placeholder="Enter Your City.." type="text" onkeyup="displayinlinewherever('caraccessories');" style='display:none;'></div>

Step 2 : To get area details need to place respective inline search function in before select drop down menu(i.e, city) as mentioned below

<select name="city" id ="city" class="drop_dn_tyres" onchange="getinlinesearch(event,'onchange');">  
    <option  value="0" >Select&nbsp;City</option>
   </select>

Step 3 : Include below mentioned js and css files

<link rel="stylesheet" href="/../css/jquery-ui.css">
<script src="/../js/jquery-ui.js"></script>

Step 4: Place the below mentioned css code in style

.dialog{width:100%;font: 12px/22px ; text-align:center;    font-family: Helvetica Neue,Helvetica,Arial,sans-serif;position:absolute;padding: 1px;display: none;z-index:9999; background: #232323;}
.ui-autocomplete
{
    position: absolute;
    cursor: default;
    height: 200px;
    overflow-y: scroll;
    overflow-x: hidden;
}

.ui-autocomplete .highlight {
   text-decoration: underline;
  }


.highlight {
   width: 159px;
    border-style: dotted;
    border-color: #cccccc;

  }

Step 5: Javascript Function
var newitems;
 function getinlinesearch(event,keytype)
  {
   //alert("inside");
  
   var city=document.getElementById("city").value;
   // alert(city);
  
   var i;
   var items="";

  
    i=$("#area");
    //document.index.searchward.style.background = 'url(/myvillage/images/searchhome.png) no-repeat 209px 9px';
  
   var val=i.val();
   /*code to high light autocomplete*/
   $.ajaxSetup({ cache: false });
   $.ui.autocomplete.prototype._renderItem = function (ul, item)
   {
    var term = this.term.split(' ').join('|');
    var re = new RegExp("(" + term + ")", "gi");   
    var itemlabel=item.label;
    var results=itemlabel.split("--");
    var value1=results[0];
    var value2=results[1];
    var t = itemlabel.replace(re, "<b>$1</b>");
    //var t1=t+" -- "+value2;
    return $("<li></li>")
    .data("item.autocomplete", item)
    .append("<a>" + t + "</a>")
    .appendTo(ul);
   };
   var vallength=val.length;
   if(vallength==0)
     {
     
    // Get the input element and its value
    document.getElementById("area").style.background = 'url(/tyres/images/searchhome.png) no-repeat 365px 9px';
     
     }
   //alert(keytype);
   if(keytype=="onchange")
   {
     /*$city = $('#city');
     var splitvalcity =$city.val(); 
     alert(splitvalb);
      if(splitvalcity=="default")
     {
      //alert("1");
      //$('#city').addClass('highlightbefore');
      //$('#city').removeClass('highlightafter');
      document.getElementById("city").focus();
     }
     else
     {
      //alert("2");
      //$('#city').removeClass('highlightbefore');
      //$('#city').addClass('highlightafter');
      document.getElementById("city").focus();
     }*/
   
     //window.scrollTo(0,document.body.scrollHeight);
     i.autocomplete({source: []});
     i.autocomplete("destroy");
     newitems="";
     $.get("./servlet/InlineSearch?city="+city+"&keyword="+onchange+"",function(data)
      {
       //alert("data :" +data);
       // Get each item separated by new line
       newitems=data.split("\n");
       //alert(newitems);
      document.getElementById("area").focus();
      //$('#corner').hide();
      //window.scrollTo(0, 150);
      });
   }
   else
   { 
     //$('#corner').hide();
    
     //alert("newsitems :" +newitems);
     // put those items in autocomplete! That's it!
     i.autocomplete({ width: 300,
     max: 10,
     delay: 100,
     minLength:2,
     autoFocus: true,
     cacheLength:1,
     scroll: true,
     highlight: true,
     source:newitems,
     select: function (event, ui, icon)
     {
      var charCode = (event.which) ? event.which : event.keyCode
      if(charCode==13)
      {
       i.css("background", "");
      
      }
     
       i.css("background", "none");
     
      /* do stuff with selection*/

      //alert("s");
       //window.location.hash = '#findbatterybutton';
      //window.scrollTo(0,document.body.scrollHeight);

      //$('#corner').show();
      //$('#findbatterybutton').addClass('highlight');
      //document.getElementById("focusable").focus();

       //$("#findbatterybutton").focus();
     },
     close: function ()
     {
     
       //this.value='';
       /* OR $(this).val('')*/
     }
     });
       
   }
}

Step 6: Method in Servlet

String s =  (req.getParameter("com") != null) ? (req.getParameter("com")) : "";
    LogLevel.DEBUG(5,new Throwable(),"s :"+s);

    String city =  (req.getParameter("city") != null) ? (req.getParameter("city")) : "";
    LogLevel.DEBUG(5,new Throwable(),"city :"+city);
  
    String keyword =  (req.getParameter("keyword") != null) ? (req.getParameter("keyword")) : "";
    LogLevel.DEBUG(5,new Throwable(),"keyword :"+keyword);

    Vector panchayatnamevector = new Vector();
   
    String panchayatname="select distinct(area) from location_area where location='"+city+"' order by area asc";
    LogLevel.DEBUG(5,new Throwable(),"panchayatname :"+panchayatname);
    panchayatnamevector=qm.executeQuery(panchayatname);
    
    LogLevel.DEBUG(5,new Throwable(),"panchayatnamevector :"+panchayatnamevector);
    String strRes="";
    ArrayList<String> as=new ArrayList<String>();

    s=s.toLowerCase();

    for(int j=0; j<panchayatnamevector.size();j++)
    {  
     Hashtable panchayatht=(Hashtable)panchayatnamevector.get(j);
     String area=String.valueOf(panchayatht.get("area"));
     LogLevel.DEBUG(5,new Throwable(),"area:"+area);

     String arealower=area.toLowerCase();
     LogLevel.DEBUG(5,new Throwable(),"arealower :"+arealower);
    
      if(keyword.equals("onchange"))
      {
       as.add(area);
      }
      else
      {
       if(arealower.startsWith(s))
       {
        LogLevel.DEBUG(5,new Throwable(),"if :"+arealower);      
        as.add(area);      
       }
      }
    
    }
    LogLevel.DEBUG(5,new Throwable(),"as:"+as);
  
    for(String st:as)
    {    
      out.println(st);    
    }
    out.close();

 }





How to reset dropdown list select ' dropdown' on 'back' button of browser using Javascript

You can use the 'onbeforeunload' event:

<script>
function reset_options() {
    document.getElementById('MySelect').options.length = 0;
    return true;
}

</script>

<body onbeforeunload="reset_options()">

To find out the keyword in the node

for example go to the path:  cd /home/ngit/tomcat/webapps/smarthr/

Example Keyword Haryana:

grep -H -R Haryana * | cut -d: -f1

If Else Condition for html tags


<% if(pagename.equals("agri"))
{ %>
<li>Agri Service Units  Login</li>

<% }
else

{ %>
<li> Agri Product Companies Login</li>

<% } %>

To disable copy paste for textbox

<input type="textbox" id="email" oncopy="return false" onpaste="return false" >

Ket Event Codes in javascript

http://www.asquare.net/javascript/tests/KeyCode.html

how to check create table

show create table agri_service_details;

How to redirect a website to mobile version:

--> Javascript window.location Method

--> Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You place this code in the head section of your main website code. That way when your site is visited, the javascript will see the browser width and redirect to the appropriate site

You can use the following code to do this:

<script type="text/javascript">
  <!--
  if (screen.width <= 800) {
    window.location = "http://m.domain.com";
  }
  //-->
</script>

to change the column name in a table:


mysql> alter table adaptation_officer_table change accept_invitation_activepartner accept_invitation_activepartners varchar(20);

Solution for reaching mysql:

 ** Increase Key Buffer ( yours is currently 64MB, but total indexes are 116M, so put at least 128MB). Should help immediately.
 ** Run mysqloptimize and mysqlrepair on your tables
 ** Increase table cache/ decrease total number of tables to increase the table cache hit rate. Maybe you've got some unused or old tables which could be deleted.

Other recommended confugration options:

   ** log_slow_queries = /var/log/mysql/mysql-slow.log
   ** long_query_time = 4
   ** log-queries-not-using-indexes

Check log file after some time.

-------------------------------------------------------

SET global max_connections = 1000000

show variables like 'max_connections'

mysql> show status like '%onn%';

mysql> show processlist;

To kill the mysql process

]$ sudo kill -9 process-id
]$ sudo service mysql start
]$ ps -ef | grep mysql

change the version number after changes done in the css files

WEB.XML

(GIS Version number)

history of last committed of a file:

]$ cvs log filename

shutdown and startup


]$ source /home....
]$ ./shutdown
]$ cd ../logs
]$ rm -rf *.log
]$ cd ../work
]$ rm -rf Catalina
]$ cd ../bin
]$ source ...
]$ ./startup

Remove logs:

> cd tomcat/logs
 >rm -rf *.log
 >catalina.out
> cd ../work
> sudo rm -rf Catalina
 >cd ../webapps/myvillage/logs
 >gis.log

Indexing:

show indexes from table_name. create index masters_key on qpa_survey_status (masters_key);

mysql commands:

1) create indexing for every field wherever you are using "where" condintion in the query. 2) "in " should not be used in the query instead use array list . 3) for fetching codes(pcode,ccode,dcode etc) use limit 1 for fast exceution of query.