<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>Aerialarts</title>
	<atom:link href="http://aerial.st/feed/" rel="self" type="application/rss+xml" />
	<link>http://aerial.st</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 01:27:51 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/feed/" />
		<item>
		<title>MySQL 5.5でのスローログ</title>
		<link>http://aerial.st/archive/2012/02/16/mysql-5-5-slow-log/</link>
		<comments>http://aerial.st/archive/2012/02/16/mysql-5-5-slow-log/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 02:51:16 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1211</guid>
		<description><![CDATA[Homebrewで入れたMySQL 5.5.10のスローログの設定。 $ sudo vim /etc/my.cnf [mysqld] （いろいろ） slow_query_log=1 long_query_time=0.02 slow_query_log_file=slow.log $ mysql.server restart $ tail -f /usr/local/var/mysql/slow.log]]></description>
		<wfw:commentRss>http://aerial.st/archive/2012/02/16/mysql-5-5-slow-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2012/02/16/mysql-5-5-slow-log/" />
	</item>
		<item>
		<title>Rack::Profilerを使う</title>
		<link>http://aerial.st/archive/2012/01/16/rack-profiler/</link>
		<comments>http://aerial.st/archive/2012/01/16/rack-profiler/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 09:55:06 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1207</guid>
		<description><![CDATA[Rack::Profilerを使うのに少し躓いたのでメモ。 Gemfile: gem "ruby-prof" gem "rack-contrib", :require =&#62; "rack/contrib" app.rbのconfigureブロックあたり: require "rack/contrib/profiler" Rack::RubyProf = RubyProf use Rack::Profiler Rack::RubyProf = RubyProfをしているのはエラーが出るから。 アクセスする際にURL末尾に ?profile=process_time を付けるとプロファイル結果がダウンロードできる。 あとはKCacheGrindとかQCacheGrindで解析する、らしい。 （qtのビルドで時間がかかってるのでまだできていない…） 参考 [/ruby]/ruby Railsアプリケーションをプロファイリングしよう]]></description>
		<wfw:commentRss>http://aerial.st/archive/2012/01/16/rack-profiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2012/01/16/rack-profiler/" />
	</item>
		<item>
		<title>Node.js（V8）は4バイトのUTF-8に未対応</title>
		<link>http://aerial.st/archive/2012/01/02/node-utf8-8bytes/</link>
		<comments>http://aerial.st/archive/2012/01/02/node-utf8-8bytes/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 09:17:50 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1204</guid>
		<description><![CDATA[現状、Node.js（V8）は4バイトのUTF-8に対応していない。 $ node &#62; code = 0x1F614 128532 &#62; char = String.fromCharCode(code) '' &#62; char.charCodeAt(0).toString(16) 'f614' 先頭の1が削られてしまっている。 ちなみにV8コミッタの@koichikさんから直接リプライをもらった。]]></description>
		<wfw:commentRss>http://aerial.st/archive/2012/01/02/node-utf8-8bytes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2012/01/02/node-utf8-8bytes/" />
	</item>
		<item>
		<title>RestClientの返り値はStringとちょっと違う</title>
		<link>http://aerial.st/archive/2011/12/27/rest-client-response-is-not-string/</link>
		<comments>http://aerial.st/archive/2011/12/27/rest-client-response-is-not-string/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 02:43:37 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1201</guid>
		<description><![CDATA[インターフェースが簡潔で使いやすいRestClientだけれども、各種HTTPメソッドの返り値をto_iするとステータスコードを返すみたいだ。 たとえば次のようなSinatraアプリが起動していたとする。 get '/' do "1" end このgetルーティングに対してRestClientでアクセスすると、次のような結果が得られる。 require "rest_client" res = RestClient.get("http://localhost:9292/") #=&#62; "1" # Stringなのにto_iはステータスコード200を返す res.class #=&#62; String res.to_i #=&#62; 200 # to_strしても変わらない str = res.to_str #=&#62; "1" str.to_i #=&#62; 200 res.class #=&#62; String # 期待される値はと言うと "1".to_i #=&#62; 1 内部でどうやっているかまでは確認できていないけど、 このようにRestClientの返り値のto_iはステータスコードを返す。 で、具体的にどんなときに不具合があるかというと、 Web APIからRestClientを使って取得した値をActiveRecord::Base.findに渡す 内部的にto_iしているのか、毎回id=200を探しに行く json gemによるエスケープ処理JSON.generate([val])が無限ループしてしまう ではどうやっていつものStringとして扱うのかというと、Stringで包みなおせばいい。 res = RestClient("http://localhost:9292") str = String.new(res) str.to_i #=&#62; 1 str.class #=&#62; String なんでこんな変な仕様になってるんだろう。 せめて返り値には別のクラスを使用して欲しかった。 そんな感じで、RestClientは変なところではまるので要注意。]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/12/27/rest-client-response-is-not-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/12/27/rest-client-response-is-not-string/" />
	</item>
		<item>
		<title>LionでPostfix+Gmail</title>
		<link>http://aerial.st/archive/2011/12/08/postfix-via-gmail-on-lion/</link>
		<comments>http://aerial.st/archive/2011/12/08/postfix-via-gmail-on-lion/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 02:49:58 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1194</guid>
		<description><![CDATA[OSX LionにはPostfixがインストールされているんだけど、これを使ってgmail経由で送信する際に一筋縄では行かなかったのでメモ。 まず /etc/postfix/main.cf に以下を追記して、gmailの587番ポートに接続するよう設定する。 relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_tls_security_options = noanonymous smtp_sasl_mechanism_filter = plain smtp_tls_security_level = secure smtp_tls_CApath = /etc/postfix/certs 次に /etc/postfix/sasl_passwd にgmailアカウントの情報を記述する（YOUR.ACCOUNTとYOUR_PASSWORD部分は自分のものに書き換える）。 [smtp.gmail.com]:587 YOUR.ACCOUNT@gmail.com:YOUR_PASSWORD そしてpostmapでデータベースを作成し、元のファイルは削除する。 # postmap /etc/postfix/sasl_passwd # rm /etc/postfix/sasl_passwd 次に、GmailのSSL証明書を取得する。下記がコマンドの出力結果（＋注釈）だけど、 注釈の通り証明書の鍵部分を /etc/postfix/certs/gmail.pem と /etc/postfix/certs/equifax.pem に保存する。 $ openssl s_client -connect pop.gmail.com:995 -showcerts CONNECTED(00000003) depth=1 /C=US/O=Google Inc/CN=Google Internet Authority verify error:num=20:unable to get local issuer certificate verify return:0 --- Certificate chain 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com i:/C=US/O=Google Inc/CN=Google Internet Authority ### [...]]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/12/08/postfix-via-gmail-on-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/12/08/postfix-via-gmail-on-lion/" />
	</item>
		<item>
		<title>git reset直前のコミットはORIG_HEADに保存されてる</title>
		<link>http://aerial.st/archive/2011/12/07/git-show-orig-head/</link>
		<comments>http://aerial.st/archive/2011/12/07/git-show-orig-head/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 13:34:14 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1191</guid>
		<description><![CDATA[間違えてgit reset（&#8211;soft/&#8211;hard問わず）してしまった場合とか、取り消すのはいいんだけどコミットログは見たいとか思ったら、 git show ORIG_HEAD すれば良い。 ORIG_HEADはgit resetする直前のHEADの状態を指しているので、git diffで差分を見るといったこともできる。 git diff ORIG_HEAD 参考 「Gitを使いこなすための20のコマンド」のgit resetの項]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/12/07/git-show-orig-head/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/12/07/git-show-orig-head/" />
	</item>
		<item>
		<title>ActiveRecord3.1/mysql2でTRUNCATE</title>
		<link>http://aerial.st/archive/2011/12/07/activerecord31-mysql2-truncate/</link>
		<comments>http://aerial.st/archive/2011/12/07/activerecord31-mysql2-truncate/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 23:32:04 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[ActiveRecord]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1188</guid>
		<description><![CDATA[DatabaseCleanerを使うと 複数データベース（各種RDBMSやMongoDB、CouchDBなどなど）に対応した方法でデータを削除できるんだけど、複数のDBにコネクションをはっている場合にはうまく動いてくれないことがあるらしい。 でも自分の場合、mysql2でうまく動いてくれればそれでいいし、わざわざDatabaseCleanerを使う必要はないよなぁ…。ということで、ActiveRecord::ConnectionAdapters::Mysql2AdapterにTRUNCATEを発行してくれるメソッドを生やしてみた。実質DatabaseCleanerのコピペ。 module ActiveRecord module ConnectionAdapters class Mysql2Adapter &#60; AbstractAdapter def truncate_tables tables_to_truncate.each do &#124;table_name&#124; truncate_table(table_name) end end def truncate_table(table_name) execute("TRUNCATE TABLE #{quote_table_name(table_name)};") end private def tables_to_truncate tables - views - ["schema_migrations"] end def views @views &#124;&#124;= select_values("select table_name from information_schema.views where table_schema = '#{current_database}'") rescue [] end end end end 次のようにtruncate_tablesを呼ぶと、ビューとschema_migrations以外に対してTRUNCATEを発行してくれる。 ActiveRecord::Base.connection.truncate_tables]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/12/07/activerecord31-mysql2-truncate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/12/07/activerecord31-mysql2-truncate/" />
	</item>
		<item>
		<title>ActiveRecord3.1/MySQLでBIGINT UNSIGNEDなid</title>
		<link>http://aerial.st/archive/2011/12/06/activerecird31-mysql2-unsigned-bigint-pk/</link>
		<comments>http://aerial.st/archive/2011/12/06/activerecird31-mysql2-unsigned-bigint-pk/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 02:44:36 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1184</guid>
		<description><![CDATA[ActiveRecord 3.1でMySQL2アダプタを使っている場合に、idカラム（プライマリキーのカラム）にBIGINT UNSIGNEDを使う方法。 まずCREATE TABLE時のidカラムの型を変更するために、ActiveRecordが読み込まれた直後、rakeタスク等でテーブルの作成が行われる前に次のように上書きする。 ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = \ "BIGINT UNSIGNED DEFAULT NULL auto_increment PRIMARY KEY" あとは各マイグレーションファイルで、外部キー（*_idってやつ）のカラムの型にBIGINT UNSIGNEDを指定する。 t.column :user_id, "BIGINT UNSIGNED" これでidカラムも*_idカラムもBIGINT UNSIGNEDで作られる。 もし既存のテーブルの型を書き換えたい場合には、 change_column :users, :id, "BIGINT UNSIGNED" でいけると思う（未確認）。 ただ、BIGINT UNSIGNEDだと0から1846京まで使えるらしいので、DB単体では破綻するような気がする。 参考 How to use long id in Rails applications? &#8211; stackoverflow]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/12/06/activerecird31-mysql2-unsigned-bigint-pk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/12/06/activerecird31-mysql2-unsigned-bigint-pk/" />
	</item>
		<item>
		<title>Object#presenceが便利</title>
		<link>http://aerial.st/archive/2011/11/16/object-presence/</link>
		<comments>http://aerial.st/archive/2011/11/16/object-presence/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 09:18:02 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[activesupport]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1181</guid>
		<description><![CDATA[ActiveSupport 2.3で導入されたObject#presenceが便利。 たとえば、 time = options[:timestamp].presence &#124;&#124; Time.now で初期値の代入に使えるし、 time = options[:timestamp].presence &#038;&#038; Time.at(options[:timestamp]) で値がある場合に限って加工に使える。 組み合わせれば、 time = (options[:timestamp].presence &#038;&#038; Time.at(options[:timestamp])) &#124;&#124; Time.now で値があれば加工して、なければ初期値を代入することができる。 でもこれはさすがにわかりづらいので、三項演算子を使って time = options[:timestamp].present? ? Time.at(options[:timestamp]) : Time.now としたほうがカッコが減ってわかりやすい。 ActiveSupportがないと生きていけないゆとりになってしまった…。]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/11/16/object-presence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/11/16/object-presence/" />
	</item>
		<item>
		<title>sinatraでbefore :onlyみたいなこと</title>
		<link>http://aerial.st/archive/2011/10/30/sinatra-before-only-filter/</link>
		<comments>http://aerial.st/archive/2011/10/30/sinatra-before-only-filter/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 17:42:44 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=1175</guid>
		<description><![CDATA[SinatraのbeforeフィルタだとRailsみたいに:onlyや:exceptで適用するルーティングを指定できない。 ただそれだとbeforeフィルタのなかでガリガリとifで分岐する必要があるのでそれもちょっと微妙。 で、A Sinatra Before Only Filterにbefore :onlyについて処理するプラグイン（？）を書いている人がいたので、ちょっと真似してみた。 module Sinatra module BeforeOnlyFilter def before_only(*routes, &#38;block) before do routes_regex = routes.map do &#124;route&#124; route.is_a?(Regexp) ? route : /^#{route.gsub(/\*/, '[^/]*')}$/ end instance_eval(&#38;block) if routes_regex.any? {&#124;regex&#124; (request.path =~ regex) != nil} end end end register Sinatra::BeforeOnlyFilter end 使うときはこんな感じ require 'sinatra/before_only_filter' before_only %r{/users/.+} do # /users/aaa とか # /users/aaa/bbb とか # /users/aaa.ccc とか end before_only "/users/*" do # /users/aaa はマッチするけど # /users/aaa/bbb や # /users/aaa.ccc はマッチしない end でも、ちょっと不便なところが。 HTTPメソッドでの区別ができない URLからパラメータを取り出すには自分でパースする必要がある というか、sinatraのソースを見るとそもそもbeforeメソッドの引数でパスが指定できる…？ def before(path = [...]]]></description>
		<wfw:commentRss>http://aerial.st/archive/2011/10/30/sinatra-before-only-filter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2011/10/30/sinatra-before-only-filter/" />
	</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/


Served from: aerial.st @ 2012-05-19 21:39:27 -->
