Notes by Dr. Xi

Displaying notes 21 - 30
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 February 17, 2011 12:34:58    Last update: August 10, 2011 09:04:32
String comparison operators: Operator Meaning -n str the length of str is nonzero. -z str the length of str is zero (0). str1 = str2 str1 and str2 are the same (note one equal sign, not two!). str1 != str2 str1 and str2 are not the same. str str is not a null string Examples: # empty string is not null if [ '' ]; then ... Numerical comparisons ( integer expressions only! ): Operator Meaning int1 -eq int2 int1 and int2 are numerically equal int1 -ne int2 int1 and int2 are numerically NOT equal int1 -gt int2 int1 is greater than int2 int1 -ge int2 int1 is greater than or equal to int2 int1 -lt int2 int1 is less than int2 int1 -le...
Created by Dr. Xi on August 02, 2011 15:44:45    Last update: August 02, 2011 15:44:45
The time module provides functions for time manipulation: $ python Python 2.7 (r27:82500, Sep 16 2010, 18...
Created by Dr. Xi on July 27, 2011 08:55:34    Last update: July 27, 2011 08:55:34
It is OK to remove elements from a list with Iterator , but you get UnsupportedOperationException if the list is created with Arrays.asList : import java.util.*; public class IteratorRe... Prints: ArrayList test: ================ List size: ...
Created by Dr. Xi on August 11, 2007 15:56:47    Last update: July 19, 2011 08:15:55
Here's a list of common TCP ports. You can find a more complete list here: http://www.gasmi.net/docs/tcp.html . Port Number Service Description 21 FTP File Transfer Protocol 22 SSH Secure Shell 23 Telnet Telnet remote login 25 SMTP Simple Mail Transfer Protocol 70 gopher Gopher 79 finger Finger 80 HTTP Hyper Text Transfer Protocol (WWW) 88 Kerberos Kerberos authentication 94 tivoli Tivoli Object Dispatcher 110 pop3 Post Office Protocol Version 3 123 ntp Network Time Protocol 137 netbios NetBIOS Name Service 138 netbios NetBIOS Datagram 139 netbios NetBIOS Session 143 imap Internet Message Access Protocol 161 snmp Simple Network Management Protocol 162 snmptrap SNMP trap 194 irc Internet Relay Chat Protocol 389 ldap Lightweight Directory Access Protocol 443 https Secure HTTP 445 SMB MS Server Message...
Created by Dr. Xi on July 15, 2011 09:25:15    Last update: July 15, 2011 09:25:15
Some methods to search for a substring within a string: To know that a substring indeed exists within a string: boolean found = wholeString.contains(substring); To find where the substring is contained: int index = wholeString.indexOf(substring); If the substring is regex: boolean match = wholeString.matches(".*" + substri... Case insensitive match: convert both whole string and substring to lowercase, then compare. Or, use case insensitive flag for regex. Test code: import java.util.regex.*; public class Stri...
Created by Dr. Xi on July 14, 2011 11:50:28    Last update: July 14, 2011 11:50:28
This is not to make the size of the array smaller, but to remove the leading and trailing spaces in each element. This works: String[] a = { " 1 ", " 2 " }; for (int i = 0; ... This does not work: for (String s: a) { s = s.trim(); }
Created by Dr. Xi on July 14, 2011 11:47:48    Last update: July 14, 2011 11:47:48
The String.trim function trims spaces from both ends. There's no built-in function to trim only the right side or left side. To right trim: String trimmed = original.replaceAll("\\s+$", ""); To left trim: String trimmed = original.replaceAll("^\\s+", "");
Created by Dr. Xi on July 14, 2011 09:28:57    Last update: July 14, 2011 09:28:57
Java arrays are fixed size, so you have to make a new array with smaller size and copy the data. For JDK6 and above: // import java.util.Arrays; newArray = Arrays.c... Before that (using Object as example): Object[] newArray = new Object [newSize] ; Syst...
Created by Dr. Xi on July 14, 2011 08:26:05    Last update: July 14, 2011 08:26:05
You can iterate through an array of String like this: String[] a = { "one", "two", "three" }; for (in... or like this: for (String s: a) { System.out.println(s); ... For a string Collection , iterate like this: Collection<String> c = Arrays.asList("one", "two",... or like this: Collection<String> c = Arrays.asList("one", "two",...
Previous  1 2 3 4 5 6 7 8 9 10 Next