2016年6月14日 星期二

50 Tips for MongoDB Developer


http://virusswb.blog.51cto.com/115214/793453
 
Tip#1.Duplicate data for speed,reference data for integrity

2016年3月21日 星期一

黑客來攻擊-強制上廣告

最近又遇到黑客來要脅要在網站內上廣告(用戶只要點擊廣告就會有可能在手機內啟動小額支付的功能)

這種模式,真的是看誰錢夠多.我們用再多的CDN,incapsula,nexusguard,cloudflare,voxility ,流量再多,也難免會有流量不夠的時候.

看來又得花時間再想一下對策了.



2008年5月15日 星期四

在Window上使用Mac 的選單RocketDock


這個不錯用.
不用買MAC 就可以用到它的選單了

使用beanutil


有一次寫一個小小的系統.
就有遇到要一直從DB撈資料塞到java bean 裡.
就要寫一大堆setter ,
分享一個小小程式,可以自動對應欄位和bean properties,
不過就在table 的欄位名稱和bean 的attribute 要取一樣的名字

例如:

tableA.ID
talbleA.CHINESE_NAME
talbleA.EMAIL

bean.id
bean.chineseName
bean.email

protected Object setBeanProperty(Object bean, ResultSet rs) {
String[] columns = getColumnName(rs);
try {
for (int i = 0; i < columns.length; i++) {
String str = determineClassType(rs.getObject(i + 1));
BeanUtils.setProperty(bean, columns[i], str);
}
} catch (Exception e) {
throw new DAOException(e, "Bean property conversion failed!");
}
return bean;
}

/**
* get all column name.
*
* @param ResultSet
* @return String []
* @author kenny
*/
protected String[] getColumnName(ResultSet rs) {

int columnCount = 0;
ResultSetMetaData metaData = null;
String columns[] = null;

try {
metaData = rs.getMetaData();
columnCount = metaData.getColumnCount();
columns = new String[columnCount];
for (int i = 0; i < columnCount; i++) {
StringBuffer sb = new StringBuffer(metaData
.getColumnName(i + 1).toLowerCase());
int index = index = sb.indexOf("_");
;
while (index != -1) {

String tmp = sb.substring(index + 1, index + 2)
.toUpperCase();

sb.replace(index + 1, index + 2, tmp);
sb.deleteCharAt(index);
index = sb.indexOf("_");

}

columns[i] = sb.toString();
}
} catch (Exception e) {
logger.error("error at getColumnName:" + e.getMessage(), e);
}

return columns;
}

/**
*
* @param Object
*
* @author kenny
*/
private String determineClassType(Object o) {
String rtn = null;
if (o instanceof String) {
rtn = Util.dataBlank(o);
} else if (o instanceof java.sql.Timestamp ) {
long l = ((java.sql.Timestamp) o).getTime();
Date d = new Date(l);
rtn = Util.commonDateFormat(d, "yyyy/MM/dd HH:mm");
} else if (o instanceof java.util.Date) {
rtn = Util.commonDateFormat((java.util.Date) o, "yyyy/MM/dd");
}else if (o instanceof java.lang.Number) {
rtn = o.toString();
}else if(o == null){
rtn="";
} else {
rtn = o.toString();
}
return rtn;
}

2008年5月13日 星期二

使用java.util.TimeZone 取得各時區的時間


所謂的UTC時間就是指表示自從標準基準時間,即1970年1月1日00:00:00 GMT)以來的指定毫秒數,所以這個時間所有計算都是一樣的。

利用 java.util.TimeZone 可以幫助我們取得各時區的時間,
一個sample code:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
TimeZone timeZoneParis = TimeZone.getTimeZone("Asia/Taipei");
Locale localeEN = Locale.US;
Date curDate = new Date();
dateFormat.setTimeZone(timeZoneParis);
System.out.println(dateFormat.format(curDate));

要取得各時區的iD 可以用以下的method
timezone.getAvailableIDs();

Sybase SQL 語法--left outer join


想像結合兩個表格.

一個左一個右.以左邊對右邊的資料,不管左邊對到右邊的資料有對到或者沒對到.都不能排除掉左邊的資料

SELECT Table1.col1, Table2.col1, Table3.col1
FROM {oj {oj Table1 LEFT OUTER JOIN Table2 ON Table1.col1 = Table2.col1}
LEFT OUTER JOIN Table3 ON Table2.col1 = Table3.col1}

2008年5月7日 星期三

Tomcat 限制特定主機存取

有時,你可能只想讓來自特定的主機名稱或 IP 位址的使用者,能存取 Tomcat 的 web 應用程式。這樣一來,就只有位於指定站點的客戶端能夠取得服務的內容了。Tomcat 內有兩個 Valve 可做此用途的設定:RemoteHostValve 和 RemoteAddrValve。

這些 Valve 可以讓你用主機名稱或 IP 位址來過濾請求,並允許或拒絕比對成功的主機。其功用類似於 Apache httpd 中,以目錄為基準的 Allow/Deny 指令。如果執行 Admin 應用程式,你可能想只允許從 localhost 來存取它,如下所示:
<Context path="/path/to/secret_files" ...>
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="127.0.0.1" deny=""/>
</Context>
如果未給定 allow 樣式,則會拒絕符合 deny 屬性的樣式,但允許所有其它的樣式。類似地,如果未給定 deny 樣式,則會允許符合 allow 屬性的樣式,但拒絕所有其它的樣式。