2009年7月15日 星期三

安裝 apache2, TinyC, php, sqlite

1. 下載 apache2 for windows: http://httpd.apache.org/download.cgi
2. 下載 php for windows: http://www.php.net/downloads.php
3. 下載 TINYC compiler: http://bellard.org/tcc/
4. 下載 SQLITE: http://www.sqlite.org/download.html
5. 下載 sqlodbc: http://www.ch-werner.de/sqliteodbc/

2009年7月8日 星期三

octave 呼叫 DLL

/* http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
to compile, type
>mkoctfile calldll.cc
*/
// calldll.cc
#include "octave/oct.h"
#include "windows.h"
#include "stdio.h"
typedef void (*helloDLL)(char *in,char *out,int n);

DEFUN_DLD (calldll, args, nargout, "An example to call DLL\n")
{
HINSTANCE hDLL; // Handle to DLL
helloDLL hello;
octave_value_list OctRet;
static char ret[1024];
hDLL = LoadLibrary((LPCSTR)"Project1.dll"); // load dll
if( hDLL != NULL)
{
hello = (helloDLL) GetProcAddress(hDLL, "hello");
hello("send parameter",ret,0);
OctRet(0)="OK";
FreeLibrary(hDLL);
}
return OctRet;

}

用 Dev C++ 寫簡單的 DLL程式

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include "windows.h"
#include "stdio.h"
extern "C"
{
DLLIMPORT void hello(char *in,char *out,int n);
}

DllClass::DllClass() { }
DllClass::~DllClass () { }
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}

DLLIMPORT void hello(char *in,char *out,int n)
{
int i;
printf ("DLL Hello %s\n",in);
out[0]='Y';
}

Octave's hello world

今天貼一個在 OCTAVE 上用 C 來寫程式
Octave 是一個數學運匴軟體,相當好用, 功能類似 matlab, 但它是自由軟體.學工程的決不能錯過, 且灌完後內建 C++ compiler, 可以用 C 來寫程式, 用 mkoctfile 來 complie, 之後會產生 .oct 檔, 該檔便可直接在命令列上呼叫, 如果要移除已載入的 .oct 程式, 可以下命令 clear all 或 clear 該oct 檔名即可

/*
Refer to URL: http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
use following syntax to compile under octave command line:
> mkoctfile hello.cc
Then it will generate a OCT file called hello.oct in the same directory
type
> p=hello
will execute the program, and the return message will be stored to variable 'p'
type
> help hello
will display the help message about the hello
In the end, it will return a string "OK" back to octave
type
>clear all
or
>clear hello
will unload the oct file
*/

// hello.cc
#include "octave/oct.h"
#include "windows.h"
#include "stdio.h"
DEFUN_DLD(hello,args,nargout,"Hello world\n")
{
octave_value_list OctRet;
printf("This is OCT file\n");
OctRet(0)="OK";
return OctRet;
}

2009年7月7日 星期二

奇怪, 這個 Blog 會將 tag 移除, 每改一次,就少了一些文字, 真是有夠怪?
想貼 php 原始碼都無法忠於原著, 放棄貼全部原碼, 只能貼部份, 因 function OTCstockmatch($match,$fin) 內含 html 的 tag, 會被該網站濾除, 就不貼了. 簡單來講利用 fgetcsv ($fin) 抓出資料, 再比對字串, 如果符合就將該筆資料的欄位內容抓出來, 利用 html 語法將它顯示到 browser 上,

function OTCstockprint($fin)
{
echo '資料來源:證券櫃檯買賣中心';
OTCstockmatch('名稱',$fin);
OTCstockmatch('聯勝',$fin);
echo '
';
}


if( 0 ) { $filename="emgstk.csv"; $fin=fopen($filename,"w+t");}
else $fin= tmpfile();
if( $fin )
{
$ch = curl_init();
if( $ch )
{
curl_setopt($ch, CURLOPT_URL,"http://nweb.otc.org.tw/emgstk/ch/emgstk.csv");
curl_setopt($ch, CURLOPT_FILE,$fin);
curl_exec($ch);
curl_close($ch);
OTCstockprint($fin);
}
fclose($fin);
}
?>

用 php 分析興櫃股票資訊

興櫃股票最新行情,檔案可以輕易自證券櫃檯買賣中心抓取,
URL 為 http://nweb.otc.org.tw/emgstk/ch/emgstk.csv
利用啟用 php CURL 外掛(在 php.ini 檔內 extension=php_curl.dll 的注解 ';' 移除即可),
稍作分析後只秀出自己關心的股票,程式碼如上

2009年4月13日 星期一

4/12刪