Category Archives: Programming

如果要自己寫 TOTP 的幾個要看的東西…

整理下來: HOTP: An HMAC-Based One-Time Password Algorithm TOTP: Time-Based One-Time Password Algorithm KeyUriFormat – google-authenticator – The format of URIs containing encoded keys – Two-step verification – Google Project Hosting 有玩過 HMAC 的人,讀這些文件應該不難… TOTP 在預設的情況下,其實就是 HMAC-SHA-1 後取後面 32bits,然後轉成數字取 100000 的餘數,而 … Continue reading

Posted in Computer, Murmuring, Network, Programming, Security, Software | Tagged , , , , , , , | 1 Comment

PHP 提供的資料結構…

從「How big are PHP arrays (and values) really? (Hint: BIG!)」這篇看到的。文章本身值得花些時間看過了解,不過對我來說重點在最後面的 SplFixedArray。 PHP 的 Datastructures 說明目前 PHP SPL 所支援的 data structure,在記憶體用量以及效率上面都會比自己實作來的小且快。 可以看到很多都支援 Countable、Iterator,以及 ArrayAccess,代表可以用 foreach() 或是對應的方式存取… 如果自己寫 library 的時候應該要善用這些 SPL。

Posted in Computer, Murmuring, Programming, Software | Tagged , , , , | Leave a comment

BSD make 與 GNU make 的 Makefile…

前陣子看到 fcamel 丟出來的舊文章:「Debugging make」,花了一些時間看裡面關於 BSD make 與 GNU make 的相同處,之後寫 Makefile 的時候應該會相當有幫助。 目前的目標是 FreeBSD 與 Ubuntu,文章裡面有提到三個變數在兩個平台是通用的,分別是 $

Posted in Computer, Murmuring, Programming, Software | Tagged , , , | 1 Comment

安裝 Pretty Beautiful Javascript…

Pretty Beautiful Javascript,這是安裝前看 jQuery 1.7.0 程式碼的效果: 這是安裝後的效果: 不過 javascript 檔案大一點跑起來就會很慢 XD

Posted in Browser, Computer, GoogleChrome, Murmuring, Network, Programming, Software, WWW | Tagged , , , | 2 Comments

改用 jquery-ujs…

昨天聽 othree 提到 jquery-ujs (Unobtrusive scripting adapter for jQuery),裡面有不少 convention 可以直接套用。othree 在三月有寫一篇文章介紹:「jQuery-ujs」。 雖然 repository 看起來是給 RoR 使用,但直接把 rails.js 抓下來用「<script src=”rails.js”></script>」掛上來,還是可以用在非 RoR 環境裡。 直接看 code 也很好懂,舉幾個例子來說: <?php $sToken = hash(‘sha256′, session_id()); ?> <meta name=”csrf-token” content=”<?php echo $sToken; ?>”> <meta name=”csrf-param” content=”sToken”> … Continue reading

Posted in Computer, Murmuring, Network, Programming, Software, WWW | Tagged , , | 1 Comment

jQuery 1.7 版,並計畫瘦身 jQuery…

jQuery 1.7 前幾天丟出來了,可以看到很多對 event 操作的改善,包括效能與功能 (新增了 .on() 與 .off()):「jQuery 1.7 Released」。 另外今天又看到瘦身計畫:「Building a Slimmer jQuery」,希望把一些「應該要拿掉」或是「應該要被修正」的問題處理掉… 所以在 jQuery 1.7 標為 Deprecation,預定在下個主版本就會處理掉這些問題。 目前 (對我家) 最主要的影響應該是 .live() 會被拔掉,以及之前有使用 .attr(‘value’) 取 current value (要 current value 應該用 .val() 取得)。 看起來是往好的方面進行…

Posted in Browser, Computer, Murmuring, Network, Programming, Software, WWW | Tagged , , , | Leave a comment

擋掉 Google Plus,加快 Google Reader 速度…

Google Reader 這次改版另外一個為人詬病的問題是「變卡」,主要原因是 Google Plus。 第一個想到的解決是利用 Adblock Plus,將 http://www.google.com/reader/* 以及 https://www.google.com/reader/* 連到 https://plusone.google.com/* 的連線需求都都擋下來。但看了 Adblock Plus 的文件,不知道要怎麼設定… 後來想到的解法是自己寫 Google Chrome Extension,主要是很久沒寫都忘光了,剛好找個實際會用到的功能來寫… 主要是用到 chrome.tabs 與 chrome.experimental.webRequest 兩組 API 組合。其中後面這組 API 必須用 about:flags 打開權限才能使用。 成品在這:「google-reader-faster」,由於用到 Google Chrome 的 Experimental API 所以無法上傳到 Web … Continue reading

Posted in Browser, Computer, GoogleChrome, Murmuring, Network, Programming, Software, WWW | Tagged , , , , , , | 2 Comments

用 RVM 安裝 Ruby 1.9.3

為了跑 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 裝起來…

Posted in Computer, Murmuring, Network, Programming, Software | Tagged , , | Leave a comment

PHP 5.3 的 anonymous function

在看到 PHPConf Taiwan 2011 的議程介紹後,看到有人在推薦 Slim Framework,一連上去就看到包含 anonymous function 的 sample code: <?php require ‘Slim/Slim.php’; $app = new Slim(); $app->get(‘/hello/:name’, function ($name) { echo “Hello, $name!”; }); $app->run(); ?> 然後回頭去翻 PHP 的說明:「Anonymous functions」,發現是從 PHP 5.3 開始支援。 於是在 JavaScript 上常用到的技巧就也可以在 PHP … Continue reading

Posted in Computer, Murmuring, Network, Programming, WWW | Tagged , , , | 2 Comments

Heroku 上跑 PHP 的心得與感想…

Heroku 不愧是 PaaS 中的領先品牌,deploy 的操作及穩定性都相當好,加上 Heroku 每個 project 都有 1 free dyno 可以使用,對於 prototyping 其實相當棒… 關於要怎麼在 Heroku 上跑 PHP,可以參考 xdite 寫的「Create PHP application on Heroku without Facebook account」這篇文章。 有幾個要抱怨的: PHP 是用 Apache HTTP Server 跑的,所以可以用 .htaccess 寫 rewrite rule,不過 Options … Continue reading

Posted in Cloud, Computer, Murmuring, Network, Programming, WWW | Tagged , , , , , , | Leave a comment