手上的幾個東西

NTRPG 用的是 wordpress + vbulletin , 都是很古老的版本, 雖然 NT 已經沒什麼人去看, 也沒什麼人去論壇發言了, 但是還是想做一套自己的系統. 爭取2010 年能完成 (已經拖了2年了, 從起初的 PHP 到現在的 RoR). 可能還要加一些其他的功能, 比如 game library, twitter 等等.

雖然 wordpress 已經很好很強大了, 但是發現基本上我只用到了10%-20%的東西, 覺得也沒必要, 不如也自己寫一個出來, 我的程序猿之心正在燃燒

除了目前在看的 RoR 之外, 還想學習下 Python/Django 和 Objective-C/Cocoa .

PHP 截取英文單詞時保持單詞不斷開

有時候要 substr 一段文字, 如果直接使用 substr 會出現單詞斷開的現象, 利用 word wrap 可以簡單的保證單詞不斷開

$long_str = ""; //你需要截取的文字
$str_limit = 150; // 你需要截取的文字長度
$break_sign = "<!-- word break -->"; //用來區分段落分段, 可以用任何和你要截取的內容不衝突的字段
$str = substr($str=wordwrap($long_str, $str_limit, $break_sign), 0, strpos($str, $break_sign)); //截取

這樣就不會單詞斷開了.
先利用 wordwrap 把文字分段, 然後 strpos 定義斷開符號的位置, 然後截取斷開符號之前所有的文字.

Tags: , , ,

MySQL – Access Denied for user root@localhost 解決辦法

在 /etc/my.cnf 內加入一行

skip-name-resolve

via http://bugs.mysql.com/bug.php?id=22118

Tags:

Mac Snow Leopard 下 ror 和 mysql 的問題

運行 script/server
點擊 About your application’s environment
發生錯誤, terminal 裡提示說 mysql 錯誤, 嘗試通過 gem install mysql 命令安裝,結果出錯

terminal 下運行這個命令解決

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

可以考慮先刪除下

gem uninstall mysql

New Project

乘著還年輕,有衝動,準備弄點東西…

雖然1年多前就想過了,一直偷懶沒動手,這次不知道會不會衝到3秒后又放棄…

但是衝動是必須的! 握拳!

function backup – xml recursive generation

	/**
	 * generate xml file
	 *
	 * @return xml result
	 * @author Jay
	 **/
	function _get_xml($result)
	{

		$doc = new DOMDocument('1.0', 'UTF-8');
		$doc->formatOutput = true;

		$root = $doc->createElement('REIWA_Import');
		$doc->appendChild($root);

		$this->_get_node($doc, $root, $result);

		echo $doc->saveXML();
		$doc->save($this->output);
	}

	/**
	 * recursive generate xml function
	 *
	 * @return void
	 * @author Jay
	 **/
	function _get_node($doc, $parent_node, $left_array)
	{
		foreach ($left_array as $key=>$value) {
			if (!eregi("_attr", $key)) {
				if (is_numeric($key)) {
					if (!$parent_node->hasChildNodes()) {
						$node = $parent_node;
					} else {
						$node = $parent_node->cloneNode(false);
						$parent_node->parentNode->appendChild($node);
					}
				} else {
					$node = $doc->createElement($key);
					$parent_node->appendChild($node);
				}
				if (is_array($value)) {
					/**
					 * recursive !!!
					 **/
					$this->_get_node($doc, $node, $value);
				} else {
					if (strlen($value)) {
						$nodeValue = $doc->createTextNode($value);
						$node->appendChild($nodeValue);
					}
					if (sizeof($left_array[$key."_attr"])) {
						foreach ($left_array[$key."_attr"] as $attrKey=>$attrValue) {
							$attrs = $doc->createAttribute($attrKey);
							$attrsValue = $doc->createTextNode($attrValue);
							$attrs->appendChild($attrsValue);
							$node->appendChild($attrs);
						}
					}
				}
			}
		}
	}

cloneNode, parentNode, hasChildNodes()

array structure:

Array
(
    [Agent_Section] => Array
        (
            [AgencyID] => integer
            [BranchID] => integer
            [AgencyBranchName] => string
            [TransmissionTime] => date
            [XMLVersion] =>
            [XMLVersion_attr] => Array
                (
                    [Type] => type
                )

            [StatusEmailAddress] => email address
            [RemoteID] => string
        )

    [Rep_Section] => Array
        (
            [0] => Array
                (
                    [FirstName] => string
                    [LastName] => string
                    [Mobile] => string
                    [CLIENT_RepRef] => string
                )

            [1] => Array
                (
                    [FirstName] => string
                    [LastName] => string
                    [Mobile] => string
                    [CLIENT_RepRef] => string
                )
        )

    [Property_Listing] => Array
        (
            [0] => Array
                (
                    [ListingCategory] =>
                    [ListingCategory_attr] => Array
                        (
                            [Type] => type
                        )

                    [UpdateTypeForSale] =>
                    [UpdateTypeForSale_attr] => Array
                        (
                            [Type] => type
                        )

                    [ListingType] =>
                    [ListingType_attr] => Array
                        (
                            [Type] => type
                        )

                    [AgentListingID] => string
                    [CLIENT_RepRef] => string
                    [PropertyCategory] =>
                    [PropertyCategory_attr] => Array
                        (
                            [Type] => type
                        )

                    [PropertyTypeResidential] =>
                    [PropertyTypeResidential_attr] => Array
                        (
                            [Type] => type
                        )

                    [LotNo] => integer
                    [ListDate] => date
                    [PublishAddress] =>
                    [PublishAddress_attr] => Array
                        (
                            [Type] => type
                        )

                    [Address] => Array
                        (
                            [Street] => string
                            [Suburb] => string
                        )

                    [PricingMethodSale] =>
                    [PricingMethodSale_attr] => Array
                        (
                            [Type] => type
                        )

                    [PricingDetail] => Array
                        (
                            [PriceTextForDisplay] => string
                        )

                    [LandArea] => Array
                        (
                            [LandAreaSize] => integer
                            [LandAreaMeasurementType] =>
                            [LandAreaMeasurementType_attr] => Array
                                (
                                    [Type] => type
                                )

                        )

                    [HeadLine] => string
                    [PublicDescription] => string
                    [Images] => Array
                        (
                            [ImageFileName] => Array
                                (
                                    [0] => 'image address'
                                )

                        )

                )
        )
)

Trip – Port Stephens

天气很好, 天空很蓝, 云朵很白, 沙子很软, 滑沙很好玩!!! ( 就是我老是从滑板上直接滑下来)

Flickr >>

Tags: ,

Say “Thanks” to my mum

Today is a special day for me. I want to say “thanks” to my mum.

Magic Mouse 开箱, 无文

IMG_2367

IMG_2381

全部, Flickr: http://www.flickr.com/photos/skargor/sets/72157622694366038/

Tags: ,

编辑器 Text Editors

写程序的时候, 我经常会纠结在编辑器的选择上.

Mac 下对于我来说, 只用 textmate, 一直很好, 但是公司的机器都是 windows, 所以有时候还是要在 windows 下编辑.

有一段时间用 Editplus , 稳定,打开文件快速, 支持 ftp 编辑, 虽然没有 bundle, 没有 theme. 可以说 Editplus 是胜在稳定快速, 但是缺乏新意. 而且用多了 textmate 的 bundle, 会很不习惯.

既然要用 Bundle, 以前比较出名的是 e-texteditor, 作者是以 windows 下的 textmate 的口号来开发的, bundle 确实也都是从 textmate 下转移过去的, 用的也很好很舒服, 特别是 blackboard theme!!!

不过时间一长, 发现问题来了, 首先, 只能开一个 instace, 那就意味着我无法打开两个窗口, 如果编辑的文件一多, 就会很烦躁. 不能开两个窗口的话, 也ok, 我最多每次少打开一些程序, 或者修改完毕后关掉. 但是它也不能像 vim 一样切割窗口, 那样我可以查看同一个文件的不同地方来进行修改, 所以纠结了半天, 找到了另外一个 editor.

Sublime Text 也同样具有 bundle, 同样是模仿 textmate 的思路, theme 里也有我中意的 blackboard, 但是我觉得它更像是 textmate/vim 的结合体, 能够和 vim 一样切割窗口, 虽然不是任意切割, 但是也感觉方便了很多. 它的设定也和 vim 类似, 是打开一个文件让你编辑.

目前遗憾的地方是, 它没法以目录为 project, 必需创建一个 project 文件才可以. 不支持 remote ftp 的操作.

Tags: ,