星期一, 11月 08, 2010

Python 使用 subprocess module 呼叫外部程式

# 當呼叫內建的指令,如 dir 時, Popen()裡的 shell 要設為 True
# stdout 可以設成檔案輸出, 如下:
fopen = open('hello.txt','w')
subprocess.Popen('dir',shell = True, stdout = fopen)
fopen.close()

星期二, 10月 26, 2010

將 source code 的原始編排放入 blog 中

使用下列網站:
http://codeformatter.blogspot.com/2009/06/about-code-formatter.html

只要將 source code 貼上, 就會產生對應的 html, 再貼入 blog 中就可以了.

使用 python 呼叫 DLL

使用 BCB 來撰寫 DLL

 extern "C" __declspec(dllexport) int __stdcall ReturnAplusB(int a,int b)  
{
return a+b+1;
}

/* 注意 __stdcall 這個宣告很重要,不然 python 會找不到而出現錯誤訊息 */

使用 python 呼叫 DLL


 from ctypes import *  
def main():
dll = windll.LoadLibrary("DllTest.dll")
c = c_short(1)
d = c_short(3)
a = dll.ReturnAplusB(c,d)
print 'the return value : %d'%a
a = dll.ReturnAplusB(4,6)
print 'the return value : %d'%a
a = dll._Print1()
print 'the return value : %d'%a
if __name__ == '__main__':
main()


## 使用 ctypes module
## 使用 windll, 這個是用來呼叫 windows 中的 DLL.

參考:
http://hi.baidu.com/fangss007/blog/item/461d00f3dc317bc50b46e078.html

星期五, 8月 27, 2010

Install Jdownloader in Ubuntu 10.04

Open the terminal and run the following command
Terminal
sudo add-apt-repository ppa:jd-team/jdownloader
sudo apt-get update
sudo apt-get install jdownloader

星期三, 7月 28, 2010

Ubuntu 上的 Hex Editor

Bless Hex Editor
另外也有 GHex, 但沒有試過。

星期六, 5月 08, 2010

Mount nrg file

使用 kiso 就可以 mount .nrg 檔
安裝方式, 使用 command line:
apt-get install kiso

之後會在"附屬應用程式" 就可找到 Kiso

星期五, 3月 26, 2010

產生 GUID 的方式

使用 BCB compiler

#include "objbase.h"

...
void __fastcall GenerateGUID(void)
{
GUID guid;

CoCreateGuid(&guid); // win32API

AnsiString asGuid = GUIDToString(guid);

}

星期三, 2月 10, 2010

把 chm 檔解開的方式

直接在 dos 視窗下輸入:
hh.exe -decompile extracted_folder filename.chm

非常簡單 !
ref:
http://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help#Applications

星期二, 11月 24, 2009

關閉自動播放功能--使用 gpedit.msc

windows xp professional:

執行 gpedit.msc 指令,啟動「群組原則」系統工具:
-> 電腦設定->系 統管理範本->系統->關閉自動播放 (啟用這項功能)

ref: http://blog.xuite.net/webe_chen/tech/24233425?ref=rel

星期三, 10月 28, 2009

Download YouTube

利用下列的 script
javascript:window.location.href%20=%20'http://youtube.com/get_video?video_id='%20+%20swfArgs['video_id']%20+%20"&fmt=18"%20+%20"&l="%20+%20swfArgs['l']%20+%20"&sk="%20+%20swfArgs['sk']%20+%20'&t='%20+%20swfArgs['t'];

其中參數 :

fmt 參數 下載格式 最高解析度 音質 聲道
flv 320*240 64Kbps MP3 單聲道
6 flv 480*360 64Kbps MP3 單聲道
18(HQ) MP4 480*360 128Kbps AAC 立體聲
22(HD) MP4 1280*720 128Kbps AAC 立體聲

參考:
http://taiwan.cnet.com/blog/0,2000089057,20137871,00.htm

星期三, 9月 23, 2009

7zip command line

using 7 zip to compress files listed in backupfilelist.txt

7z a compressed_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.7z @backupfilelist.txt

或是可以加上時間

setlocal
set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%
set yyyymmdd_hhmm=%date:~0,4%%date:~5,2%%date:~8,2%_%hh%%time:~3,2%
7z a compressed_%yyyymmdd_hhmm%.7z @backupfilelist.txt

星期五, 8月 28, 2009

os.path

使用 os.path.split() 分離路徑及檔名

# === code begin ===
import os
mypath = 'c:\basedir\dirlevel1\dirlevel2\myfile.txt'
basedir, myfilename= os.path.split(mypath)
print basedir, myfilename
# === code end ===

>> c:\basedir\dirlevel1\dirlevel2 myfile.txt

星期四, 8月 27, 2009

在 python 程式中呼叫另一個 python 程式

使用 os.system() 來達成

prog1.py:
# ========= code below ===

print 'this is prog1.py'

# ========= code above ===

prog2.py
# === code below ===

import os

cmd = 'python prog1.py'
os.system(cmd)

# === code above ===

星期三, 8月 05, 2009

How to transfer tuple to list

tuple 無法修改, 要修改其中的 element 就要使用 list. 把 tuple 轉為 list:

a = (1,2,3)
al = list(a)

就這麼簡單...

星期五, 6月 19, 2009

C++ Builder 中的 SysErrorMessage( )

把 GetLastError() 的 Error Code 轉為可閱讀的訊息.

Example:

dwErrorCode = GetLastError();
ShowMessage(SysErrorMessage(dwErrorCode));

星期一, 6月 08, 2009

蘇杭點心店

時間: 2009/6/7
地點: 台北市
老婆在師大附中考完試了, 請出 Mi 阿姨看看附近有什麼好吃的.
嗯... 蘇杭點心店 (台北市羅斯福路二段14號), 沒有突出馬路的招牌,
錯過了一次,再繞一圈才找到!點了小籠包 (讚),炒年糕,還有蟹殼黃...
中午人很多,老婆說下次經過還要再去吃... 值得推薦的一家店..



星期日, 5月 31, 2009

備份 VirtualBox Machine

使用指令:
VBoxManage clonevdi source destination
example:
VBoxManage clonevdi ~/.VirtualBox/HardDisks/WinXP.vdi ~/WindowsXP_Backup.vdi

參考:
How To: Properly Backup a VirtualBox Machine (.VDI)

星期四, 4月 23, 2009

python to exe

. 使用 py2exe (官網 : http://www.py2exe.org/)
. 建立下列程式來轉換 (命名為 setup.py)

from distutils.core import setup
import py2exe

setup(console=['hello.py']) #hello.py 就是要轉換的 .py 檔

.下一步在 cmd line 下執行
d:\> python setup.py py2exe
.轉換完成會產生一個 dist 的目錄, 在該目錄中就會有相對應的 exe 檔及 dll.

星期三, 4月 22, 2009

PDFedit

在 linux 上的一個 pdf editor , 可以直接修改 pdf 檔。
官方網站:
http://pdfedit.petricek.net/index_e.html