Archive for July 2008

memcache sample code

簡單版的測試 sample code

[code language='php']

// filename : memcache.php

$memcache = new Memcache;
$memcache->addServer('172.20.50.25', 11211);

// set 一個值到 memcache

$memcache->set('key', time() , MEMCACHE_COMPRESSED, 120);

// get 值

$data=$memcache->get('key');
print_r($data);

Holux m-241 logger 的 KML data 匯出 , 用 excel 編輯後再轉回 KML

今天早上都在玩這個…
把 kml 檔案用 simplexml 讀出來 , 簡單分析了一下就知道座標跟高度等資料在那裡了,
接著用以下的程式把它轉出 csv 檔
[code language='php']
$string=file_get_contents("0816.kml");

$xml = simplexml_load_string($string);

printf("Name,Latitude,Longitude,Altitude,Dist,Description ,Icon,IconScale,IconAltitude,IconHeading, IconColor, LineStringColor,HideNameUntilMouseOver\n");

$icon="196";
$iconscale="0.2";
$iconaltitude=10;
$iconheading="line-180";
$iconcolor="yellow";
$linestringcolor="aqua";
$HideNameUntilMouseOver="true";

$cnt=0;
$t1=0;
$last_point=array();
$dist=0;
$total_dist=0;
$ignore_time=120; // 120 seconds
$ignore_dist=10; // 10 meters

foreach ($xml->Document->Folder->Placemark as $k=>$v) {
$point=explode(",",trim($v->Point->coordinates));
if ( $last_point[0] ) {
$dist=sqrt( pow(abs($point[0]-$last_point[0])*110.766417,2) + pow(abs($point[1]-$last_point[1])*110.766417,2) );
$dist*=1000;
} else {
$dist=0;
}
$total_dist+=$dist;
$last_point=$point;
if ( $point[2]name);
$timestamp=strtotime($str_time);
if ( ($timestamp-$t1)<$ignore_time &amp;&amp; $dist<$ignore_dist ) continue;
$t1=$timestamp;
printf("%s , ",date("H:i:s",$timestamp));
printf("%s , ",$point[1]);
printf("%s , ",$point[0]);
printf("%s , ",$point[2]);
printf("%s , ",$total_dist);
printf("NO.%d
%s
Altitude : %s M , ",$cnt++,$str_time,$point[2]);
printf("%s , ",$icon);
printf("%s , ",$iconscale);
printf("%s , ",$iconaltitude);
printf("%s , ",$iconheading);
printf("%s , ",$iconcolor);
printf("%s , ",$linestringcolor);
printf("%s , ",$HideNameUntilMouseOver);
printf("\n");
}[/code]

用 excel 把 csv 讀進來編輯, 一方面用 google earth 來對原來資料 , 看那邊停留久的 data
減少一些 , 再用這個 service 把 csv 轉回 KML 檔

Excel To KML – Display Excel files on Google Earth

今天(8/19)聽了 aska 的建議, 增加 “忽略” 時間跟距離的片段進去

今天(8/21)終於把這段程式改成可以給大家用的 service 了:
http://www.monster.com.tw/kml2csv

Monster All-In-One LAMP Pack 0726A ( package )

106乙 到坪林 , 台9

7/26 從家出發走 106乙 到坪林 , 台9 , 下滑到小格頭 , 新店回 , 總共 79K

Continue reading ‘106乙 到坪林 , 台9’ »

Protected: YUM的使用

This post is password protected. To view it please enter your password below:


Linux 的燒機程式

網址: http://sourceforge.net/projects/va-ctcs

抓下來解開, 打 make

編譯完就可以:
./newburn
開始燒機了…..

server 不穩的話不用跑多久就會 HANG 掉了…

screenrc

caption always "MONSTER %{bw}%0C%A %Y/%m/%d %LD %{wb} %-w%{Y}[%n %t]%{w}%+w%{k}"
activity "activity in %n (%t) [%w:%s]"

bind b encoding big5 utf8
bind u encoding utf8 big5

screen -t ROOT 0 bash
screen -t NET 8 bash
screen -t TOP 9 bash
screen -t WK1 1 bash
screen -t WK2 2 bash

Protected: Senna for mysql install 安裝說明

This post is password protected. To view it please enter your password below:


bike中社路+風櫃嘴

騎完中社路還不過癮, 繼續騎風櫃嘴
下滑風櫃嘴…我說 “god 一直拉煞車…手都快斷掉了”
黃同學說 “奇怪? 剛剛是怎麼騎上來的?”

今天還有一件豬頭事….帶了 logger 但就是忘記忘記按下開始記錄
看來要再來一次

裝了 SyntaxHighlighter Plus , 程式碼可以看清楚了

SyntaxHighlighter Plus

It supports the following languages (the alias for use in the post is listed next to the name):

* Bash — bash, sh
* C++ — cpp, c, c++
* C# — c#, c-sharp, csharp
* CSS — css
* Delphi — delphi, pascal
* Java — java
* JavaScript — js, jscript, javascript
* PHP — php
* Python — py, python
* Ruby — rb, ruby, rails, ror
* SQL — sql
* VB — vb, vb.net

* XML/HTML — xml, html, xhtml, xslt

修改 … /wp-content/plugins/syntaxhighlighter-plus/shlfiles/SyntaxHighlighter.css
把 .dp-highlighter 的 width 改成想要的寬度

[code language=C]
#include
main() {
printf("Hello World!");
}

[/code]

test

[code language=php]
function foo() {
  echo "Hello World!\\n";
}
[/code]

設定 .htaccess 讓 網址比較短

CodeIgniter – Open source PHP web application framework

設定 .htaccess 讓 網址比較短

codeigniter 網頁提到
http://codeigniter.com/user_guide/general/urls.html

可以把www.your-site.com/index.php/news/article/my_article
變成
www.your-site.com/news/article/my_article

步驟:
改 apache 的 virtual host file
Options FollowSymLinks
在 /xxx/username/ci/ 下建 .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ /rimmon/ci/index.php/$1 [L]
</IfModule>

check email 存不存在

if ($_SERVER[argc]<2) {
  printf("Usage : %s filename\n",$_SERVER['argv'][0]);
  exit;
}

$filename=strftime("%H%M.txt");
$out=fopen($filename,"a");

$counter=0;
$fp=fopen($_SERVER['argv'][1],"r");
while ($data=fgets($fp,2000)) {
  $data=str_replace("\r","",$data);
  $data=str_replace("\n","",$data);
  if (checkmail($data)==TRUE) {
    printf("%s : %s \tGOOD_EMAIL!\n",$counter,$data);
    fputs($out,$data."\n");
  } else printf("%s : %s \tBAD_EMAIL!\n",$counter,$data);
  $counter++;
}
fclose($fp);
fclose($out);
exit;

// -------

function checkmail($mail){
  $host = explode('@',$mail);
  list($account,$host) = $host;

  if (!getmxrr($host,$mxa)) $mxa = array($host);
  while (list ($key, $mx) = each($mxa)) {
    if ($mxg = @fsockopen ($mx,25,$ir,$sr,5)) {
      $out = fgets($mxg, 1024);
      if (substr($out,0,3) == "220") {
        fputs ($mxg, "HELO example.com\r\n");

        $out = fgets ( $mxg, 1024 );
        fputs ($mxg, "MAIL FROM: <{$mail}>\r\n");
        $from = fgets ( $mxg, 1024 );
        fputs ($mxg, "RCPT TO: <{$mail}>\r\n");
        $to = fgets ($mxg, 1024);
        fputs ($mxg, "QUIT\r\n");
        fclose($mxg);
        if (ereg ("^250", $from) && ereg ( "^250", $to )) return TRUE;
        return FALSE;
      }
      return FALSE;
    }
    return FALSE;
  }
  return FALSE;
}

用 apache 的 setenv module 在程式中加入判斷 developer 是誰

<VirtualHost 172.30.0.35:80>
        ServerName rimmon.goods.dev.xxx.com.tw
        ServerAdmin webmsater@staff.xxx.com.tw
        DocumentRoot /home/rimmon/bid/goods/www
        SetEnv DEVELOPER rimmon
        alias /js/ /home/rimmon/bid/www/www/js/
        alias /css/ /home/rimmon/bid/www/www/css/
        <Directory “/home/rimmon/bid/goods/www”>
          Options  FollowSymLinks
          AllowOverride None
          Allow from all
        </Directory>
</VirtualHost>

[sparc] solve gentoo blocking problem

emerge -pv
……
[ebuild     U ] app-shells/bash-3.2_p33 [3.1_p17] USE=”nls -afs -bashlogger
-plugins% -vanilla” 2,564 kB
[blocks B     ] <sys-apps/portage-2.1.4_rc1 (is blocking
app-shells/bash-3.2_p33)
[blocks B     ] sys-apps/mktemp (is blocking sys-apps/coreutils-6.10-r2)
[blocks B     ] >=sys-apps/coreutils-6.10 (is blocking sys-apps/mktemp-1.5)
emerge -1 =bash-3.2_p17*
emerge -1 portage
emerge -1 bash
emerge -C mktemp
emerge -C sys-apps/util-linux
emerge –oneshot coreutils

emerge -1 sys-apps/util-linux

Q. mysql 的 store procedure 能看得到嗎?

看有那些 procedures
SHOW PROCEDURE STATUS

看該 procedure 的內容
SHOW CREATE PROCEDURE

SHOW PROCEDURE STATUS and SHOW FUNCTION STATUS Syntax

ncurses sample

A Simple scanw example

compile:

gcc sample.c -lncurses

[code language='c']
#include /* ncurses.h includes stdio.h */
#include

int main()
{
char mesg[]="Enter a string: "; /* message to be appeared on the screen */
char str[80];
int row,col; /* to store the number of rows and *
* the number of colums of the screen */
initscr(); /* start the curses mode */
getmaxyx(stdscr,row,col); /* get the number of rows and columns */
mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
/* print the message at the center of the screen */
getstr(str);
mvprintw(LINES - 2, 0, "You Entered: %s", str);
getch();
endwin();

return 0;
}
[/code]

Protected: [貼] 架設大型網站密技

This post is password protected. To view it please enter your password below:


改 mysql 欄位寬

 ALTER TABLE `tbl_item` CHANGE `objno` `objno` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL 

完成 2008 統一盃 鐵人三項

成績:

SWIM : 41分1秒

BIKE : 1小時54分10秒

RUN : 1小時1分整

總成績: 3小時36分10秒

Continue reading ‘完成 2008 統一盃 鐵人三項’ »