Recent Notes

Displaying keyword search results 1 - 11
Created by zhidao on April 25, 2012 14:56:38    Last update: April 25, 2012 14:56:38
Lacking better alternatives, this is how I render a global validation error: <spring:bind path="changePasswordForm"> <c:if ... <form:errors> without path attribute seems to work too: <form:errors cssClass="ui-error"/>
Created by Dr. Xi on March 14, 2012 14:23:14    Last update: March 14, 2012 14:23:14
If forgotPasswordForm.error is a String and not null, you cannot test the error condition with: <!-- This does not work! --> <c:if test="${forg... You have to use "not empty": <c:if test="${not empty forgotPasswordForm.error}"...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by jinx on May 03, 2011 11:43:26    Last update: May 03, 2011 11:43:26
The PHP function strval returns the string value of a variable. It does the same thing as casting a variable to string, or automatic conversion where string is expected. Conversion rules: Type String Value Boolean TRUE '1' Boolean FALSE '' (empty string) integer of float string representing the number Array The string 'Array' Object Result of __toString() if defined, error otherwise Resource 'Resource id #n' , where n is a number assigned to the resource. NULL '' (empty string) Example: <?php set_error_handler(function($errno, $errst... Results: bool(true) --------------------- strval: '1'...
Created by jinx on April 25, 2011 12:43:40    Last update: April 25, 2011 12:43:40
Use the PHP function method_exists to check if the class or object has a certain method. It returns TRUE if the method exists (even when the value of the property is NULL), FALSE if the method does not exist. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has method f1: bool(true) Object $a has... Also note that C++-like method overloading does not exist in PHP. Thus there's no ambiguity about which version of the method exists, i.e., with no argument, with one argument... etc. The following code generates Fatal error: <?php class A { var $p = 'A property'; ...
Created by jinx on April 25, 2011 11:50:09    Last update: April 25, 2011 11:51:53
Use the PHP function property_exists to check if the class or object has a certain property. It returns TRUE if the property exists (even when the value of the property is NULL), FALSE if the property does not exist, or NULL in case of an error. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has property $p: bool(false) Class A ha...
Created by freyo on April 18, 2011 15:08:21    Last update: April 18, 2011 15:12:20
Generate android project $ ~/android-sdk-linux_86/tools/android create proj... Create XML file res/xml/books.xml : <?xml version="1.0"?> <catalog> <book id=... Edit layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <Lin... Edit code ( src/com/android/xmlres/XMLResource.java ): package com.android.xmlres; import java.io.... Change activity label from app_name to booklist ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Add value for string resource ( res/values/string.xml ): <?xml version="1.0" encoding="utf-8"?> <resourc... Deploy and test: ant install
Created by alfa on April 08, 2011 12:33:08    Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen. import java.io.*; import java.awt.*; import ...
Created by Dr. Xi on March 29, 2011 16:06:57    Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed. import java.io.InputStream; import java.io.Outp... Retrieve and import the a certificate: E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by Dr. Xi on February 09, 2009 23:14:15    Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...
Created by Dr. Xi on December 12, 2007 20:30:01    Last update: December 12, 2007 20:32:23
This is a script to tail a log file through the web browser. It uses AJAX, apache web server, mod_python, UNIX utilities tail (requires the --lines switch) and wc . The log file may reside on the web server or any other host accessible from the web server through SSH. Although it's written in python, it should be easy to port to other languages such as Perl. Apache httpd.conf : LoadModule python_module modules/mod_python.so ... Python script: import time, os from os.path import basename ...