Archive for 2010
两个周末
上个周末,为了测试一下体力,跑了一个迷你马拉松,大概10多公里的路程,连跑带走,中间还看了一会模型飞机表演。
这个周末,代表公司参加了,2010软件工程技术、产业与人才培养论坛,论坛的名子起的很响亮,大概也就百十来人的规模
上图是来自CMU的John T Grasso(现已离开CMU,他在SEPG的推广上作出了很大的贡献),在做开篇演讲《Methodology in Software Engineering Education》期间还有一些来自IT界著名和非著名人士做了些专题报告。整个论坛类似于TED,但是比TED更有倾向性,就是软件工程、产业、教育等。
中午吃饭的时候,遇到个老先生,据他说是从美国回来,之前在Bell Labs,刚回国4个月,开了家公司,马上就搞定了3个单子,主要做的是视觉识别类的软件以及产业化,大概是用在Test Handler上的一些技术,据他说前途一片光明,佩服。
Mikado Spiel
傍晚去欧尚买盆栽植物,偶然在体育用品货架上发现个怪怪的盒子,里面装了很多小棍子,似乎听别人说过有种棍子游戏,我没有玩过,遂买回来玩玩。
详见说明:
http://de.wikipedia.org/wiki/Mikado_(Spiel)
http://baike.baidu.com/view/718078.htm
Email Lost In Outlook 2010 and Recovery Method
Several weeks ago, I upgraded my Outlook to Outlook 2010 Beta, and previously I wrote a macro to move all emails with my name in the recipient list to a local PST folder(folder: OnlyToMe) automatically. So there’s no backup in enterprise vault.
This morning, when I try to check email in my Outlook, there’s no email in this folder(OnlyToMe), but there’s a number indicating 4 new emails:
OnlyToMe(4)
This is the most important folder for me, the folder size is around 500M(for Y2010 only), below is how I recover it:
Sub Recover()
Set OutApp = CreateObject("Outlook.Application")
Set NmSpace = OutApp.GetNamespace("MAPI")
Set F = NmSpace.Folders("Default").Folders("OnlyToMe")
Set T = NmSpace.Folders("HR").Folders("Temp")
For intX = F.Items.Count To 1 Step -1
Set objMessage = F.Items.Item(intX)
objMessage.Move T
Next
Set OutApp = Nothing
Set NmSpace = Nothing
Set F = Nothing
Set T = Nothing
End Sub
Above VBA will move all mail items from the weird folder to a newly created folder. I believe I’m not the only one who got this problem, if you’re the lucky guy, try this method. Don’t forget to re-create a new PST, it’s likely something wrong with the PST.
Outlook 2010 is still a beta release, using it in a production environment is not a good practice. if you like the new features of 2010, you’d better backup your PST regularly.
Config PL/SQL Developer without installing Oracle client
- download instant client package http://download.oracle.com/otn/nt/instantclient/112010/instantclient-basic-win32-11.2.0.1.0.zip
- extract it to C:\Oracle\instantclient_11_2
- add C:\Oracle\instantclient_11_2 to %PATH%
- set %LD_LIBRARY_PATH%, %SQLPATH% and %TNS_ADMIN% as C:\Oracle\instantclient_11_2
- set OCI Library as “C:\Oracle\instantclient_11_2\oci.dll” in PL/SQL Developer (Tools->Preferences->Connection)
- done
I verified it on Windows 7, it works.
见微知著
最近新改了宽带,从有线通换到电信,初始密码是就是电话号码,这个是电信的客服人员推荐的,他说这样的密码比较好记,不容易忘记(安全意识差,对用户信息安全不负责任)。不知道是否有人扫描过电信用户的账号,用户名和密码相同的情况应该不少见(电信用的验证码就是最简单的图片,没有加任何噪音,很容易被破解,这个也是对客户信息安全的不负责任)。
电信一直比较霸道,比如宽带业务,强行绑定电话,买它的宽带一定要装固话,否则免谈,最近更离谱,不仅要装固话,还要强送139号码,对于很多人来说,已经有一个移动或者联通的号码,为什么还要装一个固话和一个139手机。看来只顾着抢钱了,很多细节的用户体验根本都顾忌不上了。
NoSuchMethodError of BeanUtils.copyProperty(due to wrong access level)
为了节省开发时间,今天打算做一个数据集合类,可以直接将java中的ResultSet,或者其他Collection派生类的内容copy到该集合中,然后加入自定义的一些方法,比如支持直接导出Excel、CSV、KDF、Image、HTML等。这里借助Apache Commons BeanUtils的和反射(Reflection),将数据库中的一行记录保存为一个对象,然后插入数据集中,结果老是报错如下:
USING CONVERTER org.apache.commons.beanutils.converters.IntegerConverter@1befab0
java.lang.reflect.InvocationTargetException: Cannot set id
at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:449)
at org.apache.commons.beanutils.BeanUtils.copyProperty(BeanUtils.java:129)… …
Caused by: java.lang.NoSuchMethodException: Property ‘id’ has no setter method
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1746)
at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:447)
代码段如下:
private void dumpResultSet(ResultSet rs, Class clazz) throws Exception {
ResultSetMetaData metaData = (ResultSetMetaData) rs.getMetaData();
int colCnt = metaData.getColumnCount();
Field[] fields = clazz.getDeclaredFields();
while (rs.next()) {
Object newInstance = clazz.newInstance();
for (int i = 1; i <= colCnt; i++) {
try {
Object value = rs.getObject(i);
for (int j = 0; j < fields.length; j++) {
Field f = fields[j];
if (f.getName().equalsIgnoreCase(
metaData.getColumnName(i).replaceAll("_", ""))) {
log.info("f.getName:" + f.getName());
BeanUtils.copyProperty(newInstance, f.getName(),
value);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
list.add(newInstance);
}
}
The root cause: public is required for class UserInfo, or else you’ll get the ‘NoSuchMethodError‘ exception, DO NOT ignore the access level
public class UserInfo {
private int id;
private String user;
private String password;
public UserInfo() {
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Eclipse一直提示:NoSuchMethodError,可是UserInfo里面明明有对应的setter方法,最后,才鬼使神差的发现,只要将UserInfo整个类声明为public就可以了。我一直都把注意力放到是否把setter和getter设置为public,却忽略了Bean的访问级别,希望碰到类似问题的朋友可以注意一下。
重置PL/SQL Developer的试用期
如果你安装了PL/SQL Developer的试用版,但在30天内,没有足够的时间来试用它(可能被别的事情耽搁了),可以把下面的Python(V2.6)程序放入你的启动项里,它可以让你无限期的试用PL/SQL Developer (经测试对版本8.0.2.1505有效,未对其他版本测试),它的原理是每次系统启动的时候,自动检测上次”重置(reset)安装信息”的时间,这些信息保存在一个SQLite数据库中(foobar.db),请不要删除它,如果时差超过了25天,再次重置(reset)。
import os
import shutil
import win32api
import win32con
import sqlite3
import time
import _winreg
from time import *
from datetime import *
# Reset the trial period of PL/SQL Developer, USE AT YOUR OWN RISK, buy it if you really need it
# by Charry
list = list();
def traverse(root, key, list):
hKey = _winreg.OpenKey(root, key);
try:
i = 0
while 1:
strFullSubKey = "";
try:
strSubKey = _winreg.EnumKey(hKey, i)
strFullSubKey = key + "\\" + strSubKey;
except WindowsError:
hKey.Close();
return;
traverse(root, strFullSubKey, list);
#print strFullSubKey;
list.append(strFullSubKey);
i+=1
except WindowsError:
print
hKey.Close();
def reg_delete_key(root, key):
global list;
traverse(root, key, list);
for item in list:
_winreg.DeleteKey(root, item);
#print item;
_winreg.DeleteKey(root, key);
def crack():
conn = sqlite3.connect('foobar.db')
conn.execute("""CREATE TABLE IF NOT EXISTS CONFIG(
ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
LAST_MODIFIED DATE DEFAULT CURRENT_DATE NULL)""")
cursor = conn.cursor()
today = datetime.now().strftime("%Y-%m-%d")
# get the last_modified date
sql = "SELECT * FROM {0} ORDER BY LAST_MODIFIED DESC;".format("CONFIG", today)
cursor.execute(sql)
str_last_modified = '1970-01-01'
for row in cursor:
str_last_modified = row[1]
break
print "Last Cracked Time: " + str_last_modified
# get date delta
tm_last_modified = datetime.strptime(str_last_modified, "%Y-%m-%d")
time_diff = datetime.now() - tm_last_modified
if time_diff.days > 25:
print "Trial period was reset " + str(time_diff) + " ago"
print "Save the world, save the cheerleader, let's teleport again"
sql = "INSERT INTO {0} (LAST_MODIFIED) VALUES('{1}');".format("CONFIG", today)
cursor.execute(sql)
conn.commit()
reg_delete_key(_winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Security");
reg_delete_key(_winreg.HKEY_CURRENT_USER, r"Software\Allround Automations");
cursor.close()
conn.close()
crack();
Keyword: Python, PL/SQL Developer, Crack
A helper function to remove Windows registry key recursively
The default register function of Python(2.6.x) can’t delete a Windows registry key recursively, an exception(Access is denied) will be thrown if you try to delete a key with sub-keys , below is a wrapper which is easy-to-use, you could use it to delete a key and its sub-keys:
import _winreg def traverse(root, key, list): hKey = _winreg.OpenKey(root, key); try: i = 0 while 1: strFullSubKey = ""; try: strSubKey = _winreg.EnumKey(hKey, i) strFullSubKey = key + "\\" + strSubKey; except WindowsError: hKey.Close(); return; traverse(root, strFullSubKey, list); #print strFullSubKey; list.append(strFullSubKey); i += 1 except WindowsError: print hKey.Close(); def reg_delete_key(root, key): global list; list = list(); traverse(root, key, list); for item in list: _winreg.DeleteKey(root, item); #print item; _winreg.DeleteKey(root, key); # Example: reg_delete_key(_winreg.HKEY_CURRENT_USER, r"Software\charry.org");
Keyword: Python, RegDeleteKey, 注册表, 删除



