• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
 
 

環境

クライアント:携帯
サーバ

  • apache
  • mongrel
  • mongrel_cluster
  • rails

+actionキャッシュを使用している。

   1  class BlobsController < ApplicationController
   2    layout nil
   3    caches_action :show
   4    session :off, :only => :show

状況

cacheがないページにアクセスすると、正しく表示される。どうやらcacheを返したときに、(携帯で)うまく表示できない様子。
PCではcacheがあっても、なくても正しく表示される:firefox。PCのブラウザは賢い。

ログを確認:cacheがあるのでhaltedしたというメッセージ

これはcacheがあるので、ActionCacheFilterを中止して、cacheを返す時のメッセージ。なのでエラーではない。

   1  Processing BlobsController#show (for 219.125.148.54 at 2008-07-02 10:49:02) [GET]
   2    Parameters: {"digest"=>"d8de32d0ad4bcf08016c6cedd31d426b", "action"=>"show", "controller"=>"blobs", "formats"=>[]}
   3  Filter chain halted as [#<ActionController::Caching::Actions::ActionCacheFilter:0xb72d10c4 @actions=#<Set: {:show}>, @options={}>] rendered_or_redirected.
   4  Filter chain halted as [#<ActionController::Filters::ClassMethods::ProcWithCallFilter:0xb72d0de0 @filter=#<Proc:0xb751d184@/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:657>>] did_not_yield.
   5  Completed in 0.00035 (2833 reqs/sec) | DB: 0.00000 (0%) | 200 OK [http://mmmuji.s21g.com/blobs/d8de32d0ad4bcf08016c6cedd31d426b]

詳しく状況を確認:Content-Typeが正しくない

サーバ、クライアントの両方のキャッシュを削除して、サイドブラウザからアクセス、画像を表示してfirefubのNetタブで確認すると、Content-Type: jpg; charset=utf8となっている。
瀧内さんからもらったアドバイス:caches_actionはヘッダーをキャッシュしないmongrelはヘッダーについてKY(空気読まない)
mongrel_jpg_cache.png

Content-Typeを設定するいくつかの方法

  1. mongrelで設定
  2. plugin(cache_fuなど)を使う
  3. railsで設定:config/initializers/mime_types.rb
  4. 表示時に設定(これはaction_cachesはヘッダーをキャッシュしないので、キャッシュ表示時には意味がない)

結論:正しいContent-Typeは(特に携帯には)大事

上記の方法以外にも、mongrelをやめるという選択肢もあるのですが、とりあえず、railsでヘッダを設定するのはmongrelをやめても邪魔にならない設定であるのでそれをやってみました。
mongrel_jpg_cache_with_mime_type.png
正しくContent-Typeが設定され、携帯からでもちゃんと表示されました!

後mime_types.rbでimage/jpgなどと致命的ミスをしてハマったというのもありました。

Refs

http://rubyforge.org/pipermail/mongrel-users/2006-May/000237.html
http://www.igvita.com/2007/06/13/caching-and-mime-types-in-rails/:cache_fuでのmime_typeキャッシュ

posted by Png satoko on Wed 2 Jul 2008 at 17:02

caches_pageとの違い

caches_actionはcaches_pageと似ていますが、依然としてすべてのリクエストがAction Packを通って処理されるようになっています。これは認証や他の制限をつけたいときに便利です。

"/lists"と"/lists.xml"は別々にキャッシュされる

また、http://blog.s21g.com/listsとhttp://blog.s21g.com/lists.xmlは異なるリクエストとして処理され、別々にキャッシュされます。つまり、:action => "lists"のキャッシュが無効になったからといって、:actioin => "list", :format => ":xml"も無効になるわけではありません。

キャッシュの無効化

expire_actionでキャッシュを無効化できます。Sweepwerを使って処理、タイミングを書く。caches.rbのサンプルを抜き出します。

   1  class ListSweeper < ActionController::Caching::Sweeper
   2      observe List, Item
   3  
   4      def after_save(record)
   5         list = record.is_a?(List) ? record : record.list
   6         expire_page(:controller => "lists", :action => %w( show public feed ), :id => list.id)
   7         expire_action(:controller => "lists", :action => "all")
   8          list.shares.each { |share| expire_page(:controller => "lists", :action => "show", :id => share.url_key) }
   9        end
  10     end
  11   
  12  class ListsController < ApplicationController
  13      caches_action :index, :show, :public, :feed
  14      cache_sweeper :list_sweeper, :only => [ :edit, :destroy, :share ]
  15  end

Refs

vendor/rails/actionpack/lib/action_controller/caching.rb
http://scottstuff.net/presentations/rails-caching/ かなり詳しい
http://www.ibm.com/developerworks/web/library/wa-rails1/
http://www.hostingrails.com/forums/rails_coding_thread/386

posted by Png satoko on Sat 28 Jun 2008 at 01:19

昨日、今日と二日続けてrepoが壊れたので解決策を探ってみました。コミットはこまめにしておくのが吉だと思います。

   1  $ git status
   2  error: bad signature
   3  fatal: index file corrupt

git-fsck --fullというコマンドも試してみたのですが、やっぱりだめ。というわけで、ダメもとで下記をやってみたらすんなり復旧できた。yay!

After trying many things, I deleted .git/index and ran git-reset which regenerated the file.
http://www.nishioka.com/blog/2008/01/source-control-with-git-and-cygwin.html

つまり下記でok!

   1  $ rm .git/index 
   2  $ git reset

Refs

http://www8.atwiki.jp/git_jp/pub/Documentation.ja/user-manual.html#recovering-from-repository-corruption

おまけ

誰かがバグを修正してコミットしてくれて、自分の手元のrepoが古くなったとき、rebaseすれば最新のをfetchしてきてくれます。

   1  $ git svn rebase

posted by Png satoko on Thu 26 Jun 2008 at 11:20

via http://groups.google.com/group/twitter-development-talk/browse_thread/thread/6f24e47cca5b68f6

We've successfully moved to the OpenFire Jabber server, and now have far more visibility into our XMPP services overall.

だから20req/hr制限なのかしら。
それにしても、早くtrackを復活させて欲しいです。
http://twitter.com/account/rate_limit_status.xml

OpenFireとは

Javaで書かれているそうです。twitterが以前使っていたejabberdはErlang。そしてあんまり情報がない...

Openfire (formerly Wildfire) is a real time collaboration (RTC) server dual-licensed under the Open Source GPL and commercially. It uses the only widely adopted open protocol for instant messaging, XMPP (also called Jabber). Openfire is incredibly easy to setup and administer, but offers rock-solid security and performance.
http://www.igniterealtime.org/projects/openfire/index.jsp

twitterが以前使っていたJabberServer:ejabberd

http://www.jabber.org/servers/ejabberd
http://www.atmarkit.co.jp/news/200704/27/erlang.html

Refs

http://www.jabber.org/servers
http://www.jabber.org/servers/openfire

posted by Png satoko on Wed 25 Jun 2008 at 15:39

http://drnicwilliams.com/2008/06/18/what-is-gitjour-gemjour-starjour/

USではRailsCampという合宿みたいな、田舎で数日籠ってhackして遊んだりなんかするというのが流行しているようですが、田舎ではインターネットがないことも多く、それで共同作業したりなんかするのに困ったという経験からいろいろツールが出てきたみたいです。

インストールの手順(必要なgemとか)はDrNicのサイトにありますので、そちらを参照してくださいね。

始まりはBonjour(Macの通信プロトコル)のオープンソース化

http://en.wikipedia.org/wiki/Bonjour_(software)

gitjour

Chad Fowlerさんたちが作ったこのツール、ローカルでgitリポジトリを共有するツールです。
http://github.com/chad/gitjour

pastejour

今度はJohn Barnetteさんが作ったpastejour。これはInternet(pastie)がなくても、コードのsnnipetを送れる仕組み。
http://github.com/jbarnette/pastejour

gemjour

さらにEvan Phoenixさんが、gemのサーバ機能を提供。誰かのローカルにあるgemを取ってこれるようになります。
http://github.com/evanphx/gemjour/tree/master

appjour:Macオンリー

Lachie Cox作。appをみんなで共有できます。
http://github.com/lachie/appjour

dejour:Macオンリー

Aaron Patterson作。Growl(Macの通知バルーン?)の仕組みを使った、ローカルネットワークでtwitterみたいな感じ?のようです。
http://github.com/aaronp/dejour/tree/master

stajour:Macオンリー

Lachie Cox作。上の通知を一覧にして表示できるアプリ。
http://github.com/lachie/starjour

最後のほうはMacオンリー。残念です... あとあと、USのギークたちはみんなでGuitar Hero3やったりするみたいですね...

posted by Png satoko on Thu 19 Jun 2008 at 13:31

rails tipsコンテストの流れで出会った記事。
http://scoop.cheerfactory.co.uk/2008/04/25/5-rails-tips/

上記で紹介されていた「Use of to_param for cheap seo」というのを実践してみました。これはAmazonで以前から実施されているSEOなのですが、ARのクラスでto_paramメソッドを用意すればいいだけだったのでやってみました。(コントローラではparam[:id]でIDを取得できるようです)

上記サイトで上がっていた例

   1  class ArticleActiveRecord::Base
   2    def to_param
   3      "#{id}-#{headline.gsub(/[^a-z0-9]+/i, '-')}".downcase
   4    end
   5  end
コードの詳細は下記をどうぞ。

一方、dummyパラメータを送ってもid=5の記事が見れてしまうという問題もあります:下記のどのURLを要求しても同じarticleが表示される。
http://myaceapp.com/articles/5
http://myaceapp.com/articles/5-railscasts-rocks
http://myaceapp.com/articles/5-ANYTHINGHEREATALL

s21gブログでのコード

   1  class ArticleActiveRecord::Base
   2    def to_param
   3      "#{id}-#{CGI.escape(title)}".downcase
   4    end
   5  end
(注) titleが長い場合もあるので短く切ってからのほうが良いかも
(注) タイトルに数字が入っている場合うまくparams[:id]が取れないこともあるみたいです

気づいたSEOやってるサービス

結論:cheapなのでやめました

一昨日昼くらいから、昨日の昼くらいまで使っていたのですが、結局cheap SEOはとりやめました。理由としては、

  • RSS中のURLがすべて新しくなるため、読者の人に良くない(瀧内さん指摘)
  • 運営し始めてある程度時間経過しているので、URLが変わるページが多く、逆にSEO的にやさしくない → 異なるURLに対して同じ内容のページが二つ存在するとスパムとみなされることがある
  • URLが長くなるのはSEOにはやさしいが、人間にはやさしくない

というわけで、サービス運営初期時でもcheap SEOは効果的ですが、すでに運営を開始して時間が経っているサービスには良くないですという結論です。
RSSを購読下さっている読者の皆様、ご迷惑をおかけしました...

posted by Png satoko on Thu 19 Jun 2008 at 06:01
posted by Png satoko on Tue 10 Jun 2008 at 06:12

今までtraceでデバッグしてきましたが、一度は使ってみようと思い使ってみました。便利ではありませんが、処理の流れを確かめたいというときはよいと思います。

デバッグの準備:デバッグ用AIRの準備

1つ目のコマンドプロンプト開き、デバッグ用flashを生成します。

   1  C:\test_app>amxmlc -debug=true app.mxml

デバッグの準備:fdbコマンドラインデバッガ

2つ目のコマンドプロンプト開きます

   1  C:\flex_sdk_3\bin>fdb
   2  (fdb) run
   3  Player が接続するのを待っています

デバッガーの開始

1つ目のプロンプトで、AIRアプリを実行します

   1  C:\test_app>adl app.xml

2つ目のプロンプトでAIRアプリが接続した旨が表示されます

   1  (fdb) run
   2  Player が接続するのを待っています
   3  Player が接続されました。セッションを開始しています。
   4  [SWF] app.swf - 1,177,344 バイト (解凍後)

ブレークポイントを設定する

ファイル:app.mxmlの62行目に追加する場合

   1  (fdb) b app.mxml:62 
   2  (fdb) continue
   3  SWF ファイルまたはフレームから追加の ActionScript コードがロードされました。
   4  現在ロードされているすべてのファイルを表示するには、「info files」と入力してくだ
   5  さい。
   6  ブレークポイント 7 が app.mxml:62 の onAppComplete() に解決されました

ブレークポイントの確認

   1  (fdb) info breakpoints
   2  Num Type           Disp Enb Address    What
   3  7   breakpoint     keep y   0x00000000 の場所にある onAppComplete() 内 app.mxml:62

ブレークポイントの削除

continueを発行してブレークポイントが設定できなかった場合など、下記のように削除します

   1  (fdb) delete 2
   2  (fdb) delte 3 6
   3  (fdb) continue

スタックトレースの表示

ブレークポイントで停止した際に下記のコマンドでスタックトレースが表示されます

   1  (fdb) bt
   2  #0   this = [Object 35225761, class='memoApp'].app/onAppComplete(e=[Object 3
   3  7504001, class='mx.events::AIREvent']) 場所 :  app.mxml:62
   4  #1   EventDispatcher/dispatchEventFunction() 場所 :  app.mxml:0
   5  #2   this = [Object 35225761, class='memoApp'].EventDispatcher/dispatchEvent(_ar
   6  g1=[Object 37504001, class='mx.events::AIREvent']) 場所 :  app.mxml:0
   7  #3   this = [Object 35225761, class='memoApp'].UIComponent/dispatchEvent(event=[
   8  Object 37504001, class='mx.events::AIREvent']) 場所 :  UIComponent.as:9051
   9  #4   this = [Object 35225761, class='memoApp'].WindowedApplication/enterFrameHan
  10  dler(e=[Object 37504289, class='flash.events::Event']) 場所 :  WindowedApplicati
  11  on.as:2522

Refs

http://livedocs.adobe.com/flex/3_jp/html/help.html?content=CommandLineTools_4.html
http://livedocs.adobe.com/flex/3_jp/html/help.html?content=debugging_03.html#240390
http://livedocs.adobe.com/flex/3_jp/html/help.html?content=debugging_02.html#240284
http://www.adamrocker.com/blog/151/actionscript30_flex_debugger_fdb.html

posted by Png satoko on Mon 2 Jun 2008 at 11:50

瀧内さんの記事を参考にgit-svn使い始めましたが便利です。svnだと1コミットに複数の修正(バグ修正、機能追加、type修正など)をつい入れてしまうのですが、gitだとそういうこともなくなります。なのでcommitメッセージが書きやすい。

Rails向けgit環境設定

   1  $git svn clone svn-repo-URL
   2  $git add log
   3  $git add tmp
   4  $touch tmp/.gitignore log/.gitignore .gitignore

Rails_ROOT直下の.gitignore:最後の2行はemacs用
(tmpやlogの下の.gitignoreは空ファイルでOKです)

   1  # .gitignore
   2  log/*.log
   3  tmp/**/*
   4  *~
   5  #*#

git stash:へそくり

何かの修正をすでに加えている最中に、typoや緊急の修正分だけをコミットしたくなったとき。 (修正として新たに追加したファイルはstashしてもgit-status中に出てきますが、dcommitは可能です)

   1  $git stash save
   2  edit edit
   3  $git commit -a -m "fixed typo"
   4  $git svn dcommit
   5  $git stash apply

svn revert:ファイル一個だけ編集前のものに戻す

   1  $git checkout -- filename

その外よく使うコマンド

   1  $git diff
   2  $git diff filename
   3  $git add filename
   4  $git add .
   5  $git status
   6  $git rm -f filename

Refs

http://blog.s21g.com/articles/583
http://coderepos.org/share/wiki/FAQ/Git
http://railscasts.com/episodes/96:railscasts Git on Rails

posted by Png satoko on Wed 28 May 2008 at 06:37 with 1 comment

http://blog.dreamhost.com/2008/05/13/passenger-for-ruby-on-rails/

話題になっていたPassengerですが、Dreamhostで採用されました。masuidriveさんもオススメのようなので、ぜひ使ったみたいです。

http://rails20.jp/2008/04/passenger/
http://www.moongift.jp/2008/04/passenger/
http://blog.masuidrive.jp/index.php/2008/04/12/deploy_rb_and_apache_conf_generator_for_mod_rail/

posted by Png satoko on Thu 15 May 2008 at 05:24
Contents
caches_actionで携帯で画像が表示されない
caches_actionの動作についてメモ:action_controller/caching.rbを読む
gitのRepoが壊れた
TwitterがOpenFire(Javaで書かれたJabber Server)を採用
合宿やhackathon、勉強会で便利なツール群:なんとかjour
s21gブログに「cheap SEO」をやってみた
RailsのTipsコンテストがrailscastsで開催されていた
Adobe AIRでfdbコマンドラインデバッガを利用する
git-svn+Railsで使うgitコマンド
ホスティングサービスDreamhostがPassenger(mod_rails)を採用
Comments
KingofSmack: Here also good reads for this mobile applicatio... '14-5
satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよっ... '10-12
ujihisa: :%s/blog/glob/g '10-7
satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 ... '09-10
しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫... '09-10
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ