Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on March 01, 2012 10:17:51
Last update: March 01, 2012 10:17:51
svn does not automatically substitute keywords like $Id$ . To enable keyword substitution, you have to enable it with propset :
$ svn propset svn:keywords "Id" README.txt
To enable keyword substitution for all files:
$ svn propset -R svn:keywords "Id" .
The above examples enabled substitution for $Id$ only. Each keyword must be explicitly listed to be substituted. The keywords recognized by svn are:
svn:keywords - Keywords to be expanded. Val...
To list properties on a file:
$ svn proplist README.txt
Properties on 'README...
To see the svn:keywords for a file:
$ svn propget svn:keywords README.txt
Id
Created by Dr. Xi on August 11, 2007 15:56:47
Last update: July 19, 2011 08:15:55
Here's a list of common TCP ports. You can find a more complete list here: http://www.gasmi.net/docs/tcp.html . Port Number Service Description 21 FTP File Transfer Protocol 22 SSH Secure Shell 23 Telnet Telnet remote login 25 SMTP Simple Mail Transfer Protocol 70 gopher Gopher 79 finger Finger 80 HTTP Hyper Text Transfer Protocol (WWW) 88 Kerberos Kerberos authentication 94 tivoli Tivoli Object Dispatcher 110 pop3 Post Office Protocol Version 3 123 ntp Network Time Protocol 137 netbios NetBIOS Name Service 138 netbios NetBIOS Datagram 139 netbios NetBIOS Session 143 imap Internet Message Access Protocol 161 snmp Simple Network Management Protocol 162 snmptrap SNMP trap 194 irc Internet Relay Chat Protocol 389 ldap Lightweight Directory Access Protocol 443 https Secure HTTP 445 SMB MS Server Message...
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 August 13, 2007 20:27:11
Last update: July 13, 2011 16:20:28
Sample code:
import java.util.*;
public class TestArrayL...
If you use iterators, the for loop is equivalent to:
for (Iterator<String> i = l.iterator(); i.hasNext(...
The simplified for loop (or, for-each loop) can be used for arrays or objects that implement java.lang.Iterable .
Note that by using generics, there's not need to down cast. But new for loop syntax doesn't down cast either. If List<String> is changed tp List<Object> , the code doesn't compile.
Created by Dr. Xi on July 11, 2011 12:24:10
Last update: July 11, 2011 12:25:44
This code snippet
import java.util.*;
public class UncheckedCast ...
fails with a compilation error and a warning:
$ javac -Xlint:unchecked UncheckedCast.java
Unc...
Because List<String> is not a reifiable type, the Java Runtime does not have enough information to verify the type or do the type casting. This is fixed by changing List<String> to List<?> (or to the raw type List ):
public static void main(String[] args) {
Ob...
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 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 Dr. Xi on April 28, 2011 11:37:23
Last update: April 28, 2011 11:37:23
The Future interface represents the result of an asynchronous computation. Future provides methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. You call one of the three submit methods of ExecutorService to get a Future object:
<T> Future<T> submit(Callable<T> task)
<T> Future<T> submit(Runnable task, T result)
Future<?> submit(Runnable task)
Use the first two to retrieve usable results from the computation. The third option returns a Future that returns null upon successful completion. It is used to simply wait for the task to complete, much like Thread.join() .
import java.util.concurrent.Future;
import java...
Created by Dr. Xi on April 19, 2011 16:02:55
Last update: April 19, 2011 16:03:24
Method Description object.__getattr__(self,name) Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self ). object.__setattr__(self,name,value) Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value in the instance dictionary). If __setattr__() wants to assign to an instance attribute, it should not simply execute self.name = value — this would cause a recursive call to itself. Instead, for new style classes, it should call the base class method with the same name, for example, object.__setattr__(self, name, value) . For classic classes, it should insert the value in the dictionary of instance attributes, e.g., self.__dict__ [name] =...
Created by Dr. Xi on April 19, 2011 16:01:39
Last update: April 19, 2011 16:01:39
This note relates to Python 2.x. A Python class is old-style by default, unless it has another new style class or the "top level" class object as its parent. The sure way to tell that an object is an instance of a new style class is to use the function type , type(x) returns <type 'instance'> for an old-style class, but it returns <class 'ClassType.X'> for a new-style class.
Class definition:
class A: # old style class
def __init__(sel...
Test session:
>>> A
<class ClassType.A at 0x7f36ae442fb0>
...