不固定長度的 2D array 用 recursion 跑出所有組合

同事工作上遇到一個問題, 就是當不固定的 2d array 或是

不固定長度的數個 list 然後頭互串, 形成像是

A1->A2->A3, B1->B2 且 A1->B1 時

若要用 recursive 把所有的組合印出, 要怎麼處理?

最終我們要的答案是:

A1 B1, A2 B1, A3 B1, A1 B2, A2 B2, A3 B2

所以我的想法是很直觀的利用 recursive 做, 內容就是 先右再下 直到跑完所有情況

Continue reading “不固定長度的 2D array 用 recursion 跑出所有組合”

render of rails

通常我們用 render, 大多數是直接顯示字串, 但是他會把整個頁面蓋掉

render :text => ‘sth for show’

有時我們要用的是顯示模版並套用設計

render :template => ‘path to template’, :layout => ‘path to layout’

但是這次遇到一個情況, 如果我想傳參數進去的時候該怎麼辦, 找了一下發現可以直接傳參數

render :locals => { :sth => ‘content’, ‘sth2’ => ‘content2’ }

在 view 的部份可以直接調用

<%=sth%>

這樣就可以了

bug of app-admin/eselect-php

After upgrading(or installing, I forgot) the eselect-php-0.6.1, my lighttpd is broken.
Thanks chage, Airken and Keeper for help, the reason is the package will not select php module automatically.
Although the post-install information shows how to do that but it seems not very important that I ignore it.
If someone got the error of php, check the eselect setting.

1
eselect php show {cgi, cli, fpm, apache2}

If there is no default setting in them just do it.

1
eselect php set {cgi, cli, fpm, apache2} 1