Thursday, May 07, 2009
單個
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Range: Bytes=0-50\n"));
多個
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Range: Bytes=0-50\nOtherheader: stuff\n"));
Thursday, April 16, 2009
欲在Symphony(PDO使用Propel)下從DB拿多列的資料,目前看到這是唯一可行的方法:
$connection = Propel::getConnection();
$query = 'SELECT MAX(%s) AS max FROM %s'; //写你要查询的sql
$query = sprintf($query, ArticlePeer::CREATED_AT, ArticlePeer::TABLE_NAME);
$statement = $connection->prepare($query);
$statement->execute();
$resultset = $statement->fetchAll(PDO::FETCH_OBJ);
最後一行如果用fetch就是只拿一列,fetchAll就拿所有列。 $resultset是個array,裡面有所有列的資料。
但這是Propel裡的東西,而非Symfony本身的。 Symfony本身的doSelect()只能拿到第一筆的資料,但列的數目又是對的。 我查了好久的文件還是找不到為什麼會這樣。 doSelectstmt()也懶得試了… Symfony真的很鳥啊!
Edit:
用了doSelect
$c = new Criteria();
$c->add(ListsPeer::MAC_ADDRESS, $mac, Criteria::EQUAL);
$stmt = ListsPeer::doSelectStmt($c);
$ids = array();
while($res = $stmt->fetchColumn(1)) {
echo $res;
}
還是可以用的啦… 算了。
Labels: PHP, Symfony, Web Programming
Tuesday, April 14, 2009
Using Propel ORM. My step-by-step walkthrough to create a working model:
There are several commands concerning the ORM which ultimately works toward building a Model.
The schema.yml, which represents the schema for a Model, can be either typed by hand, or imported and built directly from a database. To do so, type:
symfony propel:build-schema
Or if there is no corresponding database in the db, you may enter the schema by hand. After doing so, type
symfony propel:build-sql
to convert the schema into SQL commands. The actual SQL commands are stored in the lib.model.schema.sql inside the data/sql/ directory of the project folder. You can actually skip the build-sql step by editting this file directly...
After the build-sql command, you can insert the SQL commands into the db, provided that you have already configured the connection to your db. Use either
symfony configure:database "mysql:host=localhost;dbname=db_name"
or edit your
Once the connection to the db server are set, insert the SQL by typing:
symfony propel:insert-sql
This step will remove tables with the same names defined in the SQL in the db. Clearing Symfony cache is recommended after this step:
symfony cc
Then it's finally time to build Model so that we can use the ORM to access db:
symfony propel:build-model
Note: Actually, you MAY build Model directly from schema.yml, but it'd be pretty pointless without making sure your Model has a working db connection, right?
Labels: PHP, Symfony, Web Programming
Wednesday, April 01, 2009
P3P for cross-domain/remmote iframe cookie pass?! WTFOMGBBQ?! (Chinese version)
0 comments Posted by fatearthling at 3:44 PM為了某個不足為外人道之原因,在下做了這件感覺起來很蹩腳很挫的事… >_< 真的要拿出去討論的話,可能我還得好一陣子的心理建設才敢拿出去曝光… 但如果有幸有哪位前輩高手不幸在blogger看到這篇的話,還不吝留下您的意見; 像是更好的做法… 等等。 小弟感激不盡。m(_ _)m
以下這一段是要達到效果的描述:
一個母網頁頁面,必須將其cookie丟到其所包含之一個iframe裡所指到的一個不同domain的網頁(姑且稱此網頁為子網頁)。 而子網頁必須要能拿到母網頁的cookie來做一些… 見不得人的事兒。 在開啟母網頁同時,即需可看到母網頁下iframe裡的子網頁根據母網頁的cookie所做出的頁面。
為了做這件事,在擦股溝擦了好一會兒後,所做出的解答如下:
母頁面就只是一個html,除了一些讀寫刪cookie的Javascript functions外,還包括兩個iframe:
<iframe id="test1" src ="http://howard.com/cookiecutter.php?cooke_name=cookie_value" width="300px" height="100px" >
cookiecutter.php:
<?php
header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
$keys = array_keys($_GET);
header("Set-Cookie: ".$keys[0] ."=" . $_GET[$keys[0]]. "; domain=.howard.com; path=/"); ?>
cookiecutter.php較特別的是那一行header P3P的code。 P3P全名為:「The Platform for Privacy Preferences」。 基本上就是跟網頁瀏覽器說,我知道我現在要做的事不合規定或不安全,但你就讓我做就是了。 然後下一行header set-Cookie就在howard.com上設一個名字和值為cooke_name和cookie_value的cookie。
值得注意的是,如果拿掉P3P那一行,剛剛設的這個cookie在母頁上將拿不到。
如此,雖然是達成了目標,但是不管怎麼看,都應該只能算是很粗糙的解決方案,並不是真正的cookie passing。 小弟在此拋磚引玉,還希望各位先進們指教一下。
Labels: Javascript, Web Programming, 心得
Monday, March 30, 2009
A fragment identifier is defined by RFC 3986 as an optional component of a URI reference, and it must conform to a certain syntax. The syntax requires that the fragment identifier be separated from the rest of the URI reference by a # (number sign) character. The separator is not considered part of the fragment identifier.
Basically it looks like http://www.foo.org/foo.html#fragment-identifier.
To use it in Javascript, it is simply "window.location.hash"
Labels: Javascript, Web Programming
This is an imitation of PHP $_GET, in pure Javascript.
From http://www.11tmr.com/11tmr.nsf/D6Plinks/MWHE-695L9Z
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 )
{
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return unescape(strReturn);
}
Labels: Javascript, Web Programming
Friday, March 20, 2009
網頁瀏覽器: 火狐狸
附件:
- IE Tab
- Firebug
- Multiple IE
(待改)
Labels: 心得
Thursday, March 19, 2009
今天又學到了一個幫助CSS在IE7、IE6和Firefox上都能跑得一樣,但屬旁門左道的小技巧。 只能心裡腹誹IE不遵守規範…
以下例的css作為例子:
.context_bar_form_field
{
height: 15px;
#height: 15px;
_height: 21px;
}
- The first setting will apply to all browsers,
- The second setting will only apply to Microsoft Internet Explorer browsers
- The third setting will only apply to IE browsers 6.0 and older
Labels: CSS, Web Programming, 他奶奶的IE, 心得
Tuesday, March 17, 2009
今天在跟BT Box的網頁頁面的css奮鬥了一整天,一直無法將下拉式選單蓋過其下面的頁面元素。 就在要放棄之餘,突然發現了這篇文章:
http://css-discuss.incutio.com/?page=OverlappingAndZIndex
才知道原來 z-index 是不能亂設的。 譬如說想要一個dd元素可以蓋過別的頁面元素,這個dd元素的母元素盡量不要設z-index, 而只為此dd元素設一個高過想要蓋過的頁面元素的 z-index 的 z-index。 但似乎這個文章所說尚不止如此,得要好好再讀一下。
以前那他媽的知道這種隱藏版規則啊! (翻桌) 唉…
Labels: CSS, Web Programming, Work Stuff, 心得
Wednesday, February 18, 2009
Labels: 好笑
Tuesday, October 11, 2005
/usr/sbin/named.restart
Labels: Linux, Work Stuff
Monday, August 15, 2005
All from http://www.study-area.org/tips/tipsfr1.htm
% 這是匹配 {},[],() 用的,例如您的游標現在在 { 上
只要按 %,就會跑到相匹配的 } 上。寫程式時滿好用的。
. 這是什麼?ㄚ,是英文句點啦!沒錯,就是英文句點。什麼意
思?重複前次的編輯動作。這個指令太高明了,只要是編輯動
作(移動游標不算,冒號命令也不算)都可以按英文句點來重
複,要重複幾次都可以。
- 例如:您按了 yy,然後按 p 就會複製、貼上一整行,如果要重複這個動作的話,就可以按 . ,也可以把游標移到其它地方後再按。其它 dd,dw,r,cw 等編輯指令都可以這樣來重複。如果您要重複做某些編輯動作時,千萬千萬一定要想到有這麼一個英文句點重複指令。ㄚ,拜託啦!您一定要常用這個指令。
"ayy 將本行文字複製到 a 緩衝區
- a 可為 26 個英文字母中的一個,如果是小寫的話,原先的內容會被清掉,如果是大寫的話是 append 的作用,會把內容附加到原先內容之後。
- " 是 Enter 鍵隔壁的那一個同上符號(ditto marks)。
"ap 將 a 緩衝區的內容貼上。
- 緩衝區的術語在 vim 稱為 registers,vim 擴充了相當多的功能,有興趣深入的朋友請 :h registers。您用 d、c、s、x、y 等指令改變或刪除的內容都是放在 registers 中的。例如:您用 dd 刪除的一行,也是可以使用 p 來貼上的。只要是在緩衝區的內容都可以使用 p 來貼上,不是一定要 y 起來的內容才能用 p。因此您認為 p 是 paste 也可以,認為是 put 可能較正確。
5"ayy 複製五行內容至 a 緩衝區。
5"Ayy 再複製五行附在 a 內容之後,現在 a 中有十行內容了!
- ㄟ!不要我一直用 a 您就認為只有 a 可以用喔。26 個英文字母都可以的,交叉運用下,您會發覺 vi(m) 肚量不小。
- 問題來了!忘記誰是誰的時候怎麼辦? :reg(冒號命令)就會列出所有 registers 的代號及內容。您現在就試著按看看。咦!怎麼還有數目字、特殊符號的緩衝區,原來您剛剛刪除(複製)的內容就預設放在 " 這個緩衝區,然後依序是 0,1,2,...9。也就是說您按 p 不加什麼的話,是取出 " 緩衝區的內容的。% 指的是目前編輯的檔案,# 指的是前一次編輯的檔案。還有其它的呀!因為沒什麼重要,就請 :h registers 吧!registers 有個 "s" 結尾,不要搞錯了,而且 Tab 的補全鍵 vim 也支援的,也就是說您鍵入 :h regi 再按 Tab 鍵,vim 就會幫您補全,按了 Tab 後發現不是您要的,那就繼續按,總會出現您要的。:-)
- Tab 補全的功能,elvis 也有,但叫出 registers 列表的命令則沒有,您得自行記憶在您的腦袋瓜子裡。而且 elvis 的補全能力並沒 vim 強。
/ 在 c-mode 的情形下,按 / 就會在左下角出現一個 /,然後鍵
入您要尋找的字串,按個 Enter 就會開始找。
? 和 / 相同,只是 / 是向前(下)找,? 則是向後(上)找。
n 繼續尋找。
N 繼續尋找(反向)。
:[range]s/pattern/string/[c,e,g,i]
range 指的是範圍,1,7 指從第一行至第七行,1,$ 指從第一行
至最後一行,也就是整篇文章,也可以 % 代表。
- 還記得嗎? % 是目前編輯的文章,# 是前一次編輯的文章。
- g 大概都是要加的,否則只會替換每一行的第一個符合字串。可以合起來用,如 cgi,表示不分大小寫,整行替換,替換前要詢問是否替換。
這樣整篇文章的 Edwin 就會替換成 Edward。
mx x 代表 26 個小寫英文字母,這樣游標所在處就會被 mark。
`x 回到書籤原設定位置。
- ` 是 backward quote,就是 Tab 鍵上面那一個。
'x 回到書籤設定行行首。
- ' 是 forward quote,是 Enter 鍵隔壁那一個。
:marks 得知目前所有書籤的列表。
Labels: Linux, Work Stuff
Monday, August 01, 2005
RRDtools: tms1.above.net.tw/home/tms
pserver1.above.net.tw/home/tms
Labels: Linux, Work Stuff
Tuesday, June 28, 2005
To restart Dragon, check if monit is running first, and stop monit first before stopping Dragon.
Start pserver first -> proxy -> presence -> login
command to start Dragon: /usr/local/dragon/etc/dragond [start|stop|restart]
tail /var/log/dragon.log to see if it's running all services.
monit:
/etc/init.d/monit stop/start
postgres:
/etc/init.d/postgresql restart
su - postgres -c "command"
Labels: Linux, Work Stuff
Wednesday, May 25, 2005
urlopen(siteurl, [postdata])
-------------------------------
If you want GET (like open a page in a browser) just omit postdata like urlopen('http://google.com')
If you want POST (like sending a form) include postdata - values for all form variables.
Data must be prepared for HTTP transfer, that's what is urlencode for.
It takes sequence of pairs or dictionary. Dictionary constructor is convinient as you can use var names as keywords.
So all you need is to get all vars (visible and hidden all alike) and get them values.
To actually perform operation you usually .read() result of urlopen.
Labels: Python, Work Stuff
Monday, May 23, 2005
To start httpd under FreeBSD (just so I won't forget):
/usr/local/sbin/apachectl restart
or
/usr/local/etc/rc.d/apache2.sh restart
rt3 is installed in /usr/local/rt3
mysql:
/usr/local/etc/rc.d/mysql-server.sh restart
Labels: Linux, Work Stuff
