<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Gea-Suan Lin&#039;s BLOG &#187; Programming</title> <atom:link href="http://blog.gslin.org/archives/category/computer/programming/feed/" rel="self" type="application/rss+xml" /><link>http://blog.gslin.org</link> <description>幹壞事是進步最大的原動力</description> <lastBuildDate>Sat, 11 Feb 2012 22:15:31 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud
domain='blog.gslin.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <item><title>Google Chrome Extension 內攔截所有的 url request&#8230;</title><link>http://blog.gslin.org/archives/2012/02/08/2821/google-chrome-extension-%e5%85%a7%e6%94%94%e6%88%aa%e6%89%80%e6%9c%89%e7%9a%84-url-request/</link> <comments>http://blog.gslin.org/archives/2012/02/08/2821/google-chrome-extension-%e5%85%a7%e6%94%94%e6%88%aa%e6%89%80%e6%9c%89%e7%9a%84-url-request/#comments</comments> <pubDate>Wed, 08 Feb 2012 03:43:43 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Browser]]></category> <category><![CDATA[Computer]]></category> <category><![CDATA[GoogleChrome]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[google]]></category> <category><![CDATA[referer]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2821</guid> <description><![CDATA[Tweet 之前寫了一個處理 Referer header 的 extension，使用 chrome.experimental.webRequest.onBeforeSendHeaders.addListener 攔截所有的 url 然後處理 Referer header。 之前只需要在 manifest.json 裡面加上 experimental 就可以使用，但是前陣子發現失效。剛剛在「onBeforeSendHeaders listeners aren&#8217;t triggering」這個 issue 裡面找到解法：現在需要多加上 &#60;all_urls&#62; 這組權限。]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2012%2F02%2F08%2F2821%2Fgoogle-chrome-extension-%25e5%2585%25a7%25e6%2594%2594%25e6%2588%25aa%25e6%2589%2580%25e6%259c%2589%25e7%259a%2584-url-request%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2012/02/08/2821/google-chrome-extension-%e5%85%a7%e6%94%94%e6%88%aa%e6%89%80%e6%9c%89%e7%9a%84-url-request/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2012/02/08/2821/google-chrome-extension-%e5%85%a7%e6%94%94%e6%88%aa%e6%89%80%e6%9c%89%e7%9a%84-url-request/"  data-text="Google Chrome Extension 內攔截所有的 url request&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>之前寫了一個處理 <code>Referer</code> header 的 extension，使用 <code>chrome.experimental.webRequest.onBeforeSendHeaders.addListener</code> 攔截所有的 url 然後處理 <code>Referer</code> header。</p><p>之前只需要在 <code>manifest.json</code> 裡面加上 <code>experimental</code> 就可以使用，但是前陣子發現失效。剛剛在「<a
href="https://code.google.com/p/chromium/issues/detail?id=101275">onBeforeSendHeaders listeners aren&#8217;t triggering</a>」這個 issue 裡面找到解法：現在需要多加上 <code>&lt;all_urls&gt;</code> 這組權限。</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2012/02/08/2821/google-chrome-extension-%e5%85%a7%e6%94%94%e6%88%aa%e6%89%80%e6%9c%89%e7%9a%84-url-request/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>如果要自己寫 TOTP 的幾個要看的東西&#8230;</title><link>http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/</link> <comments>http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/#comments</comments> <pubDate>Sun, 18 Dec 2011 09:38:22 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Security]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[authenticator]]></category> <category><![CDATA[cpan]]></category> <category><![CDATA[google]]></category> <category><![CDATA[hotp]]></category> <category><![CDATA[oath]]></category> <category><![CDATA[otp]]></category> <category><![CDATA[qrcode]]></category> <category><![CDATA[totp]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2804</guid> <description><![CDATA[Tweet 整理下來： HOTP: An HMAC-Based One-Time Password Algorithm TOTP: Time-Based One-Time Password Algorithm KeyUriFormat &#8211; google-authenticator &#8211; The format of URIs containing encoded keys &#8211; Two-step verification &#8211; Google Project Hosting 有玩過 HMAC 的人，讀這些文件應該不難&#8230; TOTP 在預設的情況下，其實就是 HMAC-SHA-1 後取後面 32bits，然後轉成數字取 100000 &#8230; <a
href="http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F12%2F18%2F2804%2F%25e5%25a6%2582%25e6%259e%259c%25e8%25a6%2581%25e8%2587%25aa%25e5%25b7%25b1%25e5%25af%25ab-totp-%25e7%259a%2584%25e5%25b9%25be%25e5%2580%258b%25e8%25a6%2581%25e7%259c%258b%25e7%259a%2584%25e6%259d%25b1%25e8%25a5%25bf%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/"  data-text="如果要自己寫 TOTP 的幾個要看的東西&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>整理下來：</p><ul><li><a
href="http://tools.ietf.org/html/rfc4226">HOTP: An HMAC-Based One-Time Password Algorithm</a></li><li><a
href="http://tools.ietf.org/html/rfc6238">TOTP: Time-Based One-Time Password Algorithm</a></li><li><a
href="http://code.google.com/p/google-authenticator/wiki/KeyUriFormat">KeyUriFormat &#8211; google-authenticator &#8211; The format of URIs containing encoded keys &#8211; Two-step verification &#8211; Google Project Hosting</a></li></ul><p>有玩過 <a
href="https://en.wikipedia.org/wiki/HMAC">HMAC</a> 的人，讀這些文件應該不難&#8230;</p><p>TOTP 在預設的情況下，其實就是 HMAC-SHA-1 後取後面 32bits，然後轉成數字取 100000 的餘數，而 TOTP 文件是架構在 HOTP 的定義上，把時間切齊 (預設 30secs) 變成整數丟進去攪和，然後特地交代要處理 2038 年超過 Int32 的 case XDDD</p><p>最後 <a
href="http://www.google.com/">Google</a> 那份文件是要輸出 QR code 讓手機可以讀的方式，建議不要用網路服務產生 QR code (因為有 secret key 啊)，寧可自己抓 library 建一個用&#8230;</p><p>另外 Google Authenticator 一堆東西都只能用預設值 (Currently, the XXX is ignored by the Google Authenticator implementations.)，所以也沒什麼好選的，就拿預設值吧&#8230; :o</p><p>Server side 的話，至少我在 <a
href="http://www.cpan.org/">CPAN</a> 上面看到 <a
href="http://search.cpan.org/dist/Authen-OATH/">Authen-OATH</a> 可以用了，用起來也很簡單 :o</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/12/18/2804/%e5%a6%82%e6%9e%9c%e8%a6%81%e8%87%aa%e5%b7%b1%e5%af%ab-totp-%e7%9a%84%e5%b9%be%e5%80%8b%e8%a6%81%e7%9c%8b%e7%9a%84%e6%9d%b1%e8%a5%bf/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHP 提供的資料結構&#8230;</title><link>http://blog.gslin.org/archives/2011/12/18/2803/php-%e6%8f%90%e4%be%9b%e7%9a%84%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b/</link> <comments>http://blog.gslin.org/archives/2011/12/18/2803/php-%e6%8f%90%e4%be%9b%e7%9a%84%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b/#comments</comments> <pubDate>Sat, 17 Dec 2011 19:05:12 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[array]]></category> <category><![CDATA[data]]></category> <category><![CDATA[php]]></category> <category><![CDATA[spl]]></category> <category><![CDATA[structure]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2803</guid> <description><![CDATA[Tweet 從「How big are PHP arrays (and values) really? (Hint: BIG!)」這篇看到的。文章本身值得花些時間看過了解，不過對我來說重點在最後面的 SplFixedArray。 PHP 的 Datastructures 說明目前 PHP SPL 所支援的 data structure，在記憶體用量以及效率上面都會比自己實作來的小且快。 可以看到很多都支援 Countable、Iterator，以及 ArrayAccess，代表可以用 foreach() 或是對應的方式存取&#8230; 如果自己寫 library 的時候應該要善用這些 SPL。]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F12%2F18%2F2803%2Fphp-%25e6%258f%2590%25e4%25be%259b%25e7%259a%2584%25e8%25b3%2587%25e6%2596%2599%25e7%25b5%2590%25e6%25a7%258b%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/12/18/2803/php-%e6%8f%90%e4%be%9b%e7%9a%84%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/12/18/2803/php-%e6%8f%90%e4%be%9b%e7%9a%84%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b/"  data-text="PHP 提供的資料結構&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>從「<a
href="http://nikic.github.com/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html">How big are PHP arrays (and values) really? (Hint: BIG!)</a>」這篇看到的。文章本身值得花些時間看過了解，不過對我來說重點在最後面的 <a
href="http://php.net/manual/en/class.splfixedarray.php">SplFixedArray</a>。</p><p><a
href="http://www.php.net/">PHP</a> 的 <a
href="http://php.net/manual/en/spl.datastructures.php">Datastructures</a> 說明目前 PHP SPL 所支援的 data structure，在記憶體用量以及效率上面都會比自己實作來的小且快。</p><p>可以看到很多都支援 Countable、Iterator，以及 ArrayAccess，代表可以用 <code>foreach()</code> 或是對應的方式存取&#8230; 如果自己寫 library 的時候應該要善用這些 SPL。</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/12/18/2803/php-%e6%8f%90%e4%be%9b%e7%9a%84%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>BSD make 與 GNU make 的 Makefile&#8230;</title><link>http://blog.gslin.org/archives/2011/12/11/2797/bsd-make-%e8%88%87-gnu-make-%e7%9a%84-makefile/</link> <comments>http://blog.gslin.org/archives/2011/12/11/2797/bsd-make-%e8%88%87-gnu-make-%e7%9a%84-makefile/#comments</comments> <pubDate>Sun, 11 Dec 2011 11:41:11 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[bsd]]></category> <category><![CDATA[gnu]]></category> <category><![CDATA[make]]></category> <category><![CDATA[makefile]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2797</guid> <description><![CDATA[Tweet 前陣子看到 fcamel 丟出來的舊文章：「Debugging make」，花了一些時間看裡面關於 BSD make 與 GNU make 的相同處，之後寫 Makefile 的時候應該會相當有幫助。 目前的目標是 FreeBSD 與 Ubuntu，文章裡面有提到三個變數在兩個平台是通用的，分別是 $]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F12%2F11%2F2797%2Fbsd-make-%25e8%2588%2587-gnu-make-%25e7%259a%2584-makefile%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/12/11/2797/bsd-make-%e8%88%87-gnu-make-%e7%9a%84-makefile/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/12/11/2797/bsd-make-%e8%88%87-gnu-make-%e7%9a%84-makefile/"  data-text="BSD make 與 GNU make 的 Makefile&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>前陣子看到 <a
href="http://fcamel-life.blogspot.com/">fcamel</a> 丟出來的舊文章：「<a
href="http://www.ibm.com/developerworks/linux/library/l-debugmake/index.html">Debugging make</a>」，花了一些時間看裡面關於 BSD make 與 GNU make 的相同處，之後寫 Makefile 的時候應該會相當有幫助。</p><p>目前的目標是 <a
href="http://www.freebsd.org/">FreeBSD</a> 與 <a
href="http://www.ubuntu.com/">Ubuntu</a>，文章裡面有提到三個變數在兩個平台是通用的，分別是 <code>$<</code> (The source from which the target is to be made)、<code>$*</code> (The base name of the target (no extensions or directory))、<code>$@</code> (The full name of the target)。</p><p>另外文章後面也有提到不相容的地方... 如果能避免就儘量避免？</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/12/11/2797/bsd-make-%e8%88%87-gnu-make-%e7%9a%84-makefile/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>安裝 Pretty Beautiful Javascript&#8230;</title><link>http://blog.gslin.org/archives/2011/11/18/2781/%e5%ae%89%e8%a3%9d-pretty-beautiful-javascript/</link> <comments>http://blog.gslin.org/archives/2011/11/18/2781/%e5%ae%89%e8%a3%9d-pretty-beautiful-javascript/#comments</comments> <pubDate>Thu, 17 Nov 2011 21:22:33 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Browser]]></category> <category><![CDATA[Computer]]></category> <category><![CDATA[GoogleChrome]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[extension]]></category> <category><![CDATA[google]]></category> <category><![CDATA[javascript]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2781</guid> <description><![CDATA[Tweet Pretty Beautiful Javascript，這是安裝前看 jQuery 1.7.0 程式碼的效果： 這是安裝後的效果： 不過 javascript 檔案大一點跑起來就會很慢 XD]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F11%2F18%2F2781%2F%25e5%25ae%2589%25e8%25a3%259d-pretty-beautiful-javascript%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/11/18/2781/%e5%ae%89%e8%a3%9d-pretty-beautiful-javascript/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/11/18/2781/%e5%ae%89%e8%a3%9d-pretty-beautiful-javascript/"  data-text="安裝 Pretty Beautiful Javascript&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p><a
href="https://chrome.google.com/webstore/detail/piekbefgpgdecckjcpffhnacjflfoddg">Pretty Beautiful Javascript</a>，這是安裝前看 jQuery 1.7.0 程式碼的效果：</p><p><a
href="http://i.imgur.com/qqBI5.png"><img
src="http://i.imgur.com/qqBI5.png" alt="" /></a></p><p>這是安裝後的效果：</p><p><a
href="http://i.imgur.com/cNatZ.png"><img
src="http://i.imgur.com/cNatZ.png" alt="" /></a></p><p>不過 javascript 檔案大一點跑起來就會很慢 XD</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/11/18/2781/%e5%ae%89%e8%a3%9d-pretty-beautiful-javascript/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>改用 jquery-ujs&#8230;</title><link>http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/</link> <comments>http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/#comments</comments> <pubDate>Thu, 10 Nov 2011 14:28:06 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[ujs]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2775</guid> <description><![CDATA[Tweet 昨天聽 othree 提到 jquery-ujs (Unobtrusive scripting adapter for jQuery)，裡面有不少 convention 可以直接套用。othree 在三月有寫一篇文章介紹：「jQuery-ujs」。 雖然 repository 看起來是給 RoR 使用，但直接把 rails.js 抓下來用「&#60;script src="rails.js"&#62;&#60;/script&#62;」掛上來，還是可以用在非 RoR 環境裡。 直接看 code 也很好懂，舉幾個例子來說： &#60;?php $sToken = hash('sha256', session_id()); ?&#62; &#60;meta name="csrf-token" content="&#60;?php echo $sToken; ?&#62;"&#62; &#60;meta name="csrf-param" &#8230; <a
href="http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F11%2F10%2F2775%2F%25e6%2594%25b9%25e7%2594%25a8-jquery-ujs%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/"  data-text="改用 jquery-ujs&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>昨天聽 <a
href="http://blog.othree.net/">othree</a> 提到 <a
href="https://github.com/rails/jquery-ujs">jquery-ujs</a> (Unobtrusive scripting adapter for jQuery)，裡面有不少 convention 可以直接套用。othree 在三月有寫一篇文章介紹：「<a
href="http://blog.othree.net/log/2011/03/09/jquery-ujs/">jQuery-ujs</a>」。</p><p>雖然 repository 看起來是給 <a
href="http://rubyonrails.org/">RoR</a> 使用，但直接把 <a
href="https://github.com/rails/jquery-ujs/blob/master/src/rails.js">rails.js</a> 抓下來用「<code>&lt;script src="rails.js"&gt;&lt;/script&gt;</code>」掛上來，還是可以用在非 RoR 環境裡。</p><p>直接看 code 也很好懂，舉幾個例子來說：</p><blockquote><pre>&lt;?php $sToken = hash('sha256', session_id()); ?&gt;
&lt;meta name="csrf-token" content="&lt;?php echo $sToken; ?&gt;"&gt;
&lt;meta name="csrf-param" content="sToken"&gt;</pre></blockquote><p>表示 CSRF token 名稱為 <code>sToken</code>，值為 <code>hash('sha256', sesssion_id())</code>。</p><p>對於想要先跳出 confirm dialog，再決定要不要繼續執行的連結，可以加上 <code>data-confirm</code> 表示：</p><blockquote><pre>&lt;a href="/delete/1" data-confirm="是否要刪除？"&gt;</pre></blockquote><p>如果要用 POST (上面的 delete operation 不應該用 GET，因為資料被變更)，可以加上 <code>data-method</code>：</p><blockquote><pre>&lt;a href="/delete/1" data-confirm="是否要刪除？" data-method="post"&gt;</pre></blockquote><p>或是直接用 DELETE，在 server side 可以讀 <code>_method</code> 這個值：</p><blockquote><pre>&lt;a href="/delete/1" data-confirm="是否要刪除？" data-method="delete"&gt;</pre></blockquote><p>最後，建議大家去看 <a
href="https://github.com/rails/jquery-ujs/wiki">jquery-ujs 的 wiki</a>，上面有針對用法有比較完整的說明，配著 source code 一起看會比較容易上手。</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/11/10/2775/%e6%94%b9%e7%94%a8-jquery-ujs/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>jQuery 1.7 版，並計畫瘦身 jQuery&#8230;</title><link>http://blog.gslin.org/archives/2011/11/09/2773/jquery-1-7-%e7%89%88%ef%bc%8c%e4%b8%a6%e8%a8%88%e7%95%ab%e7%98%a6%e8%ba%ab-jquery/</link> <comments>http://blog.gslin.org/archives/2011/11/09/2773/jquery-1-7-%e7%89%88%ef%bc%8c%e4%b8%a6%e8%a8%88%e7%95%ab%e7%98%a6%e8%ba%ab-jquery/#comments</comments> <pubDate>Wed, 09 Nov 2011 05:23:51 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Browser]]></category> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[size]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2773</guid> <description><![CDATA[Tweet jQuery 1.7 前幾天丟出來了，可以看到很多對 event 操作的改善，包括效能與功能 (新增了 .on() 與 .off())：「jQuery 1.7 Released」。 另外今天又看到瘦身計畫：「Building a Slimmer jQuery」，希望把一些「應該要拿掉」或是「應該要被修正」的問題處理掉&#8230; 所以在 jQuery 1.7 標為 Deprecation，預定在下個主版本就會處理掉這些問題。 目前 (對我家) 最主要的影響應該是 .live() 會被拔掉，以及之前有使用 .attr('value') 取 current value (要 current value 應該用 .val() 取得)。 看起來是往好的方面進行&#8230;]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F11%2F09%2F2773%2Fjquery-1-7-%25e7%2589%2588%25ef%25bc%258c%25e4%25b8%25a6%25e8%25a8%2588%25e7%2595%25ab%25e7%2598%25a6%25e8%25ba%25ab-jquery%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/11/09/2773/jquery-1-7-%e7%89%88%ef%bc%8c%e4%b8%a6%e8%a8%88%e7%95%ab%e7%98%a6%e8%ba%ab-jquery/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/11/09/2773/jquery-1-7-%e7%89%88%ef%bc%8c%e4%b8%a6%e8%a8%88%e7%95%ab%e7%98%a6%e8%ba%ab-jquery/"  data-text="jQuery 1.7 版，並計畫瘦身 jQuery&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p><a
href="http://blog.jquery.com/2011/11/03/jquery-1-7-released/">jQuery 1.7</a> 前幾天丟出來了，可以看到很多對 event 操作的改善，包括效能與功能 (新增了 <code>.on()</code> 與 <code>.off()</code>)：「<a
href="http://blog.jquery.com/2011/11/03/jquery-1-7-released/">jQuery 1.7 Released</a>」。</p><p>另外今天又看到瘦身計畫：「<a
href="http://blog.jquery.com/2011/11/08/building-a-slimmer-jquery/">Building a Slimmer jQuery</a>」，希望把一些「應該要拿掉」或是「應該要被修正」的問題處理掉&#8230; 所以在 jQuery 1.7 標為 Deprecation，預定在下個主版本就會處理掉這些問題。</p><p>目前 (對我家) 最主要的影響應該是 <code>.live()</code> 會被拔掉，以及之前有使用 <code>.attr('value')</code> 取 current value (要 current value 應該用 <code>.val()</code> 取得)。</p><p>看起來是往好的方面進行&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/11/09/2773/jquery-1-7-%e7%89%88%ef%bc%8c%e4%b8%a6%e8%a8%88%e7%95%ab%e7%98%a6%e8%ba%ab-jquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>擋掉 Google Plus，加快 Google Reader 速度&#8230;</title><link>http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/</link> <comments>http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/#comments</comments> <pubDate>Sat, 05 Nov 2011 09:40:52 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Browser]]></category> <category><![CDATA[Computer]]></category> <category><![CDATA[GoogleChrome]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[adblock]]></category> <category><![CDATA[api]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[experimental]]></category> <category><![CDATA[google]]></category> <category><![CDATA[plus]]></category> <category><![CDATA[reader]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2768</guid> <description><![CDATA[Tweet Google Reader 這次改版另外一個為人詬病的問題是「變卡」，主要原因是 Google Plus。 第一個想到的解決是利用 Adblock Plus，將 http://www.google.com/reader/* 以及 https://www.google.com/reader/* 連到 https://plusone.google.com/* 的連線需求都都擋下來。但看了 Adblock Plus 的文件，不知道要怎麼設定&#8230; 後來想到的解法是自己寫 Google Chrome Extension，主要是很久沒寫都忘光了，剛好找個實際會用到的功能來寫&#8230; 主要是用到 chrome.tabs 與 chrome.experimental.webRequest 兩組 API 組合。其中後面這組 API 必須用 about:flags 打開權限才能使用。 成品在這：「google-reader-faster」，由於用到 Google Chrome 的 Experimental API 所以無法上傳到 &#8230; <a
href="http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F11%2F05%2F2768%2F%25e6%2593%258b%25e6%258e%2589-google-plus%25ef%25bc%258c%25e5%258a%25a0%25e5%25bf%25ab-google-reader-%25e9%2580%259f%25e5%25ba%25a6%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/"  data-text="擋掉 Google Plus，加快 Google Reader 速度&#8230;" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p><a
href="https://www.google.com/reader">Google Reader</a> 這次改版另外一個為人詬病的問題是「變卡」，主要原因是 <a
href="https://plus.google.com/">Google Plus</a>。</p><p>第一個想到的解決是利用 <a
href="http://adblockplus.org/">Adblock Plus</a>，將 <code>http://www.google.com/reader/*</code> 以及 <code>https://www.google.com/reader/*</code> 連到 <code>https://plusone.google.com/*</code> 的連線需求都都擋下來。但看了 Adblock Plus 的文件，不知道要怎麼設定&#8230;</p><p>後來想到的解法是自己寫 Google Chrome Extension，主要是很久沒寫都忘光了，剛好找個實際會用到的功能來寫&#8230; 主要是用到 <code><a
href="http://code.google.com/chrome/extensions/tabs.html">chrome.tabs</a></code> 與 <code><a
href="http://code.google.com/chrome/extensions/experimental.webRequest.html">chrome.experimental.webRequest</a></code> 兩組 API 組合。其中後面這組 API 必須用 <code>about:flags</code> 打開權限才能使用。</p><p>成品在這：「<a
href="https://github.com/gslin/google-reader-faster">google-reader-faster</a>」，由於用到 <a
href="http://www.google.com/chrome">Google Chrome</a> 的 Experimental API 所以無法上傳到 Web Store，所以暫時先用 dev mode 把 extension 讀進來用。之後要來再研究看看 Adblock Plus 是怎麼做到的&#8230;</p><p>把 Google Plus 擋掉後用鍵盤快速鍵操作順很多 XD</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/11/05/2768/%e6%93%8b%e6%8e%89-google-plus%ef%bc%8c%e5%8a%a0%e5%bf%ab-google-reader-%e9%80%9f%e5%ba%a6/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>用 RVM 安裝 Ruby 1.9.3</title><link>http://blog.gslin.org/archives/2011/10/31/2763/%e7%94%a8-rvm-%e5%ae%89%e8%a3%9d-ruby-1-9-3/</link> <comments>http://blog.gslin.org/archives/2011/10/31/2763/%e7%94%a8-rvm-%e5%ae%89%e8%a3%9d-ruby-1-9-3/#comments</comments> <pubDate>Sun, 30 Oct 2011 18:33:56 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[1.9.3]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[rvm]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2763</guid> <description><![CDATA[Tweet 為了跑 heroku 才剛裝完 1.9.2，就看到 Twitter 與 Google Plus 有人說 1.9.3-p0 出了：「[ANN] Ruby 1.9.3-p0 is out」。 首先先用 rvm get head 更新，然後用 rvm list known 應該就可以看到 1.9.3-p0 了，接下來用 rvm use --default 1.9.3 將預設值換成 1.9.3，然後 gem install heroku 把 gem 裝起來&#8230;]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F10%2F31%2F2763%2F%25e7%2594%25a8-rvm-%25e5%25ae%2589%25e8%25a3%259d-ruby-1-9-3%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/10/31/2763/%e7%94%a8-rvm-%e5%ae%89%e8%a3%9d-ruby-1-9-3/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/10/31/2763/%e7%94%a8-rvm-%e5%ae%89%e8%a3%9d-ruby-1-9-3/"  data-text="用 RVM 安裝 Ruby 1.9.3" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>為了跑 <a
href="https://github.com/heroku/heroku">heroku</a> 才剛裝完 1.9.2，就看到 <a
href="http://twitter.com/">Twitter</a> 與 <a
href="https://plus.google.com/">Google Plus</a> 有人說 1.9.3-p0 出了：「<a
href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/40527">[ANN] Ruby 1.9.3-p0 is out</a>」。</p><p>首先先用 <code>rvm get head</code> 更新，然後用 <code>rvm list known</code> 應該就可以看到 1.9.3-p0 了，接下來用 <code>rvm use --default 1.9.3</code> 將預設值換成 1.9.3，然後 <code>gem install heroku</code> 把 gem 裝起來&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/10/31/2763/%e7%94%a8-rvm-%e5%ae%89%e8%a3%9d-ruby-1-9-3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHP 5.3 的 anonymous function</title><link>http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/</link> <comments>http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/#comments</comments> <pubDate>Sat, 15 Oct 2011 22:45:05 +0000</pubDate> <dc:creator>Gea-Suan Lin</dc:creator> <category><![CDATA[Computer]]></category> <category><![CDATA[Murmuring]]></category> <category><![CDATA[Network]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[WWW]]></category> <category><![CDATA[anonymous]]></category> <category><![CDATA[function]]></category> <category><![CDATA[php]]></category> <category><![CDATA[programming]]></category><guid
isPermaLink="false">http://blog.gslin.org/?p=2756</guid> <description><![CDATA[Tweet 在看到 PHPConf Taiwan 2011 的議程介紹後，看到有人在推薦 Slim Framework，一連上去就看到包含 anonymous function 的 sample code： &#60;?php require 'Slim/Slim.php'; $app = new Slim(); $app-&#62;get('/hello/:name', function ($name) { echo "Hello, $name!"; }); $app-&#62;run(); ?&#62; 然後回頭去翻 PHP 的說明：「Anonymous functions」，發現是從 PHP 5.3 開始支援。 於是在 JavaScript 上常用到的技巧就也可以在 &#8230; <a
href="http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.gslin.org%2Farchives%2F2011%2F10%2F16%2F2756%2Fphp-5-3-%25e7%259a%2584-anonymous-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/"  data-text="PHP 5.3 的 anonymous function" data-count="horizontal" data-via="gslin">Tweet</a></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div><p>在看到 <a
href="http://phpconf.tw/2011/sessions">PHPConf Taiwan 2011 的議程介紹</a>後，看到有人在推薦 <a
href="http://www.slimframework.com/">Slim Framework</a>，一連上去就看到包含 anonymous function 的 sample code：</p><blockquote><pre>&lt;?php
require 'Slim/Slim.php';
$app = new Slim();
$app-&gt;get('/hello/:name', function ($name) {
    echo "Hello, $name!";
});
$app-&gt;run();
?&gt;</pre></blockquote><p>然後回頭去翻 <a
href="http://php.net/">PHP</a> 的說明：「<a
href="http://php.net/manual/en/functions.anonymous.php">Anonymous functions</a>」，發現是從 PHP 5.3 開始支援。</p><p>於是在 JavaScript 上常用到的技巧就也可以在 PHP 上用了：(不影響到全域變數與函數空間的方式)</p><blockquote><pre>// JavaScript
(function(){
    // ...
})();

// PHP
call_user_func(function(){
    // ...
});</pre></blockquote><p>接下來是繼續測試 Slim Framework 了，看起來算是一個不錯的小東西&#8230; 之後拿來配合 <a
href="http://www.heroku.com/">Heroku</a> 這類的 PasS 快速開發應該會很好用 :o</p> ]]></content:encoded> <wfw:commentRss>http://blog.gslin.org/archives/2011/10/16/2756/php-5-3-%e7%9a%84-anonymous-function/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: blog.gslin.org @ 2012-02-12 14:43:35 -->
