Recent Notes
Displaying keyword search results 51 - 60
Created by Dr. Xi on October 16, 2008 20:45:40
Last update: March 28, 2011 20:23:22
Java's built-in classes are way too complex/flexible for a simple protocol like HTTP. This is a wrapper to simplify HTTP GET and POST.
import java.io.*;
import java.net.*;
imp...
A simple test:
import java.io.*;
import java.util.*;
...
Created by Dr. Xi on March 02, 2011 11:39:18
Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code:
import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by mak on March 04, 2011 14:17:32
Last update: March 04, 2011 14:18:35
To create a zipfile in python:
Code:
#!/usr/local/bin/python
import zipfile
#...
Test
unzip -l test.zip
Archive: test.zip
Lengt...
To read a zipfile in python:
Code:
#!/usr/local/bin/python
import zipfile
#...
Created by James on March 03, 2011 21:48:52
Last update: March 03, 2011 21:48:52
Just another way to left zero-pad a string.
function zeroPad(s, length) {
if (s.length ...
Created by woolf on February 10, 2011 13:16:34
Last update: February 10, 2011 13:16:49
%PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of " str1 " in the expanded result with " str2 ". " str2 " can be the empty string to effectively delete all occurrences of " str1 " from the expanded output. " str1 " can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first occurrence of the remaining portion of str1. %PATH:~10,5% would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value. If either number (offset or length) is negative,...
Created by nogeek on February 08, 2011 13:46:18
Last update: February 08, 2011 13:46:18
Simple Java code that does XSLT on an XML file. The transform results go to STDOUT.
import java.io.*;
import javax.xml.parsers....
Created by Dr. Xi on October 07, 2010 19:20:55
Last update: January 11, 2011 19:59:17
Like the string trim function, Firefox provides a native implementation for array map, IE doesn't. So we have to create our own map function for Array :
if(typeof Array.prototype.map !== 'function') {
...
Test page:
<html>
<head>
<title>Array Map</...
Created by Dr. Xi on November 29, 2010 13:08:05
Last update: November 30, 2010 08:51:34
This sample code sets up a server socket on a specified address and port. I use it to test port binding conflicts.
import java.net.*;
public class SocketBind ...
Note: " netstat -ano " also gives you information on active TCP connections, including listening ports. But there are cases where netstat reports nothing and bind still fails.
Created by voodoo on November 24, 2010 23:43:29
Last update: November 24, 2010 23:43:29
Two of the three PreparedStatement.setBinaryStream methods are not implemented as of version 9.0-801 of the PostgreSQL JDBC driver.
Test program:
import java.io.*;
import java.sql.*;
pub...
Also note that setBinaryStream only works on a bytea column.
Created by nogeek on November 04, 2010 20:00:15
Last update: November 05, 2010 14:38:43
Following are some bugs in the Xalan jar shipped with JBoss 5.1.0 GA and JBoss 6.0. The Xalan jar file is located in jboss-5.1.0.GA/lib/endorsed ( %JBOSS_HOME%/common/lib for JBoss 6.0).
Test xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
...
Test xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
XSLT Java code:
import org.w3c.dom.*;
import javax.xml.parsers....
DateUtil.java
import java.util.Date;
public class DateUti...
XSLT output:
Transformer Factory class: class org.apache.xalan....
Apparently, the output is wrong. The string "A test event" should not have been displayed.