Skip to main content

Posts

Showing posts from March, 2011

Java Class File Verifier

Working in conjunction with the class loader, the class file verifier ensures that loaded class files have a proper internal structure. If the class file verifier discovers a problem with a class file, it throws an exception. Although compliant Java compilers should not generate malformed class files, a Java Virtual Machine canít tell how a particular class file was created. Because a class file is just a sequence of binary data, a virtual machine canít know whether a particular class file was generated by a well-meaning Java compiler or by shady crackers bent on compromising the integrity of the virtual machine. As a consequence, all Java Virtual Machine implementations have a class file verifier that can be invoked on untrusted classes, to make sure the classes are safe to use. One of the security goals that the class file verifier helps achieve is program robustness. If a buggy compiler or savvy cracker generated a class file that contained a method whose bytecodes included an in

How do I configure Tomcat to support remote debugging?

The short answer is to add the following options when the JVM is started: -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n Comments: this 8000 port is just for debugging, user can still access server by 80 port(if set) How do I remotely debug Tomcat using Eclipse? Make sure that you have the sources for the code that you are trying to debug in your IDE. For the libraries and for Tomcat itself you can "attach" the sources to the jar files: open a class file and then click "Attach Source..." button. If you have a servlet or something, set a breakpoint where it is sure to hit on the next request. Go to "Run->Debug Configurations...". Click on "Remote Java Applications", then click "New". Type in the title. Note that port 8000 from the Tomcat instructions. Save and run. Eclipse will connect to the JVM that Tomcat is running under. Wow, that was easy!

jQuery - StackPanels

 <div class="testSubject2">             <h2 id="header_puppies"><a href="#">Puppies</a></h2>             <div id="panel_puppies">               <img src="puppy-1.jpg"><img src="puppy-2.jpg"><img src="puppy-3.jpg"><img src="puppy-4.jpg"><img src="puppy-5.jpg"><img src="puppy-6.jpg">             </div>             <h2 id="header_flowers"><a href="#">Flowers</a></h2>             <div id="panel_flowers">               <img src="flower-1.jpg"><img src="flower-2.jpg"><img src="flower-3.jpg"><!--img src="flower-4.jpg"><img src="flower-5.jpg"><img src="flower-6.jpg"-->             </div>             <h2 id="header_food"><a href=&qu

jQuery - TABS

<div class="testSubject2"> <ul> <li><a href="#tab_puppies2" id="tab_for_puppies2">Puppies</a></li> <li><a href="#tab_flowers2" id="tab_for_flowers2">Flowers</a></li> <li><a href="tab_food.html" id="tab_for_food2">Food</a></li> <li><a href="/jqia2/lengthyTab" id="tab_for_slow2"><span>Slow</span></a></li> </ul> <div id="tab_puppies2"> <img src="puppy-1.jpg"><img src="puppy-2.jpg"><img src="puppy-3.jpg"><img src="puppy-4.jpg"><img src="puppy-5.jpg"><img src="puppy-6.jpg"> </div> <div id="tab_flowers2">

jQuery - autocomplete

<input type="text" class="testSubject" /> $('.testSubject').autocomplete({source:["FX", "Fahrenheit 451", "Family Guy, Volume One, Seasons 1 and 2", "Family Plot", "Fantastic Four (1994), Disc 1", "Funny Girl"]}); $('.testSubject').autocomplete({source:"/jqia2/getMovies"}); //Response ["Final Fantasy: The Spirits Within","Finding Nemo"]

jquery - button

jQuery UI supplies a set of 174 themed icons that can be displayed on buttons. You can show a single icon on the left (the primary icon), or one on the left and one on the right (as a secondary icon). Icons are specified as a class name that identifies the icon. For example, to create a button with an icon that represents a little wrench, we’d use this code: $('#wrenchButton').button({ icons: { primary: 'ui-icon-wrench' } }); If we wanted a star on the left, and a heart on the right, we’d do this: $('#weirdButton').button({ icons: { primary: 'ui-icon-star', secondary: 'ui-icon-heart' } });

jQuery - event bubbling

      <div id="selectionsPane">           <label for="bootChooserControl">Boot style:</label>           <select id="bootChooserControl" name="style"></select>           <label for="colorChooserControl">Color:</label>           <select id="colorChooserControl" name="color" disabled="disabled"></select>           <label for="sizeChooserControl">Size:</label>           <select id="sizeChooserControl" name="size" disabled="disabled"></select>         </div> One capability of the event model that often gets ignored by many a web developer is event bubbling. Page authors frequently focus only on the targets of events, and forget that events will bubble up the DOM tree, where handlers can deal with those events in more general ways than at the target level. If we recognize that

jQuery - usage of Load

 <div id="someContainer"></div> old way to get  the remote server's result:   window.onload = function() {         var xhr;         if (window.ActiveXObject) {           xhr = new ActiveXObject("Microsoft.XMLHTTP");         }         else if (window.XMLHttpRequest) {           xhr = new XMLHttpRequest();         }         else {           throw new Error("Ajax is not supported by this browser");         }         xhr.onreadystatechange = function() {           if (this.readyState == 4) {             if (this.status >= 200 && this.status < 300) {               document.getElementById('someContainer')                 .innerHTML = this.responseText;             }           }         };         xhr.open('GET','someResource');         xhr.send('');       }; new way to get the data:     $(function() {         $('#someContainer').load('someResource');

jQuery - usage of Array

         var anArray=['0ne','two','three'];            $.each(anArray,function(n,value){                 alert(n + 'and '+ value + ' and ' + anArray[n]);            });                     var anObject = {'one':1,'two':2,'three':3};            $.each(anObject,function(name,value){                 alert (name + ' and ' + value + ' and ' + anObject[name]);            }); var index = $.inArray(2,[1,2,3,4,5]); var a1 = [1,2,3,4,5]; var a2 = [5,6,7,8,9]; $.merge(a1,a2); $.unique(array) $.makeArray(object) Converts the passed array-like object into a JavaScript array. Parameters object (Object) The array-like object (such as a NodeList) to be converted. Returns The resulting JavaScript array. $.isArray(o) Returns true if o is a JavaScript array       

jQuery - bind events

 <img id="example" src="example.jpg" onclick="say('BOOM!');" alt="ooooh! ahhhh!"/>   $(function(){         $('#example').bind('mouseover',  function(event) {           say('Crackle!');         }).bind('mouseout', function(event){             say('bye');         })         ;       });

jQuery - attr

 <input type="text" name="mytext" id="mytext" data-custom="custom value"/> get the value of attribute:   var defaultData = $('#mytext').attr('value'); set the value of attribute:   var defaultData = $('#mytext').attr('value','love'); or var defaultData = $('#mytext').attr({'value':'love','title':'my title','disabled':true});

jQuery - about >

A more advanced approach is to use child selectors, in which a parent and its direct child are separated by the right angle bracket character (>), as in p > a This selector matches only links that are direct children of a <p> element. If a link were further embedded, say within a <span> within the <p>, that link would not be selected.

jQuery - trim function

<input type="text" name="mytext" id="mytext"/> the old way to get value and trim         function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } var textvalue = trim(myform.mytext.value); the new way: var textvalue = $.trim(('#mytext').val());

jQuery - radio and checkbox

1. get the checked Radio  <div>         <label for="radioYes">What is your answer?</label>         <input type="radio" name="someRadioGroup" id="radioYes" value="yes" checked="checked"/> Yes         <input type="radio" name="someRadioGroup" id="radioNo" value="no"/> No         <input type="radio" name="someRadioGroup" id="radioMaybe" value="maybe"/> Maybe         <input type="radio" name="someRadioGroup" id="radioConfused" value="confused"/> I dunno       </div>       <div><button type="button" id="testButton"class="green90x24">Which?</button></div>       <div id="result"></div> The old way to get the value:  var checkedValue ;           var elements = document.getElementsB

About nr_hugepages in Linux sysctl.conf file

Hugepages can be allocated using the  /proc/sys/vm/nr_hugepages  entry, or by using the  sysctl command. To view the current setting using the  /proc  entry: # cat /proc/sys/vm/nr_hugepages 0 To view the current setting using the  sysctl  command: # sysctl vm.nr_hugepages vm.nr_hugepages = 0 To set the number of huge pages using  /proc  entry: # echo 5 > /proc/sys/vm/nr_hugepages To set the number of hugepages using  sysctl  : # sysctl -w vm.nr_hugepages=5 vm.nr_hugepages = 5 It may be necessary to reboot to be able to allocate all the hugepages that is needed. This is because hugepages requires large areas of contiguous physical memory. Over time, physical memory may be mapped and allocated to pages, thus the physical memory can become fragmented. If the hugepages are allocated early in the boot process, fragmentation is unlikely to have occurred. It is recommended that the  /etc/sysctl.conf  file should be used to allocate hugepages at boot time

iBATIS vs Hibernate

There are major differences between iBatis and Hibernate but both the solutions work well, given their specific domain. Personally I would suggest you should use iBATIS if: You want to create your own SQL's and are willing to maintain them. your environment is driven by relational data model. you have to work existing and complex schema's. And simply use Hibernate if: Your environment is driven by object model and wants generates SQL automatically. To count there are few differences: iBATIS is: Simpler Faster development time Flixable Much smaller in package size Hibernate: Generates SQL for you which means you don't spend time on SQL Provides much more advance cache Highly scalable Other difference is that iBATIS makes use of SQL which could be database dependent where as Hibernate makes use of HQL which is relatively independent of databases and it is easier to change db in Hibernate. Hibernate maps your Java POJO objects to the Databas

The things I learned from work

Today is the our 7 years wedding anniversary, a very special day for me and my wife. However, I got sick and had to stay at home. In last three days, m y kids got a mild stomach bug, amplified it, multiplied it, enhanced it, and then passed it to me. The project I am working with will be closed in two weeks, and we are going to work with the new version of our product. For me, just finish one project and start another one. I have about 11 years of working experiences, and still, I am struggling for life. In this project, we used JSTL,Jsp,Servlet a lot. And I am crazy of using Jasper Report 1.2, 3.7.6 , 4.0.0 and 4.0.2 for about half a year.  Maybe, I can say I am the expert in using the jasper report and ireport tool.  Boss promised me to work on web service part in the first day I was onboard. It seems this will never come to true. I am regret of missing this valuable opportunity, but, I don't have choice - I am not my boss. I learned a lot about using Ubunto Linux and I go

A widely used standard for documenting normalized data structure

There are various standards for documenting normalized data structures, developed by different organizations as structured formal methods. Generally speaking, it really doesn’t matter which method one uses as long as everyone reading the documents understands it. Part of the documentation will always include a listing of the attributes that make up each entity (also known as the columns that make up each table) and an entity-relationship diagram representing graphically the foreign to primary key connections. A widely used standard is as follows: ■ Primary key columns identified with a hash (#) ■ Foreign key columns identified with a back slash (\) ■ Mandatory columns (those that cannot be left empty) with an asterisk (*) ■ Optional columns with a lowercase “o” Understand Relational Structures 19 The BOOKS tables can now be described as follows: Table BOOKS #* ISBN Primary key, required o Title Optional \* Publisher Foreign key, link to the PUBLISHERS table Table AUTH

The Data Validation function I wrote today

<!-- Date Validation --> // Declaring valid date character, minimum year and maximum year var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){  var i;     for (i = 0; i < s.length; i++){         // Check that current character is number.         var c = s.charAt(i);         if (((c < "0") || (c > "9"))) return false;     }     // All characters are numbers.     return true; } function stripCharsInBag(s, bag){  var i;     var returnString = "";     // Search through string's characters one by one.     // If character is not in bag, append to returnString.     for (i = 0; i < s.length; i++){         var c = s.charAt(i);         if (bag.indexOf(c) == -1) returnString += c;     }     return returnString; } function daysInFebruary (year){  // February has 29 days in any year evenly divisible by four,     // EXCEPT for centurial years which are not also divisible by 400.     re