Recent Notes
Displaying keyword search results 1 - 10
Created by Fang on November 10, 2011 09:26:12
Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines!
<?xml version="1.0" encoding="UTF-8"?>
<xsd:sch...
Created by Dr. Xi on July 14, 2011 09:28:57
Last update: July 14, 2011 09:28:57
Java arrays are fixed size, so you have to make a new array with smaller size and copy the data.
For JDK6 and above:
// import java.util.Arrays;
newArray = Arrays.c...
Before that (using Object as example):
Object[] newArray = new Object [newSize] ;
Syst...
Created by Dr. Xi on June 22, 2011 15:15:15
Last update: June 22, 2011 15:15:15
There's no such thing as an immutable byte array in Java. What we are trying to achieve here is to protect the byte array inside the object from which it is being returned. We want to caller to have the contents of the byte array, but not be able to change the contents inside the object. The trick is to return a copy instead of the internal reference:
public class ReturnByteArray {
public stati...
Created by freyo on May 23, 2011 12:07:59
Last update: May 23, 2011 12:09:42
You can construct a java.security.cert.Certificate object from a string or byte array. Byte array is cleaner because for string you also have to know the character encoding.
// import java.security.cert.CertificateFactory;
...
If the certificate string is encoded in "UTF-8", the ByteArrayInputStream should be created with:
new ByteArrayInputStream(certString.getBytes("UTF-...
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 29, 2011 13:43:13
Last update: April 29, 2011 13:44:34
List of functions testing variable type:
Function Description
is_bool Finds out whether a variable is a boolean
is_double Alias of is_float()
is_float Finds whether the type of a variable is float
is_int Find whether the type of a variable is integer
is_integer Alias of is_int()
is_long Alias of is_int()
is_null Finds whether a variable is NULL
is_numeric Finds whether a variable is a number or a numeric string
is_object Finds whether a variable is an object
is_real Alias of is_float()
is_scalar Finds whether a variable is a scalar
is_string Find whether the type of a variable is string
Test code:
<?php
class A {
}
$a = ar...
Output:
var_dump: int(1)
-------------------------
i...
Created by alfa on April 11, 2011 21:17:11
Last update: April 11, 2011 21:17:11
Some methods to create an array in Java:
With literal initialization.
// array of strings
String[] dogs = { "Chihuah...
With array constructor (array allocated by not the elements).
// create a byte array
byte[] buffer = new byte...
Anonymous array to be used as a parameter in method invocation
String.format("Hello %s, %s, %s!", new Object[] { ...
Created by jinx on April 10, 2011 20:56:06
Last update: April 10, 2011 20:59:33
The PHP manual says that the count function also counts the properties for an object. Not true. Using count on an object reference always returns 1. In order to count properties, you have to cast the object to an array, which is equivalent to calling get_object_vars on the object. When you cast an object to an array, count is still counting the number of elements in an array!
<?php
class Vegetable {
var $name;
...
Outputs:
array(3) {
["name"]=>
string(7) "Cabbage...
Created by jinx on April 05, 2011 08:59:29
Last update: April 05, 2011 08:59:29
<?php
$useragent = $_SERVER ['HTTP_USER_AGE...
PHP also provides get_browser function, which returns an object or array. But that requires browscap configuration which locates the browscap.ini file.
Created by Dr. Xi on December 25, 2009 00:13:19
Last update: December 25, 2009 00:13:19
Use the in operator to find out if a Python array contains an object:
>>> a = [1, 2, 3]
>>> 1 in a
True
>>> 3 i...