Notes by Dr. Xi
Displaying notes 171 - 180
Created by Dr. Xi on August 03, 2010 16:23:55
Last update: October 22, 2010 15:35:20
According to Java documentation:
The Java compiler and other Java tools can only process files which contain Latin-1 and/or Unicode-encoded (\udddd notation) characters.
This utility converts a utf-8 encoded file to ascii with unicode escape strings for non-ascii characters.
import java.io.*;
/**
* Reads file in U...
It is equivalent to:
native2ascii -encoding utf-8
using the standard Java native2ascii utility.
Created by Dr. Xi on October 20, 2010 15:53:47
Last update: October 20, 2010 15:54:32
I got this exception while doing scp with Ant:
build.xml:52: com.jcraft.jsch.JSchException: rejec...
The solution is to add trust="true" to the scp task:
<scp file="${dist.dir}/${war.file}"
todir...
Created by Dr. Xi on September 11, 2008 23:06:18
Last update: October 06, 2010 03:16:13
Firefox and Google chrome has native support for the trim function for a String. IE (as of IE 8.0) does not provide a trim function for String. Using the JavaScript Executor , if you execute:
'abcd '.trim
you get:
function trim() { [native code] }
in Firefox and Google Chrome. But you get nothing in IE. If you try to execute the trim method on a String:
'abcd '.trim()
you get this in IE:
TypeError: Object doesn't support this property or...
In order to have the trim function across all browsers, define this function:
if(typeof String.prototype.trim !== 'function') {
...
Or, if you use jQuery, you can use $.trim()
Created by Dr. Xi on September 29, 2010 16:28:52
Last update: September 29, 2010 16:28:52
Use the replace task with replacefilter to replace multiple tokens:
<replace file="${build.dir}/WEB-INF/jdbc.propertie...
Created by Dr. Xi on September 17, 2010 21:29:47
Last update: September 17, 2010 21:31:43
With JBoss (Tomcat?), the servlet container always appends the default charset ISO-8859-1 to the Content-Type header of a JSP response. For example, if you are using JSP to render PDF and put the following declaration at the top of the JSP:
<%@ page contentType="application/pdf"%> These would be the headers in the HTTP response (notice that charset=ISO-8859-1 was appended to Content-Type ): HTTP/1.1 200 OK Server: Apache-Coyote/1.1 X-... And the output would be truncated a few bytes before non-ASCII characters were encountered, without any error messages ! Maybe you don't intend to output binary files with JSP, but still your response would be truncated without warning if the page happens to contain any non-ASCII characters (when the charset is the default charset=ISO-8859-1 ). However, if you...
Created by Dr. Xi on September 10, 2010 22:53:42
Last update: September 10, 2010 22:54:06
The sort operation for a Python list sorts a list in place . It takes three optional arguments to control the comparisons:
s.sort([cmp[, key[, reverse]]]) cmp specifies a custom comparison function of two arguments (list items) which should return a negative, zero or positive number depending on whether the first argument is considered smaller than, equal to, or larger than the second argument: cmp=lambda x,y: cmp(x.lower(), y.lower()) . The default value is None . key specifies a function of one argument that is used to extract a comparison key from each list element: key=str.lower . The default value is None . reverse is a boolean value. If set to True , then the list elements are sorted as if each comparison were reversed. Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC...
Created by Dr. Xi on September 10, 2010 20:58:34
Last update: September 10, 2010 20:58:34
From Python docs :
string.find(s, sub[, start[, end]])
Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end] . Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
string.index(s, sub[, start[, end]])
Like find() but raise ValueError when the substring sub is not found.
>>> s = 'abcd1234'
>>> s.index('123')
4
>...
Created by Dr. Xi on September 10, 2010 20:52:32
Last update: September 10, 2010 20:52:32
Unlike PHP, in Python an array index must be integer (string is an array of characters):
>>> s
'abcd12345'
>>> s[1]
'b'
>>> s['...
Created by Dr. Xi on September 10, 2010 16:30:16
Last update: September 10, 2010 16:30:16
Perl uses the pop function to remove an item from the end of an array, and the shift function to remove an item from the beginning of an array. Python does not have a shift function, but its pop function takes a optional parameter. To remove an item from the beginning of a list , simply pop(0) .
>>> a = []
>>> a.append(1)
>>> a.append(2)
...
Created by Dr. Xi on August 30, 2010 20:17:22
Last update: August 30, 2010 20:17:41
Characters \/:*?"<>| are forbidden in Windows file names. For Python, the effect of using a forbidden character in the file name is undetermined.
In the following session a file named mytest can be seen from the Windows Explorer, which contains 0 bytes - as confirmed by the read back in the session. But if you open the file with the invalid file name used to create the file (i.e., mytest: 1.txt ), you get the original contents.
C:\>python
Python 2.7 (r27:82525, Jul 4 2010, ...