PHP 的 count() 是這樣用的 int count ( mixed $var [, int $mode = COUNT_NORMAL ] )
而其對象可以是其實 Object 可以是 Array 也可以是 NULL (一律回傳 0 ) 也可以是其他型態 (一律回傳 1 ) 。
count() 在 PHP 底層的是這樣實作的:
Continue reading “PHP count() 取得 Array 元素個數 – 效率問題”
_老屁孩_
PHP 的 count() 是這樣用的 int count ( mixed $var [, int $mode = COUNT_NORMAL ] )
而其對象可以是其實 Object 可以是 Array 也可以是 NULL (一律回傳 0 ) 也可以是其他型態 (一律回傳 1 ) 。
count() 在 PHP 底層的是這樣實作的:
Continue reading “PHP count() 取得 Array 元素個數 – 效率問題”
荒廢太久沒運動,也該是時候該要動動筋骨了,所以買了一個訓練台,以後在家裡就可以騎車…
原本要在 Yahoo 購物中心買這個訓練台,不過稍微找了一下,發現同樣的商品(同樣是公司貨),Yahoo! 拍賣上面只賣 6800 元,比購物中心的 8500 元便宜了 1700 元。所以我今天晚上就去店家面交了 (購物中心,對不起…掰掰)
Continue reading “ELITE Parabolic Rollers 滾筒訓練台”
一年多前有個 C++ vs. Python vs. Perl vs. PHP performance benchmark 測試,當時 PHP 5.3.5 實在是被打的慘不忍睹。
測試程式的內容是找出 10000000 (一千萬) 以內的質數,然後重複執行十次。以不同語言實作,再執行各個比較時間。
我最近在自己的 Mac 上面編譯了 PHP 5.4 ,再跑一次這個測試,結果有比較滿意了 (但比起其他語言,還是輸!)
Continue reading “PHP 5.4 效能比起 PHP 5.3.x 有長足的進步”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $array = array( "foo" => "bar", "bar" => "foo" ); // as of PHP 5.4 $array = [ "foo" => "bar", "bar" => "foo" ]; ?> |
在 PHP 裡面,可以用儲存鍵值組的 MAP 是個很實用的型別,值的型態可以是任意型態,但鍵的型態只能是 String 和 Int (The key can either be an integer or a string. The value can be of any type.)
以下是一些 PHP 處理 “鍵” 自動轉型的狀況分析:
當是 String 型態,鍵為 “8” 的時候,會被轉型為 Int 8 ,但如果是 “08” 則依然會被當做 String 處理。
當 Float 型態的時候,會被自動轉型成為 Int ,例如 8.7 會被捨去小數點,變成 8 。
當 Bool 型態的時候,一樣會被轉型成為 Int , True 被轉型成 1 而 False 轉型成 0 。
當 Null 型態的時候,會被當成 String ,以 “” (空字串) 表示。
而 Array 和 Object 不能被當成鍵。
另外,新的鍵會覆寫舊的鍵,自動轉型之後的鍵如果和之前的鍵有重複,也會把之前的那組覆寫掉。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php $array = array( 1 => "a", "1" => "b", 1.5 => "c", true => "d", ); var_dump($array); ?> // output // array(1) { // [1]=> // string(1) "d" //} |
ref: PHP: Arrays
所以在使用 MAP 的時候要非常小心被鍵值組被覆寫的問題。
最近 MySQL 接連停掉兩次 (不是我手動關的)。
上次是 3/8 7:30 – 10:30
這是是 3/11 7:45 – 19:20
Mar 11 07:48:37 roga mysqld: 120311 7:48:37 [Note] /usr/sbin/mysqld: Normal shutdown
Mar 11 07:48:37 roga mysqld:
Mar 11 07:48:37 roga mysqld: 120311 7:48:37 [Note] Event Scheduler: Purging the queue. 0 events
Mar 11 07:48:40 roga mysqld: 120311 7:48:40 InnoDB: Starting shutdown...
Mar 11 07:48:41 roga mysqld: 120311 7:48:41 InnoDB: Shutdown completed; log sequence number 0 3989742112
Mar 11 07:48:41 roga mysqld: 120311 7:48:41 [Note] /usr/sbin/mysqld: Shutdown complete
Mar 11 07:48:41 roga mysqld:
Mar 11 07:48:41 roga mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
看了實在是很毛。
在 MySQL 開一個 INT 欄位的時候,有時候我們會把欄位屬性設定為 Unsigned ,這樣可以儲存更多的正整數。
以 Signed 為例,可以儲存 -2147483648 to 2147483647 而以 Unsigned 為例,可以儲存 0 to 4294967295 不過在操作這類欄位的時候,必須要小心,以避免刪過頭,反而變成補血補滿。
Continue reading “MySQL unsigned INT 的問題 – 以噗浪為例”
When I was 17, I read a quote that went something like: “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been”No” for too many days in a row, I know I need to change something.
Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything – all external expectations, all pride, all fear of embarrassment or failure- these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.
– Steve Jobs
「當我17歲時,我讀到一則格言,好像是「如果把每一天都當成生命中的最後一天,總有一天你是對的。」這對我影響深遠,在過去33年裏,我每天早上都會照鏡子,自問:「如果今天是此生最後一日,我今天要幹些什麼?」每當我連續太多天都得到一個「沒事做」的答案時,我就知道我必須有所變革了。
提醒自己快死了,是我在人生中做重大決定時,所用過最重要的工具。因為幾乎每件事-所有外界期望、所有名譽、所有對困窘或失敗的恐懼-在面對死亡時,都消失了,只有最重要的東西才會留下。提醒自己快死了,是我所知避免陷入擔心失去什麼陷阱裏的最好方法。人生不帶來,死不帶去,沒什麼道理不順心而為。
– Steve Jobs
我寫了一個 DNS 托管服務:TopDN.net 。
在寫完主要的程式之後,就是要開始規劃一些資料同步的事情: TopDN.net 目前提供兩台機器當 Name Server ,分別是 ns1.topdn.net 以及 ns2.topdn.net ,在開發初期我想了三個同步的方法:
Continue reading “設定 Master/Slave DNS Server”
最近發現網路有斷線的情形,全部都是發生在清晨的時候。這讓我心情很不好…
2/22 3:30 - 5:30 2/24 3:30 - 4:00 2/25 3:30 - 5:30 2/27 3:30 - 4:00 3/1 4:00 - 5:00 3/6 6:20 - 6:25
這一切都是我活該, HTC 沒什麼問題,單純是我手賤惹的禍。
事情是這樣的:
我的 HTC Desire 壞掉了,症狀是不斷卡在開機畫面,並且一直重新開機。由於還在保固期內,所以我就送回去維修,今天接到電話,對方表示我的主機板壞掉了,是硬體的問題。不過由於我的手機有刷 Custom ROM 所以他們沒辦法出保固,要我自費換主機板 (這很正常)。
Continue reading “HTC Desire 壽終正寢”