July 2005

Entries Title

0 = false ?

Date
2005-07-31 (Sun)
Category
Tech

PHP では値評価の際、0 を false に自動変換してくれること多々です。それって非常に便利なときもあるんですけど、今回もハマりました…

ある文字列を一文字ずつ substr して、parse する、という関数を作りました。なんと言うかは知りませんが、疑似コードではこんな感じ。

while( $char = substr($strings, 0, 1) ) {
	switch ($char) {
		//do something
	}
}

ところが。PHP では文字列の "0" や int型/float型や の 0(.0) などを false と同値に扱ってしまうというたまに便利な仕様があります。ので上の用な形でコードを書いていると、結構ハマりました…

Between maker and user

Date
2005-07-31 (Sun)
Category
Tech

This article describes some typical mistake of making a "system", based on my experieince.

When I make some system -- the way of organizing letters, legos, clothing... any system is ok, but on this article, I am talking about computer software, which is related organizing --, as a dweller of IT world, I tried to understand and systemize the structure, and make it easier to do it. But as an user, it is totally different, sometimes. I mean, sometimes, the way I accept and do is very different from the abstracted ideal framework.

Now I am working on a CMS, specialized for making gallery site, easily. I've been working with a lot of artists. They want to make some fancy web-site, but some of them are kinda aggressive and if they can, they want to do daily updating task by themselves. Which is very good, in terms of designer. As all of you know, updating may be very boring, and recurring "mac-job", right? Anyway, there are a lot of reasons why I'm making it from the scratch, but that's another story.

So, my gallery CMS stands for the following big three cornerstone. 1) Scale free categorization, 2) web-based management, and 3) backend and frontend is separated and communicating by XML.

As No. 1, I adopt so-called "Folksonomy". Simply saying, the "tag". So, in my system, users can add tag on each content, and visitors can see those contents by tags.

Since there are almost no free implementaions of XML-native databases (if someone knows, please lemme know.. at lease some of them don't attract me a lot in many ways), I use RDB (MySQL) as a backend, and I guess there are not many implementaions of folksonomy on it. You know, put the tag on one table, and make another tag-index table, which describe the association between tags and contents. (if you want, you can make it flat, but I prefer two separated..)

But, but, but. The way of visitors exploring the things, and creators' most intuitive ways of organizing contents are a little bit different from the implementations.. Is it my fault of implementaions?? I dunno.. but I guess my lesson from this pit, is that interface can make it easy and I need more user tests...

input element in Safari,

Date
2005-07-31 (Sun)
Category
Tech

我らが Apple Official ブラウザ、Safari 1.3 以降 では DashBoard 拡張の為、input エレメントで、type="search" というのが使えます。例えば以下。

つまり、safari の Google 検索 ボックスと同じのが、HTML エレメントとして使えると言うことです。Source を見ればわかりますが…

placeholder
規定値
results
保存しておく履歴件数
autosave
履歴の保存名?

でしょうか。Safari が何処に履歴を保存しているのか知りませんが、autosave で associate されているものはどのドメインでも参照できそうな感じがするのは気のせい?

The news.

Date
2005-07-31 (Sun)
Category
diary

Well, I've been absent for 2 weeks. The big news is I got a job. Even though it's a little different from what I've been doing, you know, it's good to have a job. They promised me to sponser a visa too. I will give a shot, and see what happens.

BTW, since there's not many people reading this... in this blog, I will write down usual daily thing in English, and more technical thing or translation in Japanese, I guess.

when you're in Rome... (PHP's count() in javascript)

Date
2005-07-18 (Mon)
Category
Tech

PHP equivalent in Javascript シリーズ。PHP の count() ってどうやるの!?…

とかいって、結構必死に探してしまった。もうにちゃんで質問しようと思ったくらい。で、書き込む瞬間手前で思い出した。そうだ、Java 配列の長さは length property だったな、と。

javascript でもそうでした。っていうより、当たり前ですよね…使った覚えあるし。なれと言うのは怖いもので…

type in php

Date
2005-07-18 (Mon)
Category
Tech

PHP では int型 0 と boolean型 false が基本的に同値と見なされる、というか値評価の時には int型 0, String型 の "0", と 空白文字列 は boolean型 false に勝手にキャストされる、というのが正確なんですけど…まぁおかげでバグを埋め込んだり(先日あるライブラリにバグを発見して送ってみたら、返事が返ってきて、メンテナをやって欲しそうな感じだった…)、以下の様なことをするのに、やや美しくないことをしなくては行けない。忘れないためのメモでした。

$position = strpos($contents, "\n");
while ( $position !== false ) {
	array_push( $lines, substr($contents, 0, $position) );
	$contents = substr($contents, $position + 1);
	$position = strpos($contents, "\n");
}

xml generator

Date
2005-07-13 (Wed)

PHP ってやっぱり template エンジンだと思うので。XML みたいなのを作るのは便利なんじゃないかな〜って思います。でもなんか、軽量で簡単な XML class って見つからず、結局自作しました。結構便利です。

  • _name_ が tag 名になる
  • attribute を付けたい時は _ATTR_NAME_ と名前の前後を _ アンダースコアで囲む
  • channel があるのは RDF が最初目標だったから
  • dc:time 用の関数は昔書いたけど、今何処にあるかわからずほったらかし。

こんな所でしょうか。使う人なんていないと思うけど、もしも使った!と言う人は コメント/メール でご意見をお待ちしております。

Continue reading

PHP's foreach in Javascript

Date
2005-07-13 (Wed)

もう同じネタばっかり。「PHP の〜〜って javascript でなに?」foreach 編。

foreach equivalent

よくまとまってます。日本語で重要な点を抜き出します。 PHP だと

foreach ($array_or_object as $key => $value){
// $key and/or $value で 配列、またはオブジェクトのキーと要素、両方にアクセス可能、
// あるいは
}
foreach ($array_or_object as $eachObject){
// $eachObject は $array_or_object の小要素。
// そこに含まれているのが Object あるいは Array なら、Object/Array が帰って来る。
}

javascript だと
for ($key in $objectOrArray){
// $key で帰ってくるのは 配列、または オブジェクトのキーのみ。要素は別にアクセスしなくちゃ行けない…
}

と言うことみたいです。

PHP's print_r in javascript

Date
2005-07-12 (Tue)
Category
Tech

I google "javascript print_r" and I found BrandNewBox. It's almost same as what I really wanted. So I changed a little bit, and put it here.

PHP の print_r みたいなこと出来る javascript は無いかなぁと思って、Google してみたら、BrandNewBox を見つけました。惜しい!ので、作り直したのを以下に。

function print_r( theObj, outputObjId ){
	if ( theObj.constructor == Array || theObj.constructor == Object ) {
		var superUlElement = document.createElement("UL");
		for ( var p in theObj ){
			var liElement;
			var text;
			liElement = document.createElement("LI");
			if ( theObj[p].constructor == Array || theObj[p].constructor == Object ) {
				text = document.createTextNode( "[" + p + "] => " + typeof(theObj) );
				liElement.appendChild(text);
				if ( childUlElement = print_r( theObj[p], "__super__" ) ) {
					liElement.appendChild(childUlElement);
				}
			} else {
				text = document.createTextNode( "[" + p + "] => " + theObj[p] );
				liElement.appendChild(text);
			}
			superUlElement.appendChild(liElement);
		}
		if ( outputObjId != "__super__" ) {
			document.getElementById(outputObjId).appendChild(superUlElement);
		} else {
			return superUlElement;
		}
	} else {
		return null;
	}
}

CMS

Date
2005-07-05 (Tue)
Category
Tech

実は今、予算をもらって、簡単な CMS を作っています。Content Management System なんていうと聞こえがいいですが、Blog ツールは CMS ですから、使っている人はあれの管理画面なんかを思い浮かべてもらえれば。

しかし、そう思うと、MovalbeType ってよく出来てるなぁ。数週間で作り上げるってのはちょっと難しいです。はい。

Return to Page Top