Domon's Programming Notes

記錄 programming 相關筆記。

Keynote - Brad Fitzpatrick | DjangoCon on blip.tv

  • 並非別人就是天才,自己就是笨蛋。
    • 自己知道自己哪裡癢、怎麼癢,會癢就抓!
  • 為什麼要自己來?
    • 可以是為了學習,也可以是因為不想學習。自己來是有多難?
  • 簡單 != 很快可以解決
    花時間 != 困難
  • 東西放出去,就要有心理準備持續收到 mail,即使那只是自己一時的小玩具。
    • 技巧:減少自己的 address 曝光、提早建立社群

Filed under  //   opensource   programming  

The protocol-relative URL « Paul Irish

There's this little trick you can get away with that'll save you some headaches:

<img src="//domain.com/img/logo.png">

If the browser is viewing that current page in through HTTPS, then it'll request that asset with the HTTPS protocol, otherwise it'll typically* request it with HTTP. This prevents that awful "This Page Contains Both Secure and Non-Secure Items" error message in IE, keeping all your asset requests within the same protocol.

*Of course, if you're viewing the file locally, it'll try to request the file with the file:// protocol.

https 的頁面中若送出 http 的 request,就會收到 browser 的警告。

若該 resource 同時可以透過 https 和 http 取得,則不要把 protocol 寫出來,在 https 的頁面中 browser 會自行決定採 https。

Filed under  //   html   url  

Documentation is freaking awesome // Speaker Deck

寫文件有很多好處,包含讓更多人了解你的 project,進而願意使用甚至 contribute;
寫文件也是個機會,讓自己停下來了解自己的 code 是否有問題。

slide 中提到不少產生 doc 的好工具,像是 RDoc、YARD、TomDoc……等。

Filed under  //   doc   ruby  
Posted June 29, 2011

Quick Tip: Understanding CSS Specificity | Nettuts+

  • CSS rule 的 specificity 越高,priority 越高。
  • specificity 可由該 rule 包含的 selector 計算總分
    • HTML element: 1
    • class: 10
    • id: 100

Filed under  //   css   specificity  
Posted May 15, 2010

Why Ruby

1. 好的語言不該限制思考;
2. 簡潔 != 簡單。

作者在別場演講的講稿(應該是同份 slide):
http://www.rubyist.net/~matz/slides/oscon2003/power.txt

Filed under  //   Matz   ruby  
Posted May 4, 2010

Ruby製アプリケーションを配布するn個の方法 (1/2) - 原 悠‐ニコニコ動画(9)

1. RubyScript2Exe:把所有檔案在 temp dir 展開,速度比較慢。作者很久沒更新了,Ruby 1.8.6 之後無法使用。
2. Exerb:不使用 temp dir 的方式,有 RubyGems 相關問題,作者自己沒什麼在用了。
3. OCRA:只包進需要的檔案,所以比較快。建議使用。
4. Crate:把 code 和 lib 存在 sqlite3 db 裡。
5. Zip:把 win32 版 ruby 和所寫的程式放一起,寫個 .bat 檔啟動。Exerb 的作者現在用這方法。

個人經驗:
之前嘗試的時候,RubyScript2Exe 失敗;OCRA 在 XP 上可以,Win7 x64 不行;Exerb 想試還沒試(作者還有在更新);Crate 好像值得一試;zip 真是最後的終極解法(但和沒解差不多)。

演講的下半段,是把 web app 包起來當做桌面程式。

Filed under  //   exe   ruby  

OSDC.tw - Building a platform from open source

- Ability to scale != performance
- Premature optimization is the root of all evil. e.g. " v.s. ', echo v.s. print
- Do not use .htaccess (move to real apache config)

Filed under  //   php   symfony  

Assigning property values, Cascading, and Inheritance

/* From the user's style sheet */
p { text-indent: 1em ! important }
p { font-style: italic ! important }
p { font-size: 18pt }

/* From the author's style sheet */
p { text-indent: 1.5em !important }
p { font: normal 12pt sans-serif !important }
p { font-size: 24pt }
via w3.org

- 加上 ! important 的 declaration 會蓋過普通的 declaration 。
- 一般情況下,author 的 style 會蓋過 user 的 style;但加上 ! important 時,則是 user 蓋過 author。
- 例子中,前兩行 declaration 是 user 勝,第三行則是 author 勝。

The GNU General Public License - GNU Project - Free Software Foundation (FSF)

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:

<program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.

細節可參考「How to use GNU licenses for your own software」。

- 隨軟體附上檔名 COPYING,內容是 GPL 的純文字版

- 每個檔案開頭最好都要寫「This file is part of <program>.」,接著是 copyright notice(誰寫的)和 copying permission statement(表明使用 GPL)。把 <program> 和「this program」換成軟體名稱。

- 可以要求工作的雇主或學校簽署 copyright disclaimer,以免未來他們說著作權是屬於他們的。

Filed under  //   gpl  

jLinq - LINQ for JSON

var results = jLinq.from(data.users)
    .is("admin")
    .greater("age", 25)
    .orderBy("-age") //the '-' means descending
    .select();

LINQ 是 .NET 的 lib,選取部分資料時,可以 method chaining 方式,達到類似 SQL 的 operator,如 select、where……等的效果。
jlinq 這個 lib 則讓使用者可以對 JSON 裡的 object 下 LINQ style query。

Filed under  //   jlinq