2009年6月30日 星期二

2009 新書介紹: Network Infrastructure Security


Springer, 1 edition (May 20, 2009)

Research on Internet security over the past few decades has focused mainly on information assurance, issues of data confidentiality and integrity as explored through cryptograph algorithms, digital signature, authentication code, etc. Unlike other books on network information security, Network Infrastructure Security by Angus Wong and Alan Yeung addresses the emerging concern with better detecting and preventing routers and other network devices from being attacked or compromised.

Attacks to network infrastructure affect large portions of the Internet at a time and create large amounts of service disruption, due to breaches such as IP spoofing, routing table poisoning and routing loops. Daily operations around the world highly depend on the availability and reliability of the Internet, which makes the security of this infrastructure a top priority issue in the field.

Network Infrastructure Security is a book that bridges the gap between the study of the traffic flow of networks and the study of the actual network configuration. This book makes effective use of examples and figures to illustrate network infrastructure attacks from a theoretical point of view. The book includes conceptual examples that show how network attacks can be run, along with appropriate countermeasures and solutions.

2009年6月29日 星期一

JS instanceof判斷類型問題

判斷變量類型:一般情況下,可以先用typeof運算符,如果結果是"object",再用instanceof來判斷;
特別的地方是:
instanceof不認為原始類型值的變量是對象,

1. var temp="a string for test";
2. //下面這句返回"string"
3. alert( typeof temp);
4. //下面這句返回"false"
5. alert(temp instanceof String);
6.
7. //看看Ext內部實現,判斷String類型
8. if( typeof temp== "string"){
9. }

其他附加問題:

* null:表示尚未存在的對象,注意,儘管尚未存在,也是個對像啊,所以用typeof檢測一個null值變量的結果是Object;不過,為了便於寫 if語句,在js中,"undefined==false ", "null=false",因此,"undefined==null"。
*整數:最容易犯的錯誤就是,忘了070其實是個八進制數,相當於十進制的56;
*浮點數:“在進行運算之前,真正存儲的是字符串”——這應該是解釋執行的本質決定的吧——直接後果是,alert(0.8)這樣的語句可以正確輸出,而alert(2 *0.8)的輸出就成了"2.40000000000000003"
*數字邊界:數字有幾個邊界值,分別是Number.MAX_VALUE(最大值), Number.MIN_VALUE(最小值), Number.POSITIVE_INFINITY(正無窮), Number.NEGATIVE_INFINITY(負無窮), Infinity(無窮大,- Infinity,這個有點莫名其妙,不知道為啥又搞出一套);特別地,還有一個isFinit(iNumber)函數來判斷數字是否為無窮大。
* NaN:一些需要數字作為參數的函數,當傳入的實參無法轉換為數字時,往往會返回這個值;關於NaN,最重要的就是要記住NaN!=NaN,因此判斷一個變量是否為NaN,一定要使用isNaN(var)函數。
*將字符串轉換為數字:sVar.parseInt()是最常用的函數,也最容易出錯,為了保險起見,最好每次調用的時候,都加上“進制”的參數,比 如:a .parseInt(10),就制定了按十進制轉換字符串a;Number(sVar)也是一種轉換方式,不同的是,它要求整個字符串都得是有效數字,因 此Number("4.5.5")將返回NaN;

source: http://www.blogjava.net/oathleo

2009年6月28日 星期日

Oracle - 如何在 SELECT statement 中,實作 IF-THEN-ELSE 邏輯 ?

How does one implement IF-THEN-ELSE logic in a SELECT statement?

Submitted by admin on Sat, 2005-11-12 06:38

Oracle SQL supports several methods of coding conditional IF-THEN-ELSE logic in SQL statements. Here are some:
CASE Expressions

From Oracle 8i one can use CASE statements in SQL. Look at this example:

SELECT ename, CASE WHEN sal = 1000 THEN 'Minimum wage'
WHEN sal > 1000 THEN 'Over paid'
ELSE 'Under paid'
END AS "Salary Status"
FROM emp;
DECODE() Function

The Oracle decode function acts like a procedural statement inside an
SQL statement to return different values or columns based on the values of
other columns in the select statement. Examples:

select decode(sex, 'M', 'Male', 'F', 'Female', 'Unknown')
from employees;

select a, b, decode( abs(a-b), a-b, 'a > b',
0, 'a = b',
'a < b') from tableX;

Note: The decode function is not ANSI SQL and is rarely implemented
in other RDBMS offerings. It is one of the good things about Oracle,
but use it sparingly if portability is required.


GREATEST() and LEAST() Functions

select decode( GREATEST(A,B), A, 'A is greater OR EQUAL than B',
'B is greater than A')...



select decode( GREATEST(A,B),
A, decode(A, B, 'A NOT GREATER THAN B', 'A GREATER THAN B'),
'A NOT GREATER THAN B')...

NVL() and NVL2() Functions

NVL and NVL2 can be used to test for NULL values.

NVL(a,b) == if 'a' is null then return 'b'.

SELECT nvl(ename, 'No Name')
FROM emp;

NVL2(a,b,c) == if 'a' is not null then return 'b' else return 'c'.

SELECT nvl2(ename, 'Do have a name', 'No Name')
FROM emp;

COALESCE() Function

COALESCE() returns the first expression that is not null. Example:

SELECT 'Dear '||COALESCE(preferred_name, first_name, 'Sir or Madam')
FROM emp2;

NULLIF() Function

NULLIF() returns a NULL value if both parameters are equal in value. The following query would return NULL:

SELECT NULLIF(ename, ename)
FROM emp;

source: http://robertvmp.pixnet.net/blog/post/24147936

2009年6月23日 星期二

Startup Oracle listener

[root@localhost ~]# su - oracle
[oracle@localhost ~]$ cd
[oracle@localhost ~]$ source .bash_profile
\[oracle@localhost ~]$ lsnrctl start

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 24-JUN-2009 10:58:29

Copyright (c) 1991, 2005, Oracle. All rights reserved.

Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 24-JUN-2009 10:58:31
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost ~]$ sqlplus sys/oracle as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jun 24 10:58:45 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 100664912 bytes
Database Buffers 180355072 bytes
Redo Buffers 2973696 bytes

2009年6月17日 星期三

簡單獲取google天氣報告

簡單獲取google天氣報告

http://www.google.com/ig/api?hl=zh_tw&weather=hk



























































1 package com.pmjava.util;
2
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.InputStreamReader;
9 import java.net.MalformedURLException;
10 import java.net.URL;
11
12
13 import java.io.*;
14 import org.w3c.dom.*;
15 import javax.xml.parsers.*;
16
17 public class GetWeather {
18
19
20 public String getweather(String city)
21 {
22 try {
23 URL ur = new URL("http://www.google.com/ig/api?hl=zh_cn&weather="+city);
24 InputStream instr = ur.openStream();
25 String s, str;
26 BufferedReader in = new BufferedReader(new InputStreamReader(instr));
27 StringBuffer sb = new StringBuffer();
28
29 Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("weather.txt"), "utf-8"));
30 while ((s = in.readLine()) != null) {
31 sb.append(s);
32 }
33 str = new String(sb);
34 out.write(str);
35 out.close();
36 in.close();
37
38
39 } catch (MalformedURLException e) {
40 e.printStackTrace();
41 } catch (IOException e) {
42 e.printStackTrace();
43 }
44 File f=new File("cityweather.txt");
45 DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
46 String str=null;
47 try{
48 DocumentBuilder builder=factory.newDocumentBuilder();
49 Document doc = builder.parse(f);
50 NodeList nl = (NodeList) doc.getElementsByTagName("forecast_conditions");
51 NodeList n2=nl.item(0).getChildNodes();
52
53 str=n2.item(4).getAttributes().item(0).getNodeValue()+","+n2.item(1).getAttributes().item(0).getNodeValue()+"℃-"+n2.item(2).getAttributes().item(0).getNodeValue()+"";
54 }catch(Exception e)
55 {
56
57 }
58
59 return str;
60 }
61
62
63
64 }