Recent Notes

Displaying keyword search results 41 - 50
Created by freyo on April 06, 2011 14:39:10    Last update: April 06, 2011 14:39:10
Use the x509 command to print certificate information. openssl x509 -noout -text -in cert.pem Optionally with MD5 or SHA1 checksum: openssl x509 -noout -text -in cert.pem -fingerprin...
Created by Dr. Xi on March 29, 2011 16:06:57    Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed. import java.io.InputStream; import java.io.Outp... Retrieve and import the a certificate: E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by meiu on March 31, 2011 20:05:53    Last update: March 31, 2011 20:05:53
The Java exclusive or operator is ^ . This example uses it to reverse an integer array: public class ExclusiveOrExample { public st...
Created by Bambi on March 30, 2011 09:40:18    Last update: March 30, 2011 09:40:18
In Java, use PrintStream.printf with %x to print an integer as hex. public class PrintHex { public static void ...
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 magnum on March 28, 2011 11:51:53    Last update: March 28, 2011 11:52:36
dd by default does not give you any indication of progress. You may be wondering what's going on when you are copying a big file and it's taking a long time. You may start dd in the background and send it SIGUSR1 periodically to view progress. However, I think pv is more convenient. $ pv /dev/cdrom | dd of=./cdrom.img bs=64k 1.19... I've seen code like the following in the wild. But it's fragile code at best since it depends on the text output of fdisk. In fact, it doesn't work for most systems since fdisk reports in GB not MB. Plus the regex is unnecessarily complicated. # This does not work! dd if=/dev/hdb | (pv -s `...
Created by Dr. Xi on March 28, 2011 11:11:33    Last update: March 28, 2011 11:13:21
grep is a versatile command with many variations (grep, egrep, fgrep, then various implementations). It uses a regula expression (regex) pattern to filter input. But then there are basic and extended flavors of regex - leading to even more confusion. And, beware that there are lots of bad examples of regex in the wild... There are two critical questions to ask when you use grep: which grep implementation are you using? what is the flavor of the regex? Here are some examples for gnu grep v2.7: # Find all numbers (no decimal point), basic regex... Use the -o flag to show only the matching part instead of the whole matching line: grep -o -E '\b[0-9]{2}\b' The good thing about the gnu grep is that it...
Created by jinx on March 10, 2011 12:14:50    Last update: March 10, 2011 12:15:52
Use print_r to print out variables in human readable form. <?php $a = array ('a' => 'apple', 'b' => 'banan... Prints: Plain print: ============ Array print...
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 #...
Previous  1 2 3 4 5 6 7 8 9 10 Next