Recent Notes

Displaying keyword search results 1 - 9
Created by magnum on October 22, 2012 20:03:05    Last update: October 22, 2012 20:03:05
First, the test command that sleeps random number of seconds ( sleeper.sh ): #!/bin/bash stime=$[$RANDOM % 20] sleep $sti... As comparison, synchronous pipe code: #include <sys/wait.h> #include <stdio.h> #in... Asynchronous pipe code: #include <sys/wait.h> #include <stdio.h> #in...
Created by jinx on May 16, 2011 20:21:38    Last update: May 16, 2011 20:21:38
PHP compares two arrays element for element for equality. Two arrays are considered equal when they have the same number of elements, and for each element key and value both match. Test code: <?php $cmp = array( array(array(1), array(1... Outputs: array(1) { [0]=> int(1) } array(2)...
Created by Dr. Xi on April 20, 2011 21:44:15    Last update: May 02, 2011 20:56:58
The String.format() method provides versatile formatting capabilities. This tutorial tries to present these capabilities in a accessible manner. The format string A format string can contain zero, one, or more format specifiers . The general form of a format specifier is: %[argument_index$] [flags] [width] [.precision]co... where things in square brackets are optional, and conversion is a character indicating the conversion to be applied to the corresponding variable value. The only required characters in the format specifier is the percent sign % and the conversion character. A simple example: public static void simpleFormat() { System.out... The Argument index The argument index is specified by a number, terminated by the dollar sign $ . The same argument may be repeated multiple times in a format string. Unindexed...
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 Dr. Xi on April 27, 2011 15:58:31    Last update: April 27, 2011 20:05:22
From JavaDoc : java.util.concurrent.locks.ReentrantLock is a reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities. The extended capabilities are: tryLock() : acquire the lock if possible, otherwise immediately return false. tryLock(long timeout, TimeUnit unit) : acquire the lock within the timeout, return false after timeout. lockInterruptibly() : try to acquire the lock and enter wait state, but can be interrupted by other threads and exit waiting. The following shows how java.util.concurrent.locks.ReentrantLock can be used. Start two threads to manipulate the same counter, one incrementing, the other decrementing. Since the counter is incremented and decremented the same number of times, in the end, it should be 0. Without locking,...
Created by alfa on April 11, 2011 21:40:51    Last update: April 11, 2011 21:40:51
Integer.bitCount counts the number of one-bits in the two's complement binary representation of the specified int value. Example code: public class CountOnes { public static void... For long , there's Long.bitCount()
Created by Fang on August 10, 2010 21:37:36    Last update: October 25, 2010 20:18:47
The tags <fmt:formatNumber> Format a numeric value as number , currency or percentage - controlled by the type attribute (defaults to number if type is missing). Syntax: <fmt:formatNumber value="numericValue" [type="... Attributes: Name Dynamic? Type Description value true String or Number Numeric value to be formatted. type true String Specifies whether the value is to be formatted as number, currency, or percentage. pattern true String Custom formatting pattern, must follow the pattern syntax specified by the class java.text.DecimalFormat . currencyCode true String ISO 4217 currency code. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. currencySymbol true String Currency symbol. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. It is used only when currencyCode is...
Created by Fang on April 03, 2010 20:21:15    Last update: April 04, 2010 03:30:22
The tags <c:out> The <c:out> tag evaluates an expression and outputs the result on the page. The syntax is: <c:out value="value" [escapeXml="{true|false}"] ... where escapeXml defaults to true and default defaults to empty string "". <c:out value="${expr}" escapeXml="false"/> is equivalent to ${expr} . If a variable is set in multiple scopes, the lower scope wins. In the following example code, attribute1 is set in request, session, and application scopes; attribute2 is set in session and application scopes; attribute3 is set in the application scope. The results are: <c:out value="${attribute1}"/> : Attribute1 request scope <c:out value="${attribute2}"/> : Attribute2 session scope <c:out value="${attribute3}"/> : Attribute3 application scope To access values in higher scopes, you have to specify the scope explicitly, like this: <c:out value="${sessionScope.attribute1}"/> : Attribute1 session...
Created by Dr. Xi on October 18, 2008 02:59:57    Last update: October 18, 2008 02:59:57
Use java.sql.PreparedStatement to insert a BLOB or CLOB field: void setAsciiStream(int parameterIndex, InputStream x, int length) Sets the designated parameter to the given input stream, which will have the specified number of bytes. void setBinaryStream(int parameterIndex, InputStream x, int length) Sets the designated parameter to the given input stream, which will have the specified number of bytes. void setCharacterStream(int parameterIndex, Reader reader, int length) Sets the designated parameter to the given Reader object, which is the given number of characters long. void setClob(int i, Clob x) Sets the designated parameter to the given Clob object. void setBlob(int i, Blob x) Sets the designated parameter to the given Blob object. Example code: PreparedStatement pstmt = con.prepareStatement...