Recent Notes
Displaying notes 71 - 80
Created by Dr. Xi on June 11, 2010 19:04:18
Last update: June 11, 2010 19:06:35
The caret ^ is DOS command line escape character. Example 1: echo < and > as is, not interpreting them as input/output redirect. @rem sign an XML file. Requires Java class utils.xmlsig.SignXMLFile. @echo off if "%2" == "" goto usage java -Xms256m -Xmx512m utils.xmlsig.SignXMLFile %1 %2 goto end :usage echo Usage: %0 ^<inputFile^> ^<outputFile^> echo. :end Example 2: treat & literally, not as the special character to combine two commands. @rem search "dos command line" in Google. curl http://www.google.com/search?hl=en^&q=dos+command+line -o google.html Add switch -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" to make curl look like Firefox.
Created by Dr. Xi on June 03, 2010 22:43:43
Last update: June 20, 2010 14:13:05
Using the Sun BASE64Encoder : import java.io.*; import sun.misc.BASE64Encoder; public class EncodeFileWithBase64 { public static void main(String[] args) throws Exception { if (args.length < 2) { System.out.println("Usage: java EncodeFileWithBASE64 <inputFile> <outputFile>"); return; } String inputFile = args[0]; String outputFile = args[1]; BASE64Encoder encoder = new BASE64Encoder(); encoder.encode( new FileInputStream(inputFile), new FileOutputStream(outputFile) ); } } However, the Sun encoder is awfully slow. The Apache encoder is a lot faster. Here's the code with Apache encoder: import java.io.*; import org.apache.commons.codec.binary.Base64OutputStream; public class EncodeBase64WithApache { public static void main(String[] args) throws Exception { if (args.length < 2) { System.out.println("Usage: java EncodeBase64WithApache <inputFile> <outputFile>"); return; } int BUFFER_SIZE = 4096; byte[] buffer = new byte[BUFFER_SIZE]; InputStream input = new FileInputStream(args[0]); OutputStream output = new Base64OutputStream(new FileOutputStream(args[1])); int n = ...
Created by Dr. Xi on June 03, 2010 18:29:59
Last update: June 03, 2010 18:31:49
Generate a private key and store it in the keystore. The keystore file theKeyStore.jks will be created if it does not exist. The default keystore file is $HOME/.keystore if the -keystore option is not given. keytool -genkey -alias myjavakey -keyalg RSA -keystore theKeyStore.jks Generate a private key and self-sign for 10 years. keytool -genkey -alias myjavakey -keyalg RSA -validity 3650 List keys in the keystore. # short list keytool -list -keystore theKeyStore.jks # long list keytool -list -v -keystore theKeyStore.jks # show one key keytool -list -v -keystore theKeyStore.jks -alias myjavakey Create a certificate signing request (CSR). keytool -certreq -alias myjavakey -keystore theKeyStore.jks -file myjavakey.csr It seems that the Java keytool utility can't sign third party certificate signing requests (CSRs). We can use openssl to ...
Created by nogeek on June 03, 2010 16:06:05
By default, JBOSS server binds only to localhost. Use the -b option to bind to all available IP addresses: sh bin/run.sh -b 0.0.0.0
Created by Dr. Xi on June 01, 2010 16:44:12
Last update: June 01, 2010 16:45:52
I installed JDK 1.6 under C:\jdk1.6.0_20 and unpacked Eclipse GALILEO in C:\local\eclipse . When I launched Eclipse with eclipse.exe , it simply displayed a splash page and shutdown. Running eclipsec.exe displayed some vague errors: C:\local\eclipse>eclipsec Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries Turning on debug: C:\local\eclipse>eclipsec -debug Start VM: -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -XX:MaxPermSize=256m -Djava.class.path=C:\local\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201. R35x_v20090715.jar -os win32 -ws win32 -arch x86 -showsplash C:\local\eclipse\\plugins\org.eclipse.platform_3.3.202.v201002111343\splash.bmp -launcher C:\local\eclipse\eclipsec.exe -name Eclipsec --launcher.library C:\local\eclipse\plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519\eclipse_1206.dll -startup C:\local\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v200 90715.jar -product org.eclipse.epp.package.jee.product -debug -vm C:\jdk1.6.0_20\bin\client\jvm.dll -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -XX:MaxPermSize=256m -Djava.class.path=C:\local\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201. R35x_v20090715.jar Error occurred during initialization of VM Unable to load native library: Can't find dependent libraries The Solution: add -vm option to eclipse.ini : -startup plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519 -product org.eclipse.epp.package.jee.product --launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform ...
Created by nogeek on June 01, 2010 14:34:12
Test with curl and default Apache doc. C:\>curl --dump-header - http://localhost HTTP/1.1 200 OK Date: Tue, 01 Jun 2010 14:24:44 GMT Server: Apache/2.2.15 (Win32) Last-Modified: Sat, 20 Nov 2004 19:16:26 GMT ETag: "1000000023832-2c-3e95575ae9680" Accept-Ranges: bytes Content-Length: 44 Content-Type: text/html <html><body><h1>It works!</h1></body></html> C:\>curl -H Range:bytes=16-24 --dump-header - http://localhost HTTP/1.1 206 Partial Content Date: Tue, 01 Jun 2010 14:27:19 GMT Server: Apache/2.2.15 (Win32) Last-Modified: Sat, 20 Nov 2004 19:16:26 GMT ETag: "1000000023832-2c-3e95575ae9680" Accept-Ranges: bytes Content-Length: 9 Content-Range: bytes 16-24/44 Content-Type: text/html It works! C:\>curl -H Range:bytes=16- --dump-header - http://localhost HTTP/1.1 206 Partial Content Date: Tue, 01 Jun 2010 14:27:28 GMT Server: Apache/2.2.15 (Win32) Last-Modified: Sat, 20 Nov 2004 19:16:26 GMT ETag: "1000000023832-2c-3e95575ae9680" Accept-Ranges: bytes Content-Length: 28 Content-Range: bytes 16-43/44 Content-Type: text/html It works!</h1></body></html> C:\>
Created by woolf on May 27, 2010 21:54:10
Last update: May 27, 2010 21:55:16
Turn off MS-DOS style path warnings with cygwin utilities. C:\MyWorks>diff C:\local\utils\MyClass.class C:\FileStore\phase1\MyClass.class cygwin warning: MS-DOS style path detected: C:\local\utils\MyClass.class Preferred POSIX equivalent is: /cygdrive/c/local/utils/MyClass.class CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames C:\MyWorks>set cygwin=nodosfilewarning C:\MyWorks>diff C:\local\utils\MyClass.class C:\FileStore\phase1\MyClass.class C:\MyWorks>
Created by Dr. Xi on May 23, 2010 01:16:57
open(IMG, "Sample.jpg") or die "Can't open file: $!"; binmode IMG; binmode STDOUT; while (read(IMG, $buff, 8 * 2 ** 10)) { print $buff; } close IMG;
Created by Dr. Xi on May 15, 2010 19:53:27
Last update: May 15, 2010 19:54:37
Use the locale module. >>> a = 1234.5678 >>> import locale >>> locale.setlocale(locale.LC_ALL, '') # set default locale 'English_United States.1252' >>> locale.currency(a) '$1234.57' >>> locale.currency(a, grouping=True) '$1,234.57' >>>
Created by James on May 07, 2010 04:13:14
Last update: May 07, 2010 04:35:03
It seems that the key to aligning a checkbox with its label lies in the line-height property of the label. This simple HTML snippet aligns well: <!DOCTYPE HTML> <html> <head> <style type="text/css"> body { margin: 10px; font-family: sans-serif; } input.checkbox { clear: left; float: left; } label.checkbox { display: block; float: none; clear: none; margin-left: 20px; padding-bottom: 12px; } </style> </head> <body> <form id="dataform"> <input id="checkbox1" name="cb1" value="y" type="checkbox" class="checkbox"> <label for="checkbox1" class="checkbox">Checkbox 1</label> <input id="checkbox2" name="cb2" value="y" type="checkbox" class="checkbox"> <label for="checkbox2" class="checkbox">Checkbox 2</label> <input id="checkbox3" name="cb3" value="y" type="checkbox" class="checkbox"> <label for="checkbox3" class="checkbox">Checkbox 3</label> </form> </body> </html> which is rendered like this: Change the font size of the label to 12px throws off the alignment: label.checkbox { font-size: 12px; display: block; float: none; clear: none; ...