<?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/"
	>

<channel>
	<title>cocoa*life &#187; Programming</title>
	<atom:link href="http://www.cocoalife.net/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cocoalife.net</link>
	<description>Whether we can achieve something entirely depends upon our intensity of faith.</description>
	<lastBuildDate>Sun, 22 May 2011 10:42:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to use Xcode 3 color themes in Xcode 4</title>
		<link>http://www.cocoalife.net/2011/03/post_872.html</link>
		<comments>http://www.cocoalife.net/2011/03/post_872.html#comments</comments>
		<pubDate>Wed, 30 Mar 2011 11:55:55 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=872</guid>
		<description><![CDATA[I&#8217;m using either MyBlackboard (In Japanese) or Railscasts color themes in Xcode 3, these color themes, however, couldn&#8217;t be used in Xcode 4. I want to convert 3&#8242;s xccolortheme files into 4&#8242;s dvtcolortheme files, and found the just script which converted it. mrevilme&#8217;s gist: 488120 — Gist The usage of this tiny python script is [...]]]></description>
			<content:encoded><![CDATA[				<p>I&#8217;m using either <a target="_blank" href="http://d.hatena.ne.jp/griffin-stewie/20090519/p1">MyBlackboard (In Japanese)</a> or <a target="_blank" href="http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/">Railscasts</a> color themes in Xcode 3, these color themes, however, couldn&#8217;t be used in Xcode 4.</p>
				<p>I want to convert 3&#8242;s xccolortheme files into 4&#8242;s dvtcolortheme files, and found the just script which converted it.<br />
				<a target="_blank" href="https://gist.github.com/488120">mrevilme&#8217;s gist: 488120 — Gist</a></p>
				<p>The usage of this tiny python script is very simple like the following command.</p>
				<pre class="brush: bash; title: ; notranslate">$ xcode3_theme_to_xcode4.py MyBlackBoard.xcolortheme</pre>
<p>This step is very quick, and finally, I moved the dvtcolortheme file to the directory.</p>
<pre class="brush: bash; title: ; notranslate">mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes/
mv MyBlackBoard.dvtcolortheme ~/Library/Developer/Xcode/UserData/FontAndColorThemes/</pre>
				<p>If you&#8217;ve already started Xcode, restart it and you&#8217;ll find the theme at the preference of Xcode.</p>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://d.hatena.ne.jp/griffin-stewie/20090519/p1">Xcodeのテーマ（Color Theme） &#8211; griffin-stewieの日記</a></li>
				<li><a target="_blank" href="http://blog.codefront.net/2010/02/04/railscasts-xcode-theme/">Railscasts Xcode theme &#8211; redemption in a blog</a></li>
				<li><a target="_blank" href="https://gist.github.com/488120">mrevilme&#8217;s gist: 488120 — Gist</a></li>
				<li><a target="_blank" href="https://gist.github.com/524860">mrevilme&#8217;s gist: 524860 — Gist</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/03/post_872.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create OAuth / xAuth Service Provider in Ruby on Rails with devise</title>
		<link>http://www.cocoalife.net/2011/02/post_866.html</link>
		<comments>http://www.cocoalife.net/2011/02/post_866.html#comments</comments>
		<pubDate>Fri, 04 Feb 2011 03:56:35 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=866</guid>
		<description><![CDATA[At previous entiry I wrote a sample how to support xAuth in Ruby Application. In this entry, I write how to create the OAuth/xAuth Service Provider in Ruby on Rails project which uses devise plugin for authentication. OAuth support when you use devise plugin Installation First of all, I&#8217;m about to write the way of [...]]]></description>
			<content:encoded><![CDATA[				<p>At previous entiry I wrote a sample how to support xAuth in Ruby Application.</p>
				<p>In this entry, I write how to create the OAuth/xAuth Service Provider in Ruby on Rails project which uses devise plugin for authentication.</p>
				<h2>OAuth support when you use devise plugin</h2>
				<h3>Installation</h3>
				<p>First of all, I&#8217;m about to write the way of supporting OAuth using OAuth plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></p>
				<p>OAuth plugin supports Rails 3 after version 0.4.0.pre1, and add Gemfile the following line.</p>
				<pre class="brush: ruby; title: ; notranslate">gem &quot;oauth-plugin&quot;, &quot;&gt;=0.4.0.pre1&quot;</pre>
<p>The installation tutorials are written in the github plugin page.</p>
<h3>devise plugin support</h3>
<p>In addition, to use OAuth plugin in the project which utilize devise, you need to support two methods &#8220;login_required&#8221; and &#8220;logged_in?&#8221; Devise uses such helper methods as &#8220;authenticate_#{model_name}&#8221; and &#8220;#{model_name}_signed_in?&#8221;, I wrote two helper methods.</p>
<p>[lib/lindoc/oauth_helpers.rb]</p>
<pre class="brush: ruby; title: ; notranslate">module Lindoc
  module OauthHelpers
    def self.included(recipient)
      recipient.extend(ClassMethods)
      recipient.class_eval do
        include InstanceMethods
      end
    end

    module InstanceMethods
      def login_required
        authenticate_user!
      end

      def logged_in?
        user_signed_in?
      end
    end
  end
end</pre>
				<p>At the controllers associated with OAuth, add this helper methods like the this.</p>
				<p>[$RAILS_ROOT/app/oauth_clients_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class OauthClientsController &lt; ApplicationController
  include Lindoc::OauthHelpers
  ...
end</pre>
				<p>[$RAILS_ROOT/app/oauth_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth/controllers/provider_controller'

class OauthController &lt; ApplicationController
  include OAuth::Controllers::ProviderController
  include Lindoc::OauthHelpers
  ...
end</pre>
				<p>Since I want to use OAuth / xAuth authentication at API of our service, also added :oauth_required filter.</p>
				<p>[app/controllers/api/v1/api_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class Api::V1::ApiController &lt; ApplicationController
  include Lindoc::OauthHelpers

  before_filter :oauth_required
  ...
end</pre>
				<h3>Rails nested parameters support</h3>
				<p>Client applications often post data in nested parameters like &#8220;foo[bar]=baz&#8221; to Rails application, but OAuth plugin doesn&#8217;t currently support this type of parameters. The reason why OAuth plugin doesn&#8217;t, is that this plugin doesn&#8217;t consider this type when it calculates a signature the way of which is written in the specification of OAuth, and answers a bad/invalid signature. So, you need to add support by overriding the method which helps calculate it.</p>
				<p>This solution is written at Issue page of OAuth plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth/issues#issue/8">parameter normalisation issues Nesting parameters causes problems.</a></p>
				<p>[config/initializers/oauth.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Helper
    # see https://github.com/pelle/oauth/issues#issue/8
    def normalize(params)
      params.sort.map do |k, values|
        if values.is_a?(Array)
          # multiple values were provided for a single key
          values.sort.collect do |v|
            [escape(k),escape(v)] * &quot;=&quot;
          end
        elsif values.is_a?(Hash)
          key = k
          values.sort.collect do |k, v|
            [escape(&quot;#{key}[#{k}]&quot;),escape(v)] * &quot;=&quot;
          end
        else
          [escape(k),escape(values)] * &quot;=&quot;
        end
      end * &quot;&amp;&quot;
    end
  end
end]</pre>
				<h2>xAuth support</h2>
				<p>xAuth is the authentication method which is used in twitter to support desktop/mobile applications. If you want to know how to use xAuth in your applications, you should read <a target="_blank" href="http://dev.twitter.com/pages/xauth">this document</a>.<br />
				<a target="_blank" href="http://dev.twitter.com/pages/xauth">Using xAuth | dev.twitter.com</a></p>
				<h3>client application restriction</h3>
				<p>Like twitter, I want to restrict client applications which can use xAuth authentication, and I add column to decide it.</p>
				<p>[db/migrate/xxx_create_oauth_table.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">class CreateOauthTables &lt; ActiveRecord::Migration
  def self.up
    create_table :client_applications do |t|
      ...
      t.boolean :xauth_enabled, :default =&gt; false

      t.timestamps
    end
    ...
  end
end</pre>
				<h3>/oauth/access_token signature verification method change</h3>
				<p>In OAuth 1.0 specification, service provider must verify a signature which consists of both Authentication header and GET or POST parameters called &#8220;Signature Base String&#8221;, and signed by both Consumer Secret and Access Token Secret. This verification step is implemented as filter &#8220;two_legged&#8221; or &#8220;oauth10_request_token&#8221; in OAuth plugin, OAuth::Controllers::ProviderController.</p>
				<p>[oauth-plugin/lib/oauth/controllers/provider_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Controllers

    module ProviderController
      def self.included(controller)
        controller.class_eval do
          ...
          oauthenticate :strategies =&gt; :two_legged, :interactive =&gt; false, :only =&gt; [:request_token]
          oauthenticate :strategies =&gt; :oauth10_request_token, :interactive =&gt; false, :only =&gt; [:access_token]
          ...
</pre>
				<p>The simplified difference of these two methods is to use or not to use request token. You need to change signature verification method of /oauth/access_token when you request Access Token by xAuth, because unlike OAuth clients, xAuth clients don&#8217;t have request token.</p>
				<p>For that reason, to support xAuth, if request has &#8220;x_auth_mode=client_auth&#8221; in POST parametes which indicate client applications want to authenticate by xAuth, &#8220;two_legged&#8221; filter should be applied. I used &#8220;alias_method_chain&#8221; to seperate xAuth and OAuth authentication.</p>
				<p>[config/initializers/oauth.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">module OAuth
  module Controllers
    module ApplicationControllerMethods
      class Authenticator
        def oauth10_request_token_with_xauth
          if params[:x_auth_mode] == 'client_auth'
            # xAuth authentication
            two_legged
          else
            # OAuth authentication
            oauth10_request_token_without_xauth
          end
        end

        alias_method_chain :oauth10_request_token, :xauth
      end
    end
  end
end</pre>
				<h3>/oauth/access_token user verification</h3>
				<p>In /oauth/access_token request, you also verify the user using his username and password. If there is a &#8220;x_auth_mode=client_auth&#8221; POST parameter in request, verify the user and response Access Token.</p>
				<p>[$RAILS_ROOT/app/oauth_controller.rb]</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth/controllers/provider_controller'

class OauthController &lt; ApplicationController
  include OAuth::Controllers::ProviderController
  include Lindoc::OauthHelpers
  ....

  private
  def access_token_with_xauth
    # To use custom failure response with devise, you need the following line.
    # see https://github.com/plataformatec/devise/wiki/How-To:-Provide-a-custom-failure-response-with-Warden
    warden.custom_failure!

    if params[:x_auth_mode] == 'client_auth'
      render_unauthorized = Proc.new do
        render :nothing =&gt; true, :status =&gt; 401
      end

      # We support screen name and email to login
      user = User.find_for_database_authentication({ :screen_name_or_email =&gt; params[:x_auth_username] })
      if user &amp;&amp;
        user.valid_password?(params[:x_auth_password]) &amp;&amp;
        current_client_application.xauth_enabled

        @token = AccessToken.where(:user_id.eq =&gt; user,
                                   :client_application_id.eq =&gt; current_client_application,
                                   :invalidated_at.eq =&gt; nil).limit(1).first
        @token = AccessToken.create(:user =&gt; user, :client_application =&gt; current_client_application) if @token.blank?

        if @token
          render :text =&gt; @token.to_query
        else
          render_unauthorized.call
        end
      else
        render_unauthorized.call
      end
    else
      access_token_without_xauth
    end
  end

  alias_method_chain :access_token, :xauth
end</pre>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://oauth.net/core/1.0/">OAuth Core 1.0</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/yuroyoro/20100506/1273137673">OAuthプロトコルの中身をざっくり解説してみるよ &#8211; ゆろよろ日記</a> (In Japanese)</li>
				<li><a target="_blank" href="https://github.com/oauth/oauth-ruby">oauth/oauth-ruby &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/pelle/oauth/issues#issue/8">parameter normalisation issues Nesting parameters causes problems.</a></li>
				<li><a target="_blank" href="https://github.com/igaiga/oauth_rails_sample">igaiga/oauth_rails_sample &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/plataformatec/devise/wiki/How-To:-Provide-a-custom-failure-response-with-Warden">How To: Provide a custom failure response with Warden &#8211; GitHub</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/02/post_866.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to support OAuth in ASIHTTPRequest</title>
		<link>http://www.cocoalife.net/2011/01/post_865.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_865.html#comments</comments>
		<pubDate>Mon, 24 Jan 2011 06:14:33 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=865</guid>
		<description><![CDATA[ASIHTTPRequest is a brilliant library, when you want to handle HTTP requests. At this time, however, this library doesn&#8217;t support OAuth. You can support it easily with OAuthCore library which is developed by atebits who is the developer of Tweetie a.k.a. Twitter for Mac/iPhone. atebits / OAuthCore / overview – Bitbucket A sample code is [...]]]></description>
			<content:encoded><![CDATA[				<p>ASIHTTPRequest is a brilliant library, when you want to handle HTTP requests.<br />
				At this time, however, this library doesn&#8217;t support OAuth.</p>
				<p>You can support it easily with OAuthCore library which is developed by atebits who is the developer of Tweetie a.k.a. Twitter for Mac/iPhone.<br />
				<a target="_blank" href="https://bitbucket.org/atebits/oauthcore">atebits / OAuthCore / overview – Bitbucket</a></p>
				<p>A sample code is following.</p>
				<pre class="brush: objc; title: ; notranslate">#import &quot;OAuthCore.h&quot;

NSString * const CONSUMER_KEY = @&quot;YOUR_CONSUMER_KEY&quot;;
NSString * const CONSUMER_SECRET = @&quot;YOUR_CONSUMER_SECRET&quot;;
NSString * const ACCESS_TOKEN = @&quot;YOUR_ACCESS_TOKEN&quot;;
NSString * const ACCESS_TOKEN_SECRET = @&quot;YOUR_ACCESS_TOKEN_SECRET&quot;;

NSURL *URL = [NSURL URLWithString:@&quot;http://example.com/api&quot;];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:URL];

[request setPostValue:@&quot;test&quot; forKey:@&quot;test_value&quot;];
[request buildPostBody];

NSString *header = OAuthorizationHeader([request url],
                                        [request requestMethod],
                                        [request postBody],
                                        CONSUMER_KEY,
                                        CONSUMER_SECRET,
                                        ACCESS_TOKEN,
                                        ACCESS_TOKEN_SECRET);

[request addRequestHeader:@&quot;Authorization&quot; value:header];</pre>
				<p>If you want to get &#8220;Access Token&#8221; and &#8220;Access Toke Secret&#8221;, such as you authorize with xAuth, you should set both ACCESS_TOKEN and ACCESS_TOKEN_SECRET, not nil but @&#8221;".</p>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://groups.google.com/group/asihttprequest/browse_thread/thread/57e8d27717a44671">Oauth signing &#8211; ASIHTTPRequest | Google グループ</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/sugyan/20100819/1282156751">Objective-C向けOAuthライブラリ&#8221;OAuthCore&#8221;を使ってTwitter APIを叩いてみる &#8211; すぎゃーんメモ</a> (In Japanese)</li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_865.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xAuth Consumer Sample using Ruby</title>
		<link>http://www.cocoalife.net/2011/01/post_864.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_864.html#comments</comments>
		<pubDate>Fri, 21 Jan 2011 03:57:09 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=864</guid>
		<description><![CDATA[I&#8217;m developing OAuth/xAuth Service Provider using OAuth / OAuth-Plugin. pelle/oauth-plugin &#8211; GitHub Since OAuth-Plugin doesn&#8217;t support xAuth, I decided to create a program to support it. I&#8217;ll write an entry about xAuth support, before that, I write this entry about sample of using xAuth in Ruby. You need to install Ruby OAuth Gem. References POST [...]]]></description>
			<content:encoded><![CDATA[				<p>I&#8217;m developing OAuth/xAuth Service Provider using OAuth / OAuth-Plugin.<br />
				<a target="_blank" href="https://github.com/pelle/oauth-plugin">pelle/oauth-plugin &#8211; GitHub</a></p>
				<p>Since OAuth-Plugin doesn&#8217;t support xAuth, I decided to create a program to support it.<br />
				I&#8217;ll write an entry about xAuth support, before that, I write this entry about sample of using xAuth in Ruby.</p>
				<p>You need to install Ruby OAuth Gem.</p>
				<pre class="brush: ruby; title: ; notranslate">require 'oauth'

CONSUMER_KEY = 'Your-Consumer-Key'
CONSUMER_SECRET = 'Your-Consumer-Secret'

def get_access_token
  consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site =&gt; 'Your-OAUTH-Provider-URL')
  access_token = consumer.get_access_token(nil, {}, { :x_auth_mode =&gt; 'client_auth', :x_auth_username =&gt; 'Your-User-Name', :x_auth_password =&gt; 'Your-Password' })

  [access_token.token, access_token.secret]
end

def access_api(token, secret)
  consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site =&gt; 'Your-OAuth-Provider-URL')
  access_token = OAuth::AccessToken.new(consumer, token, secret)

  access_token.get('Your-API-URL')
end

token, secret = get_access_token
p &quot;token: #{token}&quot;
p &quot;secret: #{secret}&quot;

response = access_api(token, secret)
p response</pre>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://dev.twitter.com/doc/post/oauth/access_token">POST oauth/access_token | dev.twitter.com</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/lyokato/20100212/1265961914">OAuthでデスクトップアプリがブラウザを経由させたくないときのxAuth &#8211; Codin’ In The Free World</a> (In Japanese)</li>
				<li><a target="_blank" href="http://blog.livedoor.jp/maraigue/archives/1109122.html">Maraigue風。:[Ruby][Twitter] OAuthのアクセストークンを、ブラウザなしで、Twitterのユーザ名およびパスワードのみを用いて取得する(通称：xAuth)ためのRubyのコード</a> (In Japanese)</li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_864.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find Skype Chat ID with rb-skypemac</title>
		<link>http://www.cocoalife.net/2011/01/post_863.html</link>
		<comments>http://www.cocoalife.net/2011/01/post_863.html#comments</comments>
		<pubDate>Mon, 10 Jan 2011 11:44:28 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=863</guid>
		<description><![CDATA[Each Skype chat has an unique chat ID like &#8220;#hogehoge/XXXXXXXXXXXXXXXX&#8221;. This ID has very important role when you handle Skype with another programs/scripts like rb-skypemac (Ruby Gem). rb skypemac There is a very simple method to find IDs with rb-skypemac. After this command, you should select the appropriate ID.]]></description>
			<content:encoded><![CDATA[				<p>Each Skype chat has an unique chat ID like &#8220;#hogehoge/XXXXXXXXXXXXXXXX&#8221;.<br />
				This ID has very important role when you handle Skype with another programs/scripts like <a target="_blank" href="http://rb-skypemac.rubyforge.org/">rb-skypemac (Ruby Gem)</a>.<br />
				<a target="_blank" href="http://rb-skypemac.rubyforge.org/">rb skypemac</a></p>
				<p>There is a very simple method to find IDs with rb-skypemac.</p>
				<pre class="brush: ruby; title: ; notranslate">irb &gt; require 'rb-skypemac'
 =&gt; true
irb &gt; SkypeMac::Skype.send_(:command =&gt; 'SEARCH RECENTCHATS')
 =&gt; &quot;CHATS #hogehoge/XXXXXXXXXXXXXXXX, #piyopiyo/XXXXXXXXXXXXXXXX&quot;</pre>
				<p>After this command, you should select the appropriate ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2011/01/post_863.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Chef Server with RVM</title>
		<link>http://www.cocoalife.net/2010/12/post_826.html</link>
		<comments>http://www.cocoalife.net/2010/12/post_826.html#comments</comments>
		<pubDate>Thu, 23 Dec 2010 12:46:36 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=826</guid>
		<description><![CDATA[Chef is a systems integration framework, built to bring the benefits of configuration management to your entire infrastructure. The tutorials of install, and basic usage are written here. I want to use it with RVM&#8217;s Ruby on Ubuntu Server 10.10. RVM Installation I use RVM with system wide install, whose instruction is here. RVM: Ruby [...]]]></description>
			<content:encoded><![CDATA[				<p>Chef is a systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.</p>
				<p>The tutorials of install, and basic usage are written <a target="_blank" href="http://wiki.opscode.com/display/chef/Home">here</a>.</p>
				<p>I want to use it with RVM&#8217;s Ruby on Ubuntu Server 10.10.</p>
				<h2>RVM Installation</h2>
				<p>I use RVM with system wide install, whose instruction is <a target="_blank" href="http://rvm.beginrescueend.com/deployment/system-wide/">here</a>.<br />
				<a target="_blank" href="http://rvm.beginrescueend.com/deployment/system-wide/">RVM: Ruby Version Manager &#8211; Installing RVM System Wide</a></p>
				<pre class="brush: bash; title: ; notranslate">chef-server# apt-get install curl git-core
chef-server# bash &lt; &lt;( curl -L http://bit.ly/rvm-install-system-wide )</pre>
				<h2>Ruby 1.9.2 Installation</h2>
				<p>After installed RVM, you need to install Ruby 1.9.2 with RVM.</p>
				<pre class="brush: bash; title: ; notranslate">chef-server# apt-get install build-essential libssl-dev zlib1g-dev libreadline-dev
chef-server# source '/usr/local/lib/rvm'
chef-server# rvm install 1.9.2 -C --with-readline-dir=/usr --with-openssl-dir=/usr --with-zlib-dir=/usr</pre>
				<h2>Bootstrap Chef-Server Installation</h2>
				<p>Now, you are prepared for installing Chef.<br />
				There is a nice tutorial for bootstrap installation of Chef-Server.<br />
				<a target="_blank" href="http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation">Bootstrap Chef RubyGems Installation &#8211; Chef &#8211; Opscode Open Source Wiki</a></p>
				<h3>Chef Solo Attributes Configuration</h3>
				<pre class="brush: bash; title: ; notranslate">chef-server$ vi ~/chef.json</pre>
<pre class="brush: jscript; title: ; notranslate">{
  &quot;chef&quot;: {
    &quot;server_url&quot;: &quot;http://localhost:4000&quot;
  },
  &quot;run_list&quot;: [ &quot;recipe[chef::bootstrap_server]&quot; ]
}</pre>
				<h3>Temporary PATH configuration</h3>
				<p>Before using Rubygems, you should set PATH configuration temporary, because I want to use chef to set all configurations.</p>
				<pre class="brush: bash; title: ; notranslate">chef-server# source '/usr/local/lib/rvm'
chef-server# rvm use 1.9.2
chef-server# gem install chef</pre>
				<h3>Other Necessary Packages Installation</h3>
				<pre class="brush: bash; title: ; notranslate">chef-server# apt-get install wget ssl-cert
chef-server# gem install chef</pre>
				<h3>Chef Solo Installation</h3>
				<pre class="brush: bash; title: ; notranslate">chef-server# mkdir -p /etc/chef
chef-server# vi /etc/chef/solo.rb</pre>
				<p>The content of &#8220;/etc/chef/solo.rb&#8221; is following.</p>
				<pre class="brush: plain; title: ; notranslate">file_cache_path &quot;/tmp/chef-solo&quot;
cookbook_path &quot;/tmp/chef-solo/cookbooks&quot;</pre>
				<p>You can use `chef-solo` command to install chef-server.</p>
				<pre class="brush: bash; title: ; notranslate">chef-server# chef-solo -c /etc/chef/solo.rb -j ~/chef.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz</pre>
<h3>chef-client, chef-server, chef-solr, chef-solr-indexer run script PATH configuration</h3>
<p>Having finished installing, you will notice that chef-* fail to start on looking at logs &#8220;/etc/sv/chef-*/logs/main/current&#8221;.<br />
The reason of this failure is that Ruby and Gems PATH are not set correctly, so you should set them like this.</p>
<pre class="brush: bash; title: ; notranslate">chef-server# vi /etc/sv/{chef-client, chef-server, chef-solr, chef-solr-indexer}/run</pre>
				<pre class="brush: diff; title: ; notranslate">- PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
---
+ export PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/rvm/gems/ruby-1.9.2-p0/bin
+ export GEM_HOME=/usr/local/rvm/gems/ruby-1.9.2-p0
+ export GEM_PATH=/usr/local/rvm/gems/ruby-1.9.2-p0</pre>
				<p>These chef processes are watched by &#8220;runit&#8221;, and after you rewrite them, all processes will start correctly.<br />
				If you want to start/stop/restart manually, use `/etc/init.d/chef-* {start/stop/restart}` command.</p>
				<p>要は、PATH の設定だけちゃんとやっておけば RVM でインストールした Ruby でも Chef はインストールできますよということです。</p>
				<h2>References</h2>
				<ul>
				<li><a target="_blank" href="http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation">Bootstrap Chef RubyGems Installation &#8211; Chef &#8211; Opscode Open Source Wiki</a></li>
				<li><a target="_blank" href="http://brass.to/blog/try-chef.html">Chefを試してみた &#8211; ひげろぐ</a> (Japanese)</li>
				<li><a href="http://brass.to/blog/1st-chef-solo.html" target="_blank">chef-soloで作業環境構築の自動化 &#8211; ひげろぐ</a> (Japanese)</li>
				<li><a target="_blank" href="http://blog.madoro.org/mn/81">Chefを最速で使いこなすためのいくつかのポイント &#8211; Masatomo Nakano Blog</a> (Japanese)</li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/POCHI_BLACK/searchdiary?word=%2A%5Bchef%5D">[chef] &#8211; pochiのメモ帳</a> (Japanese)</li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/12/post_826.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Steak で RESTful API の受け入れテストを書く</title>
		<link>http://www.cocoalife.net/2010/12/post_856.html</link>
		<comments>http://www.cocoalife.net/2010/12/post_856.html#comments</comments>
		<pubDate>Fri, 10 Dec 2010 07:43:43 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=856</guid>
		<description><![CDATA[Steak は Ruby 製の受け入れテストのためのフレームワークです。 cavalle/steak &#8211; GitHub Github にある説明を読んでいただくとわかると思いますが Steak ではテストは RSpec のように書くことができます。 同様のツールに Cucumber もありますが、Cucumber は英語や日本語で書かなければならないので、自分の中でどうもしっくりしませんでした。 そのため、自分にとっては Steak のようにかけた方がずっと書きやすいです。 ということで、これからは Steak を使って受け入れテストを書いていこうと思っています。 そんな Steak ですが、RESTful API のテストもしたいです。 どうも Steak の裏で動いている Capybara というテストフレームワークは、 visit &#8216;/&#8217; のように GET することはできるのですが、 POST PUT DELETE というような RESTful API をテストする上ではそれだけでは足りません。 以下のような方法で、POST 等のメソッドを呼び出すことが可能なようです。 $RAILS_ROOT/spec/acceptance/support/helper.rb $RAILS_ROOT/spec/acceptance/api/articles_spec.rb @driver.status_code とかでレスポンスのステータスコードが取得できたりします。 ほかの情報はここなどを読むとよいでしょう。 Class: Capybara::Driver::Base 参考文献 [...]]]></description>
			<content:encoded><![CDATA[				<p>Steak は Ruby 製の受け入れテストのためのフレームワークです。<br />
				<a target="_blank" href="https://github.com/cavalle/steak">cavalle/steak &#8211; GitHub</a></p>
				<p>Github にある説明を読んでいただくとわかると思いますが Steak ではテストは RSpec のように書くことができます。<br />
				同様のツールに Cucumber もありますが、Cucumber は英語や日本語で書かなければならないので、自分の中でどうもしっくりしませんでした。<br />
				そのため、自分にとっては Steak のようにかけた方がずっと書きやすいです。<br />
				ということで、これからは Steak を使って受け入れテストを書いていこうと思っています。</p>
				<p>そんな Steak ですが、RESTful API のテストもしたいです。<br />
				どうも Steak の裏で動いている Capybara というテストフレームワークは、 visit &#8216;/&#8217; のように GET することはできるのですが、 POST PUT DELETE というような RESTful API をテストする上ではそれだけでは足りません。</p>
				<p>以下のような方法で、POST 等のメソッドを呼び出すことが可能なようです。</p>
				<p>$RAILS_ROOT/spec/acceptance/support/helper.rb</p>
				<pre class="brush: ruby; title: ; notranslate">module HelperMethods
  def setup_driver
    @driver = Capybara.current_session.driver
  end

  def post(path, params = {})
    @driver.process :post, path, params
  end

  def put(path, params = {})
    @driver.process :put, path, params
  end

  def delete(path, params = {})
    @driver.process :delete, path, params
  end
end</pre>
				<p>$RAILS_ROOT/spec/acceptance/api/articles_spec.rb</p>
				<pre class="brush: ruby; title: ; notranslate">require File.dirname(__FILE__) + '/../acceptance_helper'

feature &quot;Articles&quot; do
  background do
    setup_driver
  end

  scenario 'update article' do
    params = { :article =&gt; {} }
    params[:article][:title] = 'foo'
    put('/api/articles/1.json', params)
  end
end</pre>
				<p>@driver.status_code とかでレスポンスのステータスコードが取得できたりします。<br />
				ほかの情報は<a target="_blank" href="http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Driver/Base">ここ</a>などを読むとよいでしょう。<br />
				<a target="_blank" href="http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Driver/Base">Class: Capybara::Driver::Base</a></p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="https://github.com/cavalle/steak">cavalle/steak &#8211; GitHub</a></li>
				<li><a target="_blank" href="https://github.com/jnicklas/capybara">jnicklas/capybara &#8211; GitHub</a></li>
				<li><a target="_blank" href="http://blog.ardes.com/2010/4/28/capybara-and-rack-test-sessions-and-http-methods">Capybara attack: rack-test, lost sessions and http request methods</a></li>
				<li><a target="_blank" href="http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Driver/Base">Class: Capybara::Driver::Base</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/12/post_856.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JRuby で ActiveRecord 3 をちょこっと試す</title>
		<link>http://www.cocoalife.net/2010/12/post_861.html</link>
		<comments>http://www.cocoalife.net/2010/12/post_861.html#comments</comments>
		<pubDate>Tue, 07 Dec 2010 09:28:08 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=861</guid>
		<description><![CDATA[JRuby で ActiveRecord を試してみたいと思いました。 JRuby は RVM で 1.5.6 がインストールされています。 こんな感じで .rvmrc を使用して JRuby 環境になっているものとします。 まずは ActiveRecord のインストール。 MySQL を使いたいので、普通の Ruby っぽく とやってみましたが、ダメでした。 こういうのを使う必要があるらしいです。 establish_connection のやり方も若干違います。 あとは同じみたいです。 参考文献 Using ActiveRecord and JDBC with JRuby Using ActiveRecord and JDBC with JRuby – Part 2]]></description>
			<content:encoded><![CDATA[				<p>JRuby で ActiveRecord を試してみたいと思いました。<br />
				JRuby は RVM で 1.5.6 がインストールされています。</p>
				<pre class="brush: bash; title: ; notranslate">$ echo &quot;rvm jruby&quot; &gt;&gt; .rvmrc</pre>
<p>こんな感じで .rvmrc を使用して JRuby 環境になっているものとします。</p>
<p>まずは ActiveRecord のインストール。</p>
<pre class="brush: bash; title: ; notranslate">$ gem install activerecord
Successfully installed activesupport-3.0.3
Successfully installed builder-2.1.2
Successfully installed i18n-0.5.0
Successfully installed activemodel-3.0.3
Successfully installed arel-2.0.6
Successfully installed tzinfo-0.3.23
Successfully installed activerecord-3.0.3
7 gems installed (...)</pre>
				<p>MySQL を使いたいので、普通の Ruby っぽく</p>
				<pre class="brush: bash; title: ; notranslate">$ gem install mysql</pre>
<p>とやってみましたが、ダメでした。</p>
<pre class="brush: bash; title: ; notranslate">$ gem install activerecord-jdbcmysql-adapter
Successfully installed activerecord-jdbc-adapter-1.0.3-java
Successfully installed jdbc-mysql-5.0.4
Successfully installed activerecord-jdbcmysql-adapter-1.0.3-java
3 gems installed (...)</pre>
				<p>こういうのを使う必要があるらしいです。<br />
				establish_connection のやり方も若干違います。</p>
				<pre class="brush: ruby; title: ; notranslate">require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
  :adapter =&gt; 'jdbcmysql',
  :host =&gt; 'localhost',
  :username =&gt; 'root',
  :password =&gt; '',
  :database =&gt; 'piyopiyo_development',
  :pool =&gt; 5
)</pre>
				<p>あとは同じみたいです。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://rubylearning.com/blog/2008/07/28/using-activerecord-and-jdbc-with-jruby/">Using ActiveRecord and JDBC with JRuby</a></li>
				<li><a target="_blank" href="http://rubylearning.com/blog/2008/07/30/using-activerecord-and-jdbc-with-jruby-part-2/">Using ActiveRecord and JDBC with JRuby – Part 2</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/12/post_861.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cURL で GET/POST/PUT/DELETE</title>
		<link>http://www.cocoalife.net/2010/11/post_859.html</link>
		<comments>http://www.cocoalife.net/2010/11/post_859.html#comments</comments>
		<pubDate>Sun, 07 Nov 2010 01:56:33 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=859</guid>
		<description><![CDATA[-X オプションでメソッド名 GET/POST/PUT/DELETE を指定すればよい。 Basic 認証をしたいときにはさらに &#8211;basic &#8211;user user:password をつける。 API を開発したいときには cURL様々！！！ 参考文献 letter: curl で BASIC 認証で POST cURL &#8211; How To Use （マニュアルページ日本語訳） Agave Mountain: HTTP GET, POST, and PUT with curl]]></description>
			<content:encoded><![CDATA[				<p>-X オプションでメソッド名 GET/POST/PUT/DELETE を指定すればよい。</p>
				<pre class="brush: bash; title: ; notranslate">curl -X PUT -d 'example[foo]=bar' -d 'example[jane]=doe' http://example.com/api/1/example/1.json</pre>
<p>Basic 認証をしたいときにはさらに &#8211;basic &#8211;user user:password をつける。</p>
<pre class="brush: bash; title: ; notranslate">curl --basic --user user:password -X PUT -d 'example[foo]=bar' -d 'example[jane]=doe' http://example.com/api/1/example/1.json</pre>
				<p>API を開発したいときには cURL様々！！！</p>
				<h2>参考文献</h2>
				<ul>
				<li><a href="http://read-eval-print.blogspot.com/2010/02/curl-basic-post.html">letter: curl で BASIC 認証で POST</a></li>
				<li><a target="_blank" href="http://www.hcn.zaq.ne.jp/___/unix/curl_manpage.html">cURL &#8211; How To Use （マニュアルページ日本語訳）</a></li>
				<li><a target="_blank" href="http://www.agavemountain.com/2007/09/http-get-post-and-put-with-curl.html">Agave Mountain: HTTP GET, POST, and PUT with curl</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/11/post_859.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>git でコミットを分解する</title>
		<link>http://www.cocoalife.net/2010/11/post_857.html</link>
		<comments>http://www.cocoalife.net/2010/11/post_857.html#comments</comments>
		<pubDate>Mon, 01 Nov 2010 16:03:31 +0000</pubDate>
		<dc:creator>milkcocoa</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.cocoalife.net/?p=857</guid>
		<description><![CDATA[git を使うと、ブランチをさくさく切ることができてそのブランチにとりあえずコミットしておいて、後で適当にきれいにまとめ上げて master へマージするなんてことがお手軽にできます。 変なところが適当で、変なところには几帳面な自分にはまさに打って付けな感じで、Subversion とかではなかなかコミットできなかったものの、今はとりあえず途中であってもコミットして、あとで修正するなんてこともやっています。 作業途中でもコミットできるのは便利なのですが、依存関係の問題でコミットしたものの一部を取り出してコミットしなおして、その部分だけを他のブランチへ入れたいなんてことがありました。 言い換えれば branchA の HEAD^ を分解する、HEAD^ の中にある一部のファイルだけを取り出してコミットし直すというのが今回やりたいことです。 git checkout branchA git reset --soft HEAD^ &#8211;soft を使うとコミットのみを取り消すことができます。 ちなみに &#8211;hard はコミットをなかったことにするものですので、コミット自体消えてしまいます。 これで index に記録された状態にまで戻ります。 この状態で通常の git reset をすれば、index 記録前の状態に戻るので、今回必要なファイルを index に記録するようにすればいいです。 すなわち git reset . git add foo git commit ということになります。 後は残りの部分を通常と同じようにコミットし、必要な部分を cherry-pick すれば、今回やりたいことはできました。 参考文献 Gitを使いこなすための20のコマンド &#8211; SourceForge.JP Magazine git-cherry-pickを掘り下げる &#8211; [...]]]></description>
			<content:encoded><![CDATA[				<p>git を使うと、ブランチをさくさく切ることができてそのブランチにとりあえずコミットしておいて、後で適当にきれいにまとめ上げて master へマージするなんてことがお手軽にできます。<br />
				変なところが適当で、変なところには几帳面な自分にはまさに打って付けな感じで、Subversion とかではなかなかコミットできなかったものの、今はとりあえず途中であってもコミットして、あとで修正するなんてこともやっています。</p>
				<p>作業途中でもコミットできるのは便利なのですが、依存関係の問題でコミットしたものの一部を取り出してコミットしなおして、その部分だけを他のブランチへ入れたいなんてことがありました。<br />
				言い換えれば branchA の HEAD^ を分解する、HEAD^ の中にある一部のファイルだけを取り出してコミットし直すというのが今回やりたいことです。</p>
				<pre>git checkout branchA
git reset --soft HEAD^</pre>
				<p>&#8211;soft を使うとコミットのみを取り消すことができます。<br />
				ちなみに &#8211;hard はコミットをなかったことにするものですので、コミット自体消えてしまいます。<br />
				これで index に記録された状態にまで戻ります。</p>
				<p>この状態で通常の git reset をすれば、index 記録前の状態に戻るので、今回必要なファイルを index に記録するようにすればいいです。</p>
				<p>すなわち</p>
				<pre>git reset .
git add foo
git commit</pre>
				<p>ということになります。</p>
				<p>後は残りの部分を通常と同じようにコミットし、必要な部分を cherry-pick すれば、今回やりたいことはできました。</p>
				<h2>参考文献</h2>
				<ul>
				<li><a target="_blank" href="http://sourceforge.jp/magazine/09/03/16/0831212/3">Gitを使いこなすための20のコマンド &#8211; SourceForge.JP Magazine</a></li>
				<li><a target="_blank" href="http://d.hatena.ne.jp/idesaku/20091230/1262159267">git-cherry-pickを掘り下げる &#8211; idesaku blog</a></li>
				</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoalife.net/2010/11/post_857.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

