Recent Notes
Displaying keyword search results 1 - 10
Created by freyo on February 06, 2013 21:10:47
Last update: February 06, 2013 21:12:18
I have an old Samung phone to be used as a toy. After restoring back to factory image and power on, I was stuck at the activate service screen. Unfortunately, the four corner magic touch did not work. So I did quite a bit of digging and this is what worked on my Samsung Continuum: Press emergency call button, then at the dialer, press * # 8 3 7 8 6 6 3 3 , press the Home key From the home screen, tap phone icon, Dial * # 2 2 7 4 5 9 2 7 Enter SPC code: ______ displays tap in white box to show virtual keyboard, enter 6 digit code (default: 000000), tap OK Select “Hidden menu Enable”, tap OK From...
Created by Fang on March 06, 2012 12:24:53
Last update: March 06, 2012 12:24:53
Validation groups can be used to control which rules validation rules to run. A validation group can be identified by any Java interface (not class!). Multiple validation groups may be specified when validating.
In this example, I added a validation group named MyValidationGroup ( src/main/java/com/example/MyValidationGroup.java in Maven project):
package com.example;
public interface MyVal...
and added a @Size rule for a person's name, because my database can only store up to 15 characters for a person's name:
package com.example;
import javax.validatio...
Now validate Person with a JUnit test ( src/test/java/com/example/TestPersonWithGroup.java in Maven project):
package com.example;
import java.util.Set;
...
Test with " mvn clean test ". The rules where groups is not specified, which belong to the javax.validation.groups.Default group, are not executed with these tests.
Created by Fang on January 04, 2012 09:54:05
Last update: January 04, 2012 09:54:05
There are two ways to validate a form with JSF: jsf validation on the page with <f:validate...> tags (for example: <f:validateLength> , <f:validateRegex> , etc.), or JSR303 bean validation. This note is about how to customize messages for JSR303 bean validation. The validation message is specified in the message attribute for each validation annotation type. The mesage attribute is not a literal string, but a string that is interpolated in various ways. For example, the default validation message for AssertFalse is {javax.validation.constraints.AssertFalse.message} , which is replaced with the corresponding string in ValidationMessages.properties (or ValidationMessages_tr.properties , ValidationMessages_es.properties , depending on the locale). This is the contents of ValidationMessages.properties in the hibernate validator reference implementation:
javax.validation.constraints.AssertFalse.message =... To customize the messages, just provide the new value in...
Created by magnum on September 23, 2011 16:06:02
Last update: September 28, 2011 09:29:53
This procedure works for xl2tpd .
Edit L2TP configuration file /etc/xl2tpd/xl2tpd.conf :
; Sample l2tpd.conf
;
[global]
; listen...
Edit PPP options file for L2TP /etc/ppp/options.xl2tpd :
ipcp-accept-local
ipcp-accept-remote
ms-dns ...
Edit PPP authentication file /etc/ppp/chap-secrets :
# Secrets for authentication using CHAP
# serve...
Start the server:
# /etc/init.d/xl2tpd start
Monitor the log:
# less /var/log/messages
Created by freyo on May 13, 2011 15:45:29
Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator.
build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<man...
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<Lin...
res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<res...
src/com/android/xmltool/DumpXml.java
package com.android.xmltool;
import java.ut...
Screenshot
Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by alfa on July 15, 2011 13:25:45
Last update: July 15, 2011 13:25:45
Read the whole contents of a file into a String. It's better to read the whole file as bytes and convert to String than to read the file line by line and concatenate the lines.
String getFileContents(String fileName) throws...
Using java.nio :
import java.io.FileInputStream;
import java...
Created by alfa on June 02, 2011 15:26:37
Last update: June 02, 2011 15:26:37
While doing some Java reflection code, I noticed the method Class.isSynthetic() , which the JavaDoc says returns " true if and only if this class is a synthetic class as defined by the Java Language Specification". However, there's no definition of "synthetic class" in the JLS ! The only thing that I can find that remotely resembles a definition is in the JVM spec , where it defines the synthetic attribute : "The Synthetic attribute is a fixed-length attribute in the attributes table of ClassFile (§4.1), field_info (§4.5), and method_info (§4.6) structures. A class member that does not appear in the source code must be marked using a Synthetic attribute." By this definition, a default constructor, which does not appear in the source code, should...
Created by alfa on June 02, 2011 13:04:18
Last update: June 02, 2011 13:04:18
Some javap usage examples.
Start from HelloWorld.java :
@Deprecated
public class HelloWorld {
pu...
javap -c HelloWorld outputs:
Compiled from "HelloWorld.java"
public class He...
javap -v HelloWorld outputs ( -v for verbose mode):
Compiled from "HelloWorld.java"
public class He...
The output consists of:
" Compiled from... " header
Class attributes. For the HelloWorld example, there are two: SourceFile and Deprecated .
Minor and major class file version
Constant pool
Disassembled code
LineNumberTable for debugging purposes.
javap by default only prints package/protected/public members. To display all members including private, use the -p switch.
javap -v -p HelloWorld
Created by meiu on March 31, 2011 19:54:05
Last update: March 31, 2011 19:54:05
With StringBuffer/StringBuilder:
public class ReverseString {
private static...
Without StringBuffer/StringBuilder:
public class ReverseString {
private static...
Created by Dr. Xi on March 28, 2011 20:51:30
Last update: March 28, 2011 20:53:46
HTTP basic authentication is just Base64 encoded user name and password passed in as the Authorization header. So the following code works:
// encode user name and password
String credent...
However, since JDK 1.2, there's a more Java friendly way:
Authenticator.setDefault(new Authenticator() {
...
Test code:
import java.net.*;
import java.io.*;
pub...