PHP Coding Standards

參考: Mantis : http://www.mantisbt.org/guidelines.php

中文翻譯: http://www.ichiayi.com/wikipage/tech/mantis_coding

First, start off by reading the PHP Coding Standards document. I’ve deviated in a few places but just about everything in the document applies here as well.

Above all, write code that is easy to read and maintain. Comment blocks of code and functions at all times. And get on my case if I deviate too much as well!

Naming Variables
  • Use all lower case.
  • Use _ to separate words, e.g. $green_color_value
  • Use descriptive names (except loop variables).
  • Loop variables can be of the usual variety: $i, $j, $k, etc.
  • Count variables should follow the format $*_count, e.g. $bug_count
  • Global variables should be prefixed with g_
  • Temporary variables should be prefixed with t_
  • Parameters and variables passed from forms that have been cleaned of any special SQL chars (i.e. slashes) should be prefixed with c_
  • Uncleaned function parameters should be prefixed with p_
  • Uncleaned variables passed from forms should be prefixed with f_
  • Other variables are prefixed with v_, v2_, etc.
  • Never prefix with l_ or o_ or q_ (visually confusing)
  • $query and $result should be used for SQL query and results respectively
Naming Functions
  • Use all lower case.
  • Use _ to separate words, e.g. setup_page_breaks()
  • Keep functions to 5 words or less
  • Functions that print should be prefixed with print_.
  • Try to use prefixes to group functions (i.e., email_, news_, etc.)
Naming Classes
  • Use FirstLetterOfWordIsCaptilized style
  • Variables that are class objects should have the prefix coo_
Naming Files
  • Use all lower case.
  • Use _ to separate words, e.g. view_new_bugs_page.php
  • Use .php file extensions
  • Filenames must be less than 32 characters in length. This plays nice with older file systems like Mac OS.
  • Included files should be suffixed by _inc.php
SQL formatting
  • UPPERCASE all SQL keywords:
    $query = "SELECT *
    	FROM $g_mantis_bug_table
    	WHERE id='1'";
  • Always assign a query string to a variable. This makes code easier to debug when problems occur. Do not create the query in the call to the function.
  • Break up SQL queries over multiple lines to be easy to read.
General Formatting
  • Use TABS with a size of 4
  • Follow the table formatting of existing pages
  • Use <?php ?> for php delimiters.
  • Try not to print/echo HTML unless it’s short or in a function loop
  • Do not use the EOF construct
Miscellaneous
  • Don’t use the ?: construct except in very rare cases. It is confusing and has a lot of bug potential.
  • Avoid magic numbers. The only magic numbers in use should be 1 and 0 and their meaning should be obvious.
Page Guidelines
  • The first item should be the copyright notice
  • At the bottom will be the footer information and closing print_ functions.
Braces and Parantheses
  • Parantheses should be right after a function name, e.g. function() not function ()
  • Parantheses should have a space right after a keyword (if, while, for), e.g. for (…)
  • Formatting of braces is illustrating below. We use unmatched placing.
  • Arrays should be referenced with no spaces, e.g. $arr[‘index’] not $arr[ ‘index’ ]
    for (...) {
        blah
    }
    
    or
    
    if (...) {
        blah
    }
  • if … else blocks should be in this format:
    if (...) {
        blah1
    } else {
        blah2
    }
Comparisons
  • The NOT operator should be placed next to its operand. No spaces, e.g. !$value
  • Parentheses should be used for grouping, especially with multiple comparisons, e.g. if ( ( null == $val ) && ( null == $val2 ) )
Strings
  • Use spaces around the string concatenation operator, e.g. ‘str ‘ . $value . ‘ str2’;
  • Use ‘ instead of " if there are no variables or special characters.
Comments
  • Use the # symbol for line commenting, not //
  • Use /* */ for block commenting unless you nest /* */ comments. Generally, only use this during development.
  • Use @@@ followed by a brief message (BROKEN, TEMPORARY, etc) as a "look at this" indicator. Leaving your name next to is a good idea. This way critical items can easily be found.
Editor Features
  • Search and replace in multiple files
  • Goto line number
  • Syntax highlighting
  • Adjustable TAB spacing

2009 蘭陽海上長泳 – 迎向龜山 / 烏石港

2009 蘭陽海上長泳 – 迎向龜山團報
日期 : 98年5月31日[星期日]
地點 : 頭城鎮烏石港北堤 延著岸邊往北游 1500公尺 折返
總共游泳距離約3000公尺
報名到4/20止(5人以上組隊報名)

下圖是 2008年游的路徑(淡藍色) , 白線是 3000M 龜山島的直線距離(如果要游到龜山島的話要游約9-11公里).

affe2987da981aa7a3d898f9b03a21e2

get my ip address useing c / sample code

C CODE

902c2c377de669ec360e37664cc1f041

/*
  FILENAME : my_local_ip.c
*/
#include
#include
#include
#include
#include
#include
#include
#include 

int main(int argc, char **argv) {
  int s;
  struct sockaddr_in sin;
  int slen;
  int port;

  if( argc<3 ) {
    printf("Usage: %s  \n", argv[0]);
    printf("\n\tsample %s 203.66.88.89 80\n",argv[0]);
    return -1;
  }

  port = atoi(argv[2]);

  s = socket(PF_INET, SOCK_STREAM, 0);
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = PF_INET;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = inet_addr(argv[1]);
  if(connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    printf("127.0.0.1");
    return -1;
  }

  memset(&sin, 0, sizeof(sin));
  slen = sizeof(sin);
  if(getsockname(s, (struct sockaddr *)&sin, &slen) < 0) {
    printf("127.0.0.1");
    close(s);
    return -1;
  }

  printf("%s", inet_ntoa(sin.sin_addr));

  close(s);
  return 0;
}

可以依自己的需求來改這SHELL:

#!/bin/sh
ADDR=`my_local_ip 168.95.1.1 53`
FILENAME=${ADDR=}".txt"

echo $FILENAME

oci / compile php with oracle instant client

小筆記一下…

oracle 那邊 download 這幾個 file

-rw-rw-r– 1 root portage 44414338 Feb 24 13:41 instantclient-basic-linux32-11.1.0.7.zip
-rw-rw-r– 1 root portage   607196 Feb 24 13:41 instantclient-sdk-linux32-11.1.0.7.zip

放到 /usr/portage/distfiles 這底下

然後 PHP 是這麼編的

USE="apache2 berkdb bzip2 calendar cjk cli crypt curl gd gdbm hash iconv json mysql mysqli ncurses nls oci8-instant-client pcre readline reflection session simplexml spell spl ssl truetype unicode xml zlib" emerge -av php

Microsoft Internet Explorer 8 / IE8 新功能 accelerator implement

 

參考這頁: http://msdn.microsoft.com/en-us/library/cc304163(VS.85).aspx

可以作出這樣的效果 , 這東西 microsoft 管它叫作 Internet Explorer 8 的 “新” 功能 – Accelerators

cbbf837d7ab99e765e0f1b3a5374674a

XML file:

.....
....
重點是 .... preview action="xxxxx" accept-charset="big5"
....

好了, 接下來是碎碎唸時間 …. 心得是 微軟老愛搞這種小玩意兒… 要用到此功能, 首先 user 必須要在網頁選取一段他感興趣的字, 然候再點旁邊出現的藍框 , 仔細找會有一個 所有的加速器 , 再移過去 會看到自己寫的 加速器 , 然後在加速器上要等一下下 , 才會出現 商品 preview , 然後整個過程手還不能發抖讓 mouse 游標跑掉 . . . 這功能有人要用才有鬼咧.

而且這東西要叫 “加速器” 才好笑, 用的過程囉唆的要命, 還要叫加速器??