<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>ilearnthis.com</title>
	<link>http://ilearnthis.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Wed, 19 Mar 2008 08:27:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>[PHP] たくさんのキーワードからn個(n行)をランダムに選択する（抽出する）</title>
		<link>http://ilearnthis.com/archives/7</link>
		<comments>http://ilearnthis.com/archives/7#comments</comments>
		<pubDate>Wed, 19 Mar 2008 08:27:41 +0000</pubDate>
		<dc:creator>groundwalker</dc:creator>
		
		<category><![CDATA[Service Development]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://ilearnthis.com/archives/7</guid>
		<description><![CDATA[
Webサービス作っていると、いくつかのアイテムから n個をランダムに選択したいときがあります。たとえば、人気のキーワードは日に数千あるけれど、上位10個を表示するだけだとランキング上位のキーワードが確固たる地位を築いてしまうだけで、おもしろくなかったりします。そんなときは上位1000個から10個のキーワードをランダムに選択して表示するようにすると、ユーザーもちょっとおもしろい気づきが得られたりするかもしれません。


たとえば、キーワードとその検索頻度を１行に並べた(csv形式やtsv形式）1,000キーワード（1,000行）からなるファイルが入力としてあるとしましょう。PHPで作るなら、


&#60;?
// number of output lines
$max=intval($argv[1]);

// open standard input
$h=fopen('php://stdin','r');
if (!$h) { die('stdin open error'); }

// put all lines into an array
$lines=array();
while(!feof($h)) {
  $lines[]=fgets($h);
}

fclose($h);

// shuffle the array of lines
shuffle($lines);

// output selected lines
for($i=0;$i&#60;$max;$i++) {
  echo $lines[$i];
}
?&#62;


のようなコードで、標準入力から読み込んだキーワードから、指定した n個をランダムに選択（抽出）することができます。たとえば、これを extract_n_randomly.php として保存し、


% php -q extract_n_randomly.php 10 < keywords.tsv


とすれば、実行するたびに異なる 10個 のキーワードを得ることができます。


ポイントは shuffle() ( cf. PHP: shuffle - Manual ) [...]]]></description>
			<content:encoded><![CDATA[<p>
Webサービス作っていると、いくつかのアイテムから n個をランダムに選択したいときがあります。たとえば、人気のキーワードは日に数千あるけれど、上位10個を表示するだけだとランキング上位のキーワードが確固たる地位を築いてしまうだけで、おもしろくなかったりします。そんなときは上位1000個から10個のキーワードをランダムに選択して表示するようにすると、ユーザーもちょっとおもしろい気づきが得られたりするかもしれません。
</p>
<p>
たとえば、キーワードとその検索頻度を１行に並べた(csv形式やtsv形式）1,000キーワード（1,000行）からなるファイルが入力としてあるとしましょう。PHPで作るなら、
</p>
<pre>
&lt;?
// number of output lines
$max=intval($argv[1]);

// open standard input
$h=fopen('php://stdin','r');
if (!$h) { die('stdin open error'); }

// put all lines into an array
$lines=array();
while(!feof($h)) {
  $lines[]=fgets($h);
}

fclose($h);

// shuffle the array of lines
shuffle($lines);

// output selected lines
for($i=0;$i&lt;$max;$i++) {
  echo $lines[$i];
}
?&gt;
</pre>
<p>
のようなコードで、標準入力から読み込んだキーワードから、指定した n個をランダムに選択（抽出）することができます。たとえば、これを extract_n_randomly.php として保存し、
</p>
<pre>
% php -q extract_n_randomly.php 10 < keywords.tsv
</pre>
<p>
とすれば、実行するたびに異なる 10個 のキーワードを得ることができます。
</p>
<p>
ポイントは shuffle() ( cf. <a href="http://jp.php.net/shuffle">PHP: shuffle - Manual</a> ) で、配列をランダムに並べ替えてくれます。</p>
]]></content:encoded>
			<wfw:commentRss>http://ilearnthis.com/archives/7/feed</wfw:commentRss>
		</item>
		<item>
		<title>[apache] 複数ドメインで同じディレクトリを参照させるには</title>
		<link>http://ilearnthis.com/archives/6</link>
		<comments>http://ilearnthis.com/archives/6#comments</comments>
		<pubDate>Wed, 19 Mar 2008 02:57:47 +0000</pubDate>
		<dc:creator>groundwalker</dc:creator>
		
		<category><![CDATA[Service Development]]></category>

		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://ilearnthis.com/archives/6</guid>
		<description><![CDATA[
SeverAlias を使えばいいんですね。参考: ServerAlias Directive @apache.org


たとえば name based virtual host 設定していて、example.com と www.example.com および w.example.com で /var/www/example.com を参照させたい場合、


&#60;VirtualHost *:80&#62;
    ServerName example.com
    ServerAlias www.example.com w.example.com
    DocumentRoot /var/www/example.com
    ....
&#60;/VirtualHost&#62;


のように設定すれば、設定が１カ所で済むわけですね。


さらに、RewriteRule を設定しておくと、すべてを example.com に集約したりすることができますね。


 RewriteCond %{HTTP_HOST} .*\.example\.com
 RewriteRule ^(.*)$ http://example.com/$1 [R=301]

]]></description>
			<content:encoded><![CDATA[<p>
SeverAlias を使えばいいんですね。参考: <a href="http://httpd.apache.org/docs/2.0/mod/core.html#serveralias">ServerAlias Directive @apache.org</a>
</p>
<p>
たとえば name based virtual host 設定していて、example.com と www.example.com および w.example.com で /var/www/example.com を参照させたい場合、
</p>
<pre>
&lt;VirtualHost *:80&gt;
    ServerName example.com
    ServerAlias www.example.com w.example.com
    DocumentRoot /var/www/example.com
    ....
&lt;/VirtualHost&gt;
</pre>
<p>
のように設定すれば、設定が１カ所で済むわけですね。
</p>
<p>
さらに、RewriteRule を設定しておくと、すべてを example.com に集約したりすることができますね。
</p>
<pre>
 RewriteCond %{HTTP_HOST} .*\.example\.com
 RewriteRule ^(.*)$ http://example.com/$1 [R=301]
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ilearnthis.com/archives/6/feed</wfw:commentRss>
		</item>
		<item>
		<title>WordPress コトハジメ</title>
		<link>http://ilearnthis.com/archives/4</link>
		<comments>http://ilearnthis.com/archives/4#comments</comments>
		<pubDate>Sat, 15 Mar 2008 16:50:55 +0000</pubDate>
		<dc:creator>groundwalker</dc:creator>
		
		<category><![CDATA[ilearnthis]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://ilearnthis.com/archives/4</guid>
		<description><![CDATA[
まず、このブログを作るにあたって学んだことは Wordpress ですよ。


WordPress › Blog Tool and Weblog Platform


groundwalker.comは、MovableType を使っていて、勝手もわかっているので、ver.4 になったことだし、MT 使おうかと思いましたが、違うシステムも使ってみないと、と思い直しましたです。


ということで、インストール手順をまとめておきます。なおインストールしたサーバーは FreeBSD のレンタルサーバーです。逆引きすればどこかわかりますけどね。。。


WordPress › Download から .TAR.GZ 版をダウンロードして、DocumentRoot にするディレクトリに展開。

% wget http://wordpress.org/latest.tar.gz
% tar xvfz latest.tar.gz
% mv wordpress $DocumentRoot


http://yourdomain/ にアクセスすると、ウィザードが始まるので、MySQLのアカウント用意して入力して完了。


次はテーマのインストールだ。
]]></description>
			<content:encoded><![CDATA[<p>
まず、このブログを作るにあたって学んだことは Wordpress ですよ。
</p>
<p style="text-align:center">
<a href="http://wordpress.org/">WordPress › Blog Tool and Weblog Platform</a>
</p>
<p>
<a href="http://groundwalker.com/blog/">groundwalker.com</a>は、<a href="http://www.movabletype.org/">MovableType</a> を使っていて、勝手もわかっているので、ver.4 になったことだし、MT 使おうかと思いましたが、違うシステムも使ってみないと、と思い直しましたです。
</p>
<p>
ということで、インストール手順をまとめておきます。なおインストールしたサーバーは FreeBSD のレンタルサーバーです。逆引きすればどこかわかりますけどね。。。
</p>
<ol>
<li><a href="http://wordpress.org/download/">WordPress › Download</a> から .TAR.GZ 版をダウンロードして、DocumentRoot にするディレクトリに展開。
<pre>
% wget http://wordpress.org/latest.tar.gz
% tar xvfz latest.tar.gz
% mv wordpress $DocumentRoot
</pre>
</li>
<li>http://yourdomain/ にアクセスすると、ウィザードが始まるので、MySQLのアカウント用意して入力して完了。</li>
</ol>
<p>
次はテーマのインストールだ。</p>
]]></content:encoded>
			<wfw:commentRss>http://ilearnthis.com/archives/4/feed</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;Stay hungry, stay foolish.&#8221; と Steve Jobs は言っていましたよ</title>
		<link>http://ilearnthis.com/archives/3</link>
		<comments>http://ilearnthis.com/archives/3#comments</comments>
		<pubDate>Sat, 15 Mar 2008 13:47:37 +0000</pubDate>
		<dc:creator>groundwalker</dc:creator>
		
		<category><![CDATA[ilearnthis]]></category>

		<category><![CDATA[lifehack]]></category>

		<guid isPermaLink="false">http://ilearnthis.com/archives/3</guid>
		<description><![CDATA[
正確に言うと、Steve Jobs が スタンフォード大学の2005年6月12日 の 卒業スピーチで、Whole Earth Catalog - Wikipedia の 1974年版の裏表紙に添えられた言葉を引用したのですが、その当時にこのスピーチを聞いてから今日までの時間の中で、一番心に残っていることに気づいていたたわけです。


さっさと始めればいいのにずるずると来ましたが、常に学び続ける実践の記録を残すべく ilearnthis.com をはじめてみました（やっと）。自分が調べ知ったことや、考えたこと、やってみたことをつらつらと書きつつ、公開することで得られるかもしれないフィードバックもまた学ぶソースにしていけたらいいなと、思います。


Steve Jobs Speech


スピーチ全文はこちら » Text of Steve Jobs&#8217; Commencement address (2005)


最後に該当部分の引用をしておきます。


&#8230; On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath [...]]]></description>
			<content:encoded><![CDATA[<p>
正確に言うと、Steve Jobs が スタンフォード大学の2005年6月12日 の 卒業スピーチで、<a href="http://en.wikipedia.org/wiki/Whole_Earth_Catalog">Whole Earth Catalog - Wikipedia</a> の 1974年版の裏表紙に添えられた言葉を引用したのですが、その当時にこのスピーチを聞いてから今日までの時間の中で、一番心に残っていることに気づいていたたわけです。
</p>
<p>
さっさと始めればいいのにずるずると来ましたが、常に学び続ける実践の記録を残すべく ilearnthis.com をはじめてみました（やっと）。自分が調べ知ったことや、考えたこと、やってみたことをつらつらと書きつつ、公開することで得られるかもしれないフィードバックもまた学ぶソースにしていけたらいいなと、思います。
</p>
<p>
<a href="http://myspacetv.com/index.cfm?fuseaction=vids.individual&#038;videoid=2232744">Steve Jobs Speech</a><br /><embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=2232744&#038;v=2&#038;type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>
</p>
<p>
スピーチ全文はこちら » <a href="http://news-service.stanford.edu/news/2005/june15/jobs-061505.html">Text of Steve Jobs&#8217; Commencement address (2005)</a>
</p>
<p>
最後に該当部分の引用をしておきます。
</p>
<blockquote><p>
&#8230; On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: &#8220;Stay Hungry. Stay Foolish.&#8221; It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. &#8230;
</p>
</blockquote>
<p>私的訳</p>
<blockquote><p>
&#8230; （The Whole Earth Catalog の）裏表紙には、君たちが冒険してヒッチハイクするような早朝の田舎道の写真があって、その写真の下に最後に読者に送る言葉として添えられているんだ。 &#8220;Stay Hungry. Stay Foolish.&#8221; 常に私自身そうあろうと思っているよ。&#8230;
</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ilearnthis.com/archives/3/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
