Sunday, September 24, 2006

Saturday, July 15, 2006

Tuesday, March 07, 2006

ThinkFree Office3 Online

ThinkFree:Write, Show and Clac .
You can edit Microsoft Excel spreadsheet, Microsoft Word documents, or Microsoft PowerPoing presentation on line.

URL:
http://online.thinkfree.com

Wednesday, March 01, 2006

Python: Funkload

FunkLoad:This tool enables to do functional and load testing of web appplication.

URL:
http://funkload.nuxeo.org/

Friday, February 24, 2006

Singleton using python under ms-windows

From ASPN python cookbook
Submitter: Dragan Jovelic

URL:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474070
-------------------------------------------------------
from win32event import CreateMutex
from win32api import CloseHandle, GetLastError
from winerror import ERROR_ALREADY_EXISTS

class singleinstance:
""" Limits application to single instance """

def __init__(self):
self.mutexname = "testmutex_{D0E858DF-985E-4907-B7FB-8D732C3FC3B9}"
self.mutex = CreateMutex(None, False, self.mutexname)
self.lasterror = GetLastError()

def aleradyrunning(self):
return (self.lasterror == ERROR_ALREADY_EXISTS)

def __del__(self):
if self.mutex:
CloseHandle(self.mutex)


#---------------------------------------------#
# sample usage:
#

from singleinstance import singleinstance
from sys import exit

# do this at beginnig of your application
myapp = singleinstance()

# check is another instance of same program running
if myapp.aleradyrunning():
print "Another instance of this program is already running"
exit(0)

# not running, safe to continue...
print "No another instance is running, can continue here"

Wednesday, February 22, 2006

離職攻防戰I

今天我拿team leader C簽好的離職單給單位處長A簽名,
A:「老闆教我不能簽,要叫C跟老闆溝通完,我才能簽」
隨即,他播電話給C,也就是我的team leader
A:「C啊,我不能簽啊,你要先跟老闆講」

A掛掉電話後,把離職單還給我

A:「等溝通完了你在拿來。人要走,我留你也是沒意思啊,
但是還是要請C先去跟老闆說。」

我回到位置上,撥了通電話到國防部訓儲小組,跟他們說我有按照離職程序無法,但是公司不給離開。

國防部訓儲小組就打電話到公司國防訓儲關心。人事部主任對於我打電話去國防部求助的事情很不開心,他找了我team leader去談,跟他抱怨說我很不聽話,居然跑去國防部告狀,這樣他會考慮用合約內容跟我求償。訓儲小組也打電話給我,跟我說他們瞭解後的結果。

國:「因為你有跟公司簽約,這部分我們沒辦法插手,你要自己去找人問那份合約是不是有法律效益,因為我們不清楚那份合約的法律效益,所以不能貿然的幫助你註銷資格,讓你回去服役……」

他說了很多,主要是說因為我有跟公司簽至少工作兩年的合約,所以不能幫我,要我自己先解決好合約的問題,如果公司不按照程序送公文,他可以幫忙催。

我當初簽的合約,沒有一式兩份,我這裡連副本都沒有留存。所以一點印象都沒有,於是我問了兩個都確定要離職的同事。

同B:這個合約有阿,大家都嘛有簽這個我以前問過法律顧問耶,他說除非像是航空空司那種花錢培訓你,你沒有用勞力付出。但是我們有付出相當勞力換取薪水,所以那種合約無效。
同D:拜託,我提離職的時候,A也是跟我講一模一樣的話。

我:是喔.....:'

我 之前跟Team Leader談的時候,他有開一些工作項目,說如果我弄完,他就簽名。我也是很任份的把工作做好,前幾天demo給他看,他給了一些意見後以及多了幾個小 地方要在做之外,我也努力達到他的需求。我覺得離職就是這樣啊,你說的條件我做到了,為什麼你還要這樣刁難我呢?在國防部關心完之後,team leader找我單獨談。
C:「你這樣我很失望,你要找我先談啊」

這是我的離職攻防戰I

Monday, February 20, 2006

Slidy

Make your presentations in pure HTML+ javascript (option).

try:
http://www.w3.org/Talks/Tools/Slidy/

Friday, February 17, 2006

id3 tags

java:
jaudiotagger
de vdheide java mp3 library
jid3

python:
id3-py
eyeD3
PyID3
pyid3tag
PyMedia
pytagger

ID3.org

python websites

There are several good python-related websites. Here are below:
Python daily: http://www.pythonware.com/daily/
Dirtsimple: http://dirtsimple.org/
gmane.comp.python.announce: http://permalink.gmane.org/gmane.comp.python.announce

Wednesday, February 15, 2006

Rhino

Mozillz Rhino is an open-source implementation of JavaScript written entirely in Java.

URL:
JSR 223 in Project Mustang.

javadoc: javax.script (since j2sdk1.6)

JFrame.show()

JFrame.show() ==>Deprecated. As of JDK version 1.5, replaced by setVisible(boolean)

javax.swing.SpringLayout ==>add from 1.4. SpringLayout is a very flexible layout manager that can emulate many of the features of other layout managers.

URL:
How to Use SpringLayout

A concatenative language

A concatenative language is one where every function has a single argument (a stack) and returns a single value (a new stack).

FYI:
Programming language Forth
Programming language JOY
Unimperative Reborn as a Concatenative Language
Joy compared with other functional languages

Tuesday, February 14, 2006

I love div

有時候在javascript要出現提示的訊息,會直接把要顯示的東西當作一個變數或是字串,往往美工相關人員的編輯以及翻譯並不會去看HTML原始碼,有時候會漏翻了這些句子。
在不使用任何高超的技術下(純粹用HTML與簡單的javascript),我採用以下的方法,讓美編人員可以在編輯時期,看到那些要顯示出來的語句。


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>test</title>
<script language="javascript" type="text/javascript">
function initHTML()
{
var divObjs = new Array(document.getElementById('actionPrompt'));
var i = 0;
for(i=0;i<divObjs.length;i++)
{
if( doesObjExists(divObjs[i]) )
setHiddent(divObjs[i]);
}
}
function setHiddent(obj)
{
obj.style.visibility = 'hidden';
}
function doesObjExists(obj)
{
var result = false;
result = obj&& typeof(obj) != 'undefined'
return result;
}
function mainProgress()
{
var actPrompt = document.getElementById('actionPrompt');
var promptText = 'Are you sure to delete all of them?';
if(doesObjExists(actPrompt))
{
promptText = actPrompt.innerHTML;
}
return confirm(promptText);
}
</script>
</head>
<body onLoad="javascript:initHTML();">
<form name="test" onSubmit="javascript:mainProgress();">
<input type="submit" name="Submit" value="按我">
</form>
<div id="actionPrompt">您確定要刪除嗎?</div>
</body>
</html>

Thursday, February 09, 2006

sqlite3 bugs?

使用:sqlite 3.2.7
schema:
CREATE TABLE msginfo(msgnum INTEGER PRIMARY KEY,msgtype INTEGER NOT NULL DEFAULT 0,msgts INTEGER NOT NULL,msgbtime INTEGER NOT NULL,msgtime INTEGER DEFAULT NULL,linenum INTEGER NOT NULL,msgtsbegin INTEGER NOT NULL DEFAULT 0,callid VARCHAR(255) DEFAULT '',dialstr VARCHAR(255) DEFAULT '',ownerid INTEGER NOT NULL,msgmemo TEXT DEFAULT NULL,user_type INTEGER,archived INTEGER DEFAULT NULL,source INTEGER DEFAULT NULL,orgidx INTEGER DEFAULT NULL,UNIQUE (msgts,linenum,ownerid));
CREATE INDEX Idx_comp on msginfo (ownerid,msgts);
CREATE INDEX Idx_msgts on msginfo (msgts);
CREATE INDEX idx_msgbtime ON msginfo(msgbtime);
CREATE INDEX idx_msgfile ON msginfo (msgts,linenum);
CREATE INDEX idx_msgtime ON msginfo(msgtime);
CREATE INDEX idx_msgtsbegin ON msginfo(msgtsbegin);
CREATE INDEX idx_ownerid ON msginfo (ownerid);

import pysqlite2.dbapi2 as sqlite
con = sqlite.connect('test.db')
cur = con.cursor()
pagelen = 50
cond = 'ownerid=20 AND msgtype=0'
cur.execute('SELECT COUNT(*) FROM msginfo WHERE %s' % cond)
total = cur.fetchone()[0]
pages = (total + pagelen - 1) //pagelen
print 'Total:%d'% total
for i in range(pages):
offset = i * pagelen
cur.execute('select * from msginfo where %s order by msgts desc limit 50 offset %d'% (cond, offset))
a = cur.fetchall()
begin = i*pagelen
sizeofa = len(a)
print 'offset = %d and data =%d (%d~%d)'% (offset,sizeofa, begin, begin + sizeofa)

---------------------------------------------------------------------------------
Total: 1978
offset = 0 and data =50 (0~50)
offset = 50 and data =50 (50~100)
offset = 100 and data =50 (100~150)
offset = 150 and data =50 (150~200)
offset = 200 and data =50 (200~250)
offset = 250 and data =50 (250~300)
offset = 300 and data =50 (300~350)
offset = 350 and data =50 (350~400)
offset = 400 and data =50 (400~450)
offset = 450 and data =50 (450~500)
.....
.....
offset = 1750 and data =50 (1750~1800)
offset = 1800 and data =50 (1800~1850)
offset = 1850 and data =50 (1850~1900)
offset = 1900 and data =50 (1900~1950)
offset = 1950 and data =31 (1950~1981)
------------------------------------------
紅色部分應該是28,因為1978 % 50 = 28

檢查SQL語法以及使用的Index:
bash-2.03# idxchk backupMsgInfo.db
SELECT COUNT(*) FROM msginfo WHERE ownerid = 20 AND msgtype = 0
table index(es) column(s)
------- ----------- ------------------------------
msginfo
msginfo idx_ownerid (ownerid)

bash-2.03# idxchk backupMsgInfo.db
SELECT * FROM msginfo WHERE ownerid = 20 AND msgtype = 0 ORDER BY msgts DESC LIMIT 50 OFFSET 1950
table index(es) column(s)
------- ---------- ------------------------------
msginfo
msginfo Idx_comp (ownerid,msgts)

使用的Index不同。現在強制取消使用Index:
sqlite3 backupMsgInfo.db
>SELECT * FROM msginfo WHERE +ownerid = 20 AND +msgtype = 0 ORDER BY msgts DESC LIMIT 50 OFFSET 1950;
219|0|948670669|73655|73749|2|948670615||1|20|||5||27
211|0|948670558|73505|73558|2|948670505||1|20|||5||26
203|0|948670447|73314|73407|2|948670394||1|20|||5||25
...
...
共28筆

結局:
資料庫Index不同步。
(到底是什麼鬼原因讓資料庫的Index不同步....)
解決方法:使用VACCUM

Tuesday, February 07, 2006

刪除某行

import os
ip = '192.168.1.123'
ip = ip.replace('.','\\.')
SourceFile = '/root/.ssh/known_hosts'
UpdateFile = '/root/.ssh/known_hosts'
params = (SourceFile, ip, UpdateFile)
result = os.system("cp %s /tmp/known_hosts.$$ ;awk '$1!~/^%s/ {print ; }' /tmp/known_hosts.$$ > %s;rm -rf /tmp/known_hosts.$$"% params) == 0

Monday, February 06, 2006

Openwebmail malfunction

The openwebmail is suddenly malfunction after someone upgrade perl without notifing.

Here is the solution below:

portupgrade -f perl-5.8.\* -m "ENABLE_SUIDPERL=yes"

rehash

use.perl port

portupgrade -m "-DFORCE_PKG_REGISTER" -rf perl-5.8.\* -x perl-5.8.\* -l /tmp/portupgrade.log



The original post

Audacity

Audacity, a free, corss-plantform audio editor. The LAME library helps a lot to generate mp3 files.

Wednesday, January 25, 2006

sqlite index checker

http://www.sqlite.org/cvstrac/wiki?p=IdxChk

dxchk (index check) is a Tcl program that analyzes a SELECT (or other) SQL statement and prints which indexes are used.

You must install TCL and sqlite first. The other imporant package is SQLITE with TEA (Tcl Extension Architecture).
SQLITE with TEA is under download pages of sqlite

XMLHttpRequest since IE 7

http://tinyurl.com/36r6y

if (window.XMLHttpRequest){

// If IE7, Mozilla, Safari, etc: Use native object
var xmlHttp = new XMLHttpRequest()

}
else
{
if (window.ActiveXObject){

// ...otherwise, use the ActiveX control for IE5.x and IE6
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

}

Tuesday, January 24, 2006

Great!

我:「我週四以及週五要請假」

某:「你把project弄好,我可以考慮讓你請週五」

我:「喔」

-------
我心中的幹聲不絕....
本週五上班到下午三點,讓我請週五,還真仁慈啊!
抱歉,我就要離該這裡了,週四不讓我請,我也不會來上班的。

says you

我說:「SQL裡,如果要避免使用到錯誤的index ,可以在查詢時,在該column name前加上'+'」

某人:「喔,那種應該不是標準語法吧?我覺得不要用」


過了幾天

某人:「關於SQL的部分,我們應該在查詢時,在某些條件中的column name前面加上'+',得到我們要的結果」

我:「........」(心理OS:『都你在說』)

Monday, January 23, 2006

SFTP

長久以來誤會了SFTP....以為他是ftp over ssh。原來SFTP是ssh-2的subsystem,並非ftp over ssh。
--------插曲---------
某:「既然有sftp,也有rsync over ssh,那麼就應該有rsync over ftp」
我:「我之前有報告過官方網站上說,ftp與rsync是迥異的protocol。並且ftp不像ssh session可以下指令啟動遠端rsync啊!」
某「我覺得應該可以,只是沒有直接的工具,你去找找,要不然看一下winscp的source code,為什麼他可以提供sftp」
我:「是喔」

(rsync over ssh over ftp,哇,好偉大的協定...這是數學裡的等價類推嗎?)

Wednesday, January 18, 2006

能力差

前幾天team leader找我單獨開會,口氣很和緩的跟我說事情。他是一個很好的人。
  1. 我寫的程式一塌糊塗,很糟糕,無法讓他很快的瞭解。
  2. 對於解決事情的方法有問題,跟他想像的解決結果有很大的差異,常常提供出錯誤的結果,讓他無法做正確的判斷。
  3. 理論跟實務落差太大,讓他對我很失望。
  4. 個性過於情緒化,好跟不好的時候讓他無法接受。(這點我完全承認)
  5. 必須替客戶著想,不是任何客戶反應都是廢話。
  6. 盡量不要修改原有的習慣,原有架構使用mbxIdx,mgsIdx,mbxVal代表登入帳號內部識別碼、資料訊息內部識別碼以及登入帳號外部識別碼,我因為完全搞不清楚這些相似的東西,所以把內部識別碼改成ownerid。

我並不是那種別人跟我說bugs變生氣的人,但是直覺反應總是會說:「耶!怎麼會」,之後就想專心努力找出bugs所在。

最近資料庫效能非常低落,他覺得我使用的SQL非常有問題(見前幾篇post),我卻沒有跟他好好反應,因為我就是覺得SQL指令就是那樣下啊,除非有關於使用index,才會有差別。
小 型資料庫的確跟大型資料庫有實做上的差別,我也找不到證據去證明小型資料庫是否能夠在較低效能(via 的cpu)與較少資源的(128記憶體,與顯示卡分享)組合下,可以讓3個以上程序同時存取,並且在資料量250k下,搜尋與顯示時必須有適當的表現,當 然資源還是必須要讓產品做主要的功能優先,並且提供網頁或電話的控制存取。

好吧,我到底已經濫倒什麼程度了。

Tuesday, January 17, 2006

白目

我在這家公司待滿一年啦!昨天下班後,有幾個同事嘰嘰喳喳的在聊天,原來他們在討論要離職的事情。我覺得在公司公開討論這個有點不好,所以並沒有加入。不過還是有一些人,是想用「離職」來當要求加薪的手段,我覺得這個手段這是無可厚非,但是,更怪的事情就是連能力不怎樣的人也是用離職要求加薪,公司答應他的請求,也讓他留了很多年,真是見鬼的爛政策。是說管裡的人太白目嗎?

Wednesday, January 11, 2006

最好是不一樣啦



def genSqlCmd(aid,limit=0, offset=0) :
sqlcmd = 'SELECT * FROM test where aid = ?"
if limit > 0:
offset = min( 0, offset )
sqlcmd = '%s LIMIT %d OFFSET %d'% (sqlcmd, limit, offset)
sqlObj.execute(sqlcmd,
(aid,))


limit都是傳50進去,而offset分成兩種傳法:
  1. 3000-->2950-->2900
  2. 0-->50-->100
最好是產生的的sql命令會不一樣啦。team leader堅信我的程式如果傳遞offset是降冪,產生的sql指令會跟傳升冪的不同。

Friday, January 06, 2006

喔...

Python的程式可以分package ,斃team在使用的時候,完全沒有計畫把相關的code切成一個一個package ,這在一開始還好,但是現在因為功能新增,跟目錄下已經夾雜著各式各樣的py。

當初一開始時候我詢問了team的老大,他覺得沒有必要。嘿嘿.....現在這個鬼樣子,改口說要分package。

我很機歪的回:「這樣很多要改勒」
他也回了我一句:「現在不改,以後會更恐怖」

奇怪,早知如此,我當初跟他建議的時候,為什麼不好好分勒。

文章類型

我企圖分別出這個blog要發表文章的類型。可能大多都是抱怨給自己看的東西(post給自己爽的),所以如果真的有人不小心路過,請原諒我的意見。

Thursday, January 05, 2006

Everything but me ==> Everything but boring

喔喔.....都是無聊事情的blog