preload
Mar 29


程式名稱為My fone


載入畫面


操作畫面.

請台灣大哥大的朋友幫忙到 http://liho.tw/fone/測試.
我認為應該有很多錯誤. 因為我不熟台灣大哥大的規則.
如果您知道有計算上的錯誤請您告訴我.謝謝.

有點小累, 先這樣.晚點再補齊.

Tagged with:
Mar 28
1
2
3
4
5
6
7
<?
mb_internal_encoding('UTF-8');
$output =  "123中文測試...";
$pos = mb_strpos($output, "中文");
$output = substr($output, $pos);
echo $output;
?>

上面執行結果為 :

中文測試…

Tagged with:
Mar 28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?
$webpage = $_GET["w"];
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $webpage);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
$output = curl_exec($ch);
 
curl_close($ch);
 
echo iconv("Big5", "UTF-8", $output);
?>
Tagged with:
Mar 24

今天晚上臨時想寫個節費程式. 這樣就可以算到底還有多少通簡訊可以傳. 到底還有幾分鐘通話可以使用. 目前這隻程式還算很陽春. 最好是能夠直接登入emome然後把資料撈回來. Orz 就不用輸入那些有的沒有的通話及簡訊費用了.

畫面大概如下 :


程式名稱為My mPro


載入畫面


大家講使用畫面


元氣型使用畫面


基本型使用畫面

請用iPhone瀏覽 : http://liho.tw/mpro/ 頁面. 記得加入主畫面(Home Screen).
在使用這個節費程式前, 先到 emome 註冊你的帳號. 然後進入我的帳單網頁查詢您的未出帳的資訊. 在進去 My mPro 程式計算目前剩餘通話量.

Tagged with:
Jan 20
1
2
NSDictionary *playerInfo = [aNotification userInfo];
NSLog(@"%@", playerInfo);

我很好奇這個 NSDictionary 裡面裝了什麼膏藥? 就用NSLog幫忙揭開神祕的面紗 :

Album = “In the Enchanted Garden”;
“Album Rating” = 0;
“Album Rating Computed” = 1;
Artist = “Kevin Kern”;
“Artwork Count” = 1;
Genre = “New Age”;
“Library PersistentID” = “-8755280181446606464″;
Location = “file://localhost/Users/xxxxx/Music/iTunes/iTunes%20Music/Kevin%20Kern/In%20the%20Enchanted%20Garden/07%20Water%20Lilies.mp3″;
Name = “Water Lilies”;
PersistentID = 8747019994823533665;
“Play Count” = 0;
“Play Date” = “2040-02-06 06:28:16 +0800″;
“Player State” = Playing;
“Playlist PersistentID” = “-8755280181446606453″;
“Rating Computed” = 1;
“Skip Count” = 0;
“Skip Date” = “2040-02-06 06:28:16 +0800″;
“Store URL” = “itms://itunes.com/link?n=Water%20Lilies&an=Kevin%20Kern&pn=In%20the%20Enchanted%20Garden”;
“Total Time” = 257802;
“Track Count” = 10;
“Track Number” = 7;
Year = 1996;

另外, 還可以用下列方式

NSString *strOutput = [NSString stringWithFormat:@"%@", playerInfo];

NSString *strOutput = [playerInfo description];

Tagged with:
Jan 13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(int argc, char *argv[])
{
    [NSThread detachNewThreadSelector:@selector(checkiTunesStatus) toTarget:self withObject:nil];
}
 
- (void) checkiTunesStatus
{	
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	while (pTunesRun) {
		[NSThread sleepForTimeInterval:1.0];
	}
	[pool release];
	[NSThread release];
}

這個程式在一般的Application執行沒問題. 但是寫成 widget plugin就死翹翹了. 先自己記錄起來.之後再用這個 codes.

Tagged with:
Nov 10

I’m going to use the Google Mini pdf file as this demonstration. Please download that file to the same directory of your php script in advance. Check it out here. You can see how GOOD Google did the document preview function is. Of course, I’m not as well as Google’s experts. But, I just knew a small trick.

我將使用Google Mini pdf 檔案進行這個範例解說. 請先將這個檔案下載到你的php程式相同目錄. 按這裡. , 你可以先看看 Google 的 document preview 的功能已經相當完善. 當然, 我不像 Google 的專業人士那麼厲害. 但是, 我知道一點小技巧.

Before you start to generate pdf file preview, you need to make sure your system is installed the GhostScript and the ImageMagick.

在開始產生pdf預覽前, 你先在你的系統安裝 GhostScriptImageMagick程式.

Following php script to generate thumbnails pdf files:
下列php程式碼會產生縮圖:

1
exec('/usr/bin/convert "googlemini_datasheet.pdf" -geometry 200 "googlemini_thumbnails.png"');

Output :

file name : googlemini_thumbnails-0.png


file name : googlemini_thumbnails-1.png

Following php script to generate large pdf files:
下列php程式碼會產生大圖:

1
exec('/usr/bin/convert "googlemini_datasheet.p22df" -density 1200x1200 -geometry 1024 -quality 100 "googlemini_large.png"');

Output :

file name : googlemini_large-0.png


file name : googlemini_large-1.png

From above php scripts, you can see the convert command generated two png files. Because, the Google Mini pdf file has two pages. If there are many pages in pdf file, It will be generated some file name with “-0″, “-1″, “-2″, “-3″ and so on.

從上列php程式碼, 你可以了解 convert 指令幫你產生了兩張 png 圖. 因為那個 Google Mini pdf 檔案有兩頁. 如果pdf檔案有很多頁面, 那會產生”-0″, “-1″, “-2″, “-3″…等.

If you would like to generate the first page, you can use following php script:
如果你只想產生第一頁, 你可以使用下列php程式.

1
exec('/usr/bin/convert "googlemini_datasheet.pdf[0]" -geometry 200 "googlemini_page1.png"');

Just add the [0] after the pdf file name. How about the second page? Just change inside number of [ ] from 0 to 1.

只要在pdf檔案後面加入[0]就可以了. 那如果要只輸出第二頁? 只要改變 [ ] 裡面的數子. 從 0 到 1.

References :

Tagged with:
Sep 19

建立 rrd 檔案. 然後更新溫度資訊到 rrd 檔案內 :
initial rrd file and update temperature into rrd file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// update.php
$rrd_file = "r733.rrd";
 
function init_rrd() {
    global $rrd_file;
 
    $opts = array("--step", "300", "--start", 0,
                 "DS:Battery:GAUGE:600:1:100",
                 "DS:EMU:GAUGE:600:1:100",
                 "RRA:AVERAGE:0.5:1:600",
                 "RRA:AVERAGE:0.5:6:700",
                 "RRA:AVERAGE:0.5:24:775",
                 "RRA:AVERAGE:0.5:288:797",
                 "RRA:MAX:0.5:1:600",
                 "RRA:MAX:0.5:6:700",
                 "RRA:MAX:0.5:24:775",
                 "RRA:MAX:0.5:288:797");
    $rtn = rrd_create($rrd_file, $opts, count($opts));
 
    if ($rtn == 0) {
        $err = rrd_error();
        exit("ERROR : $err\n");
    }
 
} // end function init_rrd()
 
function update_rrd() {
    global $rrd_file;
    $battery_cmd = "/usr/bin/snmpwalk -v 1 -c tiara_pub 192.168.170.250 1.3.6.1.4.1.318.1.1.1.2.2.2.0";
    $emu_cmd = "/usr/bin/snmpwalk -v 1 -c tiara_pub 192.168.170.250 1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1";
    $flag = true;
 
    while($flag) {
        $battery_temperature = "";
        $emu_temperature = "";
        while($battery_temperature == "") {
            $output = shell_exec($battery_cmd);
            $battery_temperature = trim(str_replace("SNMPv2-SMI::enterprises.318.1.1.1.2.2.2.0 = Gauge32:", "", $output));
            if ($battery_temperature == "") sleep(5);
        }
 
        while($emu_temperature == "") {
            $output = shell_exec($emu_cmd);
            $emu_temperature = trim(str_replace("SNMPv2-SMI::enterprises.318.1.1.10.2.3.2.1.4.1 = INTEGER:", "", $output));
            if ($emu_temperature == "") sleep(5);
        }
        $battery_temperature = (int)$battery_temperature;
        $emu_temperature = (int)$emu_temperature;
        $rtn = rrd_update($rrd_file, "N:$battery_temperature:$emu_temperature");
        if ($rtn == 0) {
            $err = rrd_error();
            exit("ERROR : $err\n");
        }
 
        if (isset($_GET["t"])) {
            sleep(300);
        } else {
            $flag = false;
        }
    } // end while(true)
 
} // end function update_rrd()
 
if (file_exists($rrd_file)) {
    update_rrd();
} else {
    init_rrd();
    update_rrd();
}

畫 rrd 圖 :
draw rrd graphs :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// index.php
$rrd_file = "r733.rrd";
 
include_once "update_r733.php";
 
function draw_rrd() {
    global $rrd_file;
 
    $opts = array( "--start", "-1h", "--vertical-label=deg C", "--title=R733 Temperature last hour",
                   "DEF:battery=".$rrd_file.":Battery:AVERAGE",
                   "DEF:emu=".$rrd_file.":EMU:AVERAGE",
                   "COMMENT:                                           Max    Average    Last\\n",
                   "AREA:battery#99CC00:Battery \:",
                   "GPRINT:battery:MAX:%2.0lfdeg C",
                   "GPRINT:battery:AVERAGE:%2.0lfdeg C",
                   "GPRINT:battery:LAST:%2.0lfdeg C\\r",
                   "LINE2:emu#6699CC:EMU \:",
                   "GPRINT:emu:MAX:%2.0lfdeg C",
                   "GPRINT:emu:AVERAGE:%2.0lfdeg C",
                   "GPRINT:emu:LAST:%2.0lfdeg C\\r"
               );
 
    $ret = rrd_graph("r733_1h.gif", $opts, count($opts));
 
    if(!is_array($ret)) {
        $err = rrd_error();
        exit("draw_rrd() ERROR: $err\n");
    }
 
    $opts = array( "--start", "-1d", "--vertical-label=deg C", "--title=R733 Temperature last day",
                   "DEF:battery=".$rrd_file.":Battery:AVERAGE",
                   "DEF:emu=".$rrd_file.":EMU:AVERAGE",
                   "COMMENT:                                           Max    Average    Last\\n",
                   "AREA:battery#99CC00:Battery \:",
                   "GPRINT:battery:MAX:%2.0lfdeg C",
                   "GPRINT:battery:AVERAGE:%2.0lfdeg C",
                   "GPRINT:battery:LAST:%2.0lfdeg C\\r",
                   "LINE2:emu#6699CC:EMU \:",
                   "GPRINT:emu:MAX:%2.0lfdeg C",
                   "GPRINT:emu:AVERAGE:%2.0lfdeg C",
                   "GPRINT:emu:LAST:%2.0lfdeg C\\r"
               );
 
    $ret = rrd_graph("r733_1d.gif", $opts, count($opts));
 
    if(!is_array($ret)) {
        $err = rrd_error();
        exit("draw_rrd() ERROR: $err\n");
    }
 
    $opts = array( "--start", "-1w", "--vertical-label=deg C", "--title=R733 Temperature last week",
                   "DEF:battery=".$rrd_file.":Battery:AVERAGE",
                   "DEF:emu=".$rrd_file.":EMU:AVERAGE",
                   "COMMENT:                                           Max    Average    Last\\n",
                   "AREA:battery#99CC00:Battery \:",
                   "GPRINT:battery:MAX:%2.0lfdeg C",
                   "GPRINT:battery:AVERAGE:%2.0lfdeg C",
                   "GPRINT:battery:LAST:%2.0lfdeg C\\r",
                   "LINE2:emu#6699CC:EMU \:",
                   "GPRINT:emu:MAX:%2.0lfdeg C",
                   "GPRINT:emu:AVERAGE:%2.0lfdeg C",
                   "GPRINT:emu:LAST:%2.0lfdeg C\\r"
               );
 
    $ret = rrd_graph("r733_1w.gif", $opts, count($opts));
 
    if(!is_array($ret)) {
        $err = rrd_error();
        exit("draw_rrd() ERROR: $err\n");
    }
 
    $opts = array( "--start", "-1m", "--vertical-label=deg C", "--title=R733 Temperature last month",
                   "DEF:battery=".$rrd_file.":Battery:AVERAGE",
                   "DEF:emu=".$rrd_file.":EMU:AVERAGE",
                   "COMMENT:                                           Max    Average    Last\\n",
                   "AREA:battery#99CC00:Battery \:",
                   "GPRINT:battery:MAX:%2.0lfdeg C",
                   "GPRINT:battery:AVERAGE:%2.0lfdeg C",
                   "GPRINT:battery:LAST:%2.0lfdeg C\\r",
                   "LINE2:emu#6699CC:EMU \:",
                   "GPRINT:emu:MAX:%2.0lfdeg C",
                   "GPRINT:emu:AVERAGE:%2.0lfdeg C",
                   "GPRINT:emu:LAST:%2.0lfdeg C\\r"
               );
 
    $ret = rrd_graph("r733_1m.gif", $opts, count($opts));
 
    if(!is_array($ret)) {
        $err = rrd_error();
        exit("draw_rrd() ERROR: $err\n");
    }
 
    $opts = array( "--start", "-1y", "--vertical-label=deg C", "--title=R733 Temperature last year",
                   "DEF:battery=".$rrd_file.":Battery:AVERAGE",
                   "DEF:emu=".$rrd_file.":EMU:AVERAGE",
                   "COMMENT:                                           Max    Average    Last\\n",
                   "AREA:battery#99CC00:Battery \:",
                   "GPRINT:battery:MAX:%2.0lfdeg C",
                   "GPRINT:battery:AVERAGE:%2.0lfdeg C",
                   "GPRINT:battery:LAST:%2.0lfdeg C\\r",
                   "LINE2:emu#6699CC:EMU \:",
                   "GPRINT:emu:MAX:%2.0lfdeg C",
                   "GPRINT:emu:AVERAGE:%2.0lfdeg C",
                   "GPRINT:emu:LAST:%2.0lfdeg C\\r"
               );
 
    $ret = rrd_graph("r733_1y.gif", $opts, count($opts));
 
    if(!is_array($ret)) {
        $err = rrd_error();
        exit("draw_rrd() ERROR: $err\n");
    }
} // end function draw_rrd()
 
draw_rrd();
 
?>
<img src="r733_1h.gif"><br>
<img src="r733_1d.gif"><br>
<img src="r733_1w.gif"><br>
<img src="r733_1m.gif"><br>
<img src="r733_1y.gif">

在 linux 內執行 curl http://xxx.liho.tw/temperature/update.php & 這樣就可以每 300 秒回報一次溫度.

展示畫一天的溫度的rrd圖 :

Tagged with:
Jun 11

程式碼如下 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <gtk/gtk.h>
 
static void destroy(GtkWidget *widget, gpointer data) {
    gtk_main_quit();
}
 
int main(int argc, char *argv[]) {
    GtkWidget *window;
    GtkWidget *label;
 
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
    label = gtk_label_new("hello world");
    gtk_container_add(GTK_CONTAINER(window), label);
    gtk_container_set_border_width(GTK_CONTAINER(window), 15);
    gtk_window_set_title(GTK_WINDOW(window), "hello world");
    gtk_widget_show(label);
    gtk_widget_show(window);
    gtk_main();
 
    return 0;
}

這是執行結果 :

GTK+我不是那麼懂! 還是初學者.請多多指教!

參考 : GTK+ 2.0 Tutorial

Tagged with:
Jun 04

下面這個. 會把輸出儲存在$output

1
2
$cmd = "ls -l";
$output = shell_exec($cmd);

還有另外一種作法用 system function . 這個在執行過程就會直接顯示出來.

1
2
$cmd = "ls -l";
$output = system($cmd, $retval);
Tagged with: