アプリ作るよー
CoffeeScript で FaceBookアプリを書く。
で、FaceBookアプリってなんじゃらほいってことで
fb.dev+ の キャンバスチュートリアル を読んでみる。
ふーん。
CoffeeKup
CoffeeKup is markup as CoffeeScript.
CoffeeKup は、Coffeescriptで書かれたマークアップ。haml みたいな感じ。
CoffeeKup Intro の Hello,world.
head -> title 'Hello World' body -> <head> <title>Hello World</title> </head> <body> </body>
シンプルなのがいい。
Windowsでは、npm install -g したパッケージがエラーになる
公式の node.js のWindowsインストールパッケージをインストールすると node と一緒に npm もインストールされる。
C:\Users\kenchi>npm -g install underscore npm http GET https://registry.npmjs.org/underscore npm http 200 https://registry.npmjs.org/underscore underscore@1.3.3 C:\Users\kenchi\AppData\Roaming\npm\node_modules\underscore C:\Users\kenchi>node > var _ = require('underscore') Error: Cannot find module 'underscore' at Function._resolveFilename (module.js:332:11) at Function._load (module.js:279:25) at Module.require (module.js:354:17) at require (module.js:370:17) at repl:1:9 at REPLServer.eval (repl.js:80:21) at repl.js:190:20 at REPLServer.eval (repl.js:87:5) at Interface.<anonymous> (repl.js:182:12) at Interface.emit (events.js:67:17)
でも、-g 付きでインストールしたものを require するとエラーになっちゃう。global でなければ、カレントの .\node_modules 以下にインストールするけど、underscore とかはグローバルがいいな。
ってことでググる。
Node.js の起動オプション、環境変数、npm start の話
環境変数NODE_PATHが必要だと。
C:\Users\kenchi>npm -g bin C:\Users\kenchi\AppData\Roaming\npm (not in PATH env variable)
うちのPCは Windows 7 Home だから。xp だと Documents and Settings\(USER) 以下になる。
で、環境変数APPDATA を使うとOS依存しないで済む。
C:\Users\kenchi>echo %APPDATA% C:\Users\kenchi\AppData\Roaming C:\Users\kenchi>set NODE_PATH=%APPDATA%\npm\node_modules C:\Users\kenchi>echo %NODE_PATH% C:\Users\kenchi\AppData\Roaming\npm\node_modules C:\Users\kenchi>node > require("module").globalPaths [ 'C:\\Users\\kenchi\\AppData\\Roaming\\npm\\node_modules', 'C:\\Users\\kenchi\\.node_modules', 'C:\\Users\\kenchi\\.node_libraries', 'C:\\Program Files\\lib\\node' ]
環境変数NODE_PATH の内容が追加される訳だ。
> var _ = require("underscore") undefined
これでエラーにならなくなる。
ちなみに、nodeとか coffeescript の REPL から抜けるのは、Windowsの cmdだと CTRL+C を2回だ。
参考: npm についてまとめてみる (npmv1.1.0-beta-4/nodev0.6.6)
オブジェクト指向のパイプ
こんなやつ
PS> ls .android|foreach { Write-Host $_.Name, $_.LastWriteTime } avd 2011/01/01 16:28:28 androidtool.cfg 2011/01/01 16:28:47 ddms.cfg 2011/01/01 17:32:57 default.keyset 2011/01/01 16:28:48 modem-nv-ram-5554 2011/01/01 16:28:57 repositories.cfg 2011/01/01 17:32:57
lsは、Get-ChildItem, foreachは、ForEach-Objectの Aliasだ。
コマンドとメソッドの区別がつきにくいよね(笑
で、タイトルだけどパイプを .(ドット)に読み替えると、単にメソッドチェーンなだけだったりして。
でも、ま、便利だよね。
RSS の要素に対する条件指定
yql こと、Yahoo!Query Language の話
like と matches が使える。like は、SQL同等で、大文字小文字同一。
matches は、正規表現が指定出来る。user-time,service-timeを見た限りでは
どちらも大して変わらないかな。
ちなみにこれは、指定した RSS の title とか description でフィルタリングする
LOCAL Filters の話。query=... などのサーバへの queryでのフィルタリングは、REMOTE Filters となる。
select title,link,description,date from rss where url="http://news.rkb.ne.jp/rkb_news/index.xml" and description like "%北九州%" -- description に「北九州」を含むもの
select title from rss where url="http://mobiletsusin2.blog33.fc2.com/?xml" and title matches ".*au.*" -- title に「au」を含むもの
これの結果は、こう だ。
<?xml version="1.0" encoding="UTF-8"?> <query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="3" yahoo:created="2011-01-29T14:22:54Z" yahoo:lang="en-US"> <diagnostics> <publiclyCallable>true</publiclyCallable> <redirect from="http://mobiletsusin2.blog33.fc2.com/?xml" status="302"><![CDATA[http://feeds.fc2.com/fc2/xml?host=mobiletsusin2.blog33]]></redirect> <url execution-time="199" proxy="DEFAULT"><![CDATA[http://mobiletsusin2.blog33.fc2.com/?xml]]></url> <user-time>201</user-time> <service-time>199</service-time> <build-version>10970</build-version> </diagnostics> <results> <item xmlns="http://purl.org/rss/1.0/"> <title>【東日本】auシンプルコース 一括安売り情報 Part52</title> </item> <item xmlns="http://purl.org/rss/1.0/"> <title>au Cyber-shot S006 by Sony Ericsson stage 5</title> </item> <item xmlns="http://purl.org/rss/1.0/"> <title>au Cyber-shot携帯 S003 by Sony Ericsson stage4</title> </item> </results> </query>