Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on May 02, 2011 15:59:37
Last update: February 25, 2012 09:16:37
This code snippet gets the default keystore used by the Java keytool and displays the list of aliases along with the key type (certificate or private key).
import java.io.File;
import java.io.FileInputSt...
The default keystore used by the above code is: $HOME/.keystore .
Created by Dr. Xi on August 25, 2011 08:41:36
Last update: August 25, 2011 08:41:36
There is no switch statement in Python. PEP 3103 is in rejected status. Use the " if..elif.. " struct instead:
r = i % 5
if r == 0:
print "V: ", l
...
Created by Dr. Xi on August 10, 2011 14:58:49
Last update: August 10, 2011 14:58:49
In python:
#!/usr/local/bin/python
import sys
if sys.ve...
In shell script:
#!/bin/bash
PYTHON=/usr/local/bin/python
...
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 June 20, 2011 15:18:06
Last update: June 20, 2011 15:18:06
Perl does not have built-in functions to get the base name or dir name from a file path. But on the Unix platforms we can rely on the executables basename and dirname .
#!/usr/bin/perl
$f = '/A path with/space "/file...
The quotes, escapes, and chomp are necessary:
# This fails when there's a space in $f
$base =...
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 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>
...
Created by Dr. Xi on April 18, 2011 12:10:37
Last update: April 18, 2011 12:14:24
Python defines a long list of special methods to customize class behavior. This is a short list for the Basic Customizations . Method Description object.__new__(cls[, ...]) Called to create a new instance of class cls. __new__() is a static method (special-cased so you need not declare it as such) that takes the class of which an instance was requested as its first argument. __new__() is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. It is also commonly overridden in custom metaclasses in order to customize class creation. object.__init__(self[,...]) Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class’s __init__()...
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 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.*;
...