Swiftで空のimageViewをadd

        //空のImageViewを貼る
        var frame = CGRectMake(0,0,1000,1000)
        UIGraphicsBeginImageContext(frame.size)
        var context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context,UIColor.whiteColor().CGColor);
        let uiImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.imageView = UIImageView(image:uiImage)
        self.baseUiView.addSubview(self.imageView)

SwiftでViewをaddとremove

                    //remove
                    self.readCanvas?.removeFromSuperview()
                    self.drawCanvas?.removeFromSuperview()
                                        
                    //ReadCanvas
                    self.readCanvas = UIView(frame:self.canvasFrame);
                    self.readCanvas.backgroundColor = UIColor.clearColor()
                    self.baseUiView.addSubview(self.readCanvas);
                    
                    //DrawCanvas
                    self.drawCanvas = UIView(frame:self.canvasFrame);
                    self.drawCanvas.backgroundColor = UIColor.clearColor()
                    self.baseUiView.addSubview(self.drawCanvas);

pod setupしたらエラーが起きたので、0.19.2を使うように変更

http://stackoverflow.com/questions/26273378/cant-install-cocoapods-report-on-pod-setup

$ pod setup
/Users/hoge/.rvm/gems/ruby-1.9.2-p320/gems/xcodeproj-0.19.3/lib/xcodeproj/plist_helper.rb:140:in `<module:CoreFoundation>': uninitialized constant Fiddle::NULL (NameError)
	from /Users/hoge/.rvm/gems/ruby-1.9.2-p320/gems/xcodeproj-0.19.3/lib/xcodeproj/plist_helper.rb:70:in `<top (required)>'
	from /Users/hoge/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require'
$ sudo gem uninstall xcodeproj
You have requested to uninstall the gem:
	xcodeproj-0.19.3
cocoapods-0.34.2 depends on xcodeproj (~> 0.19.2)
If you remove this gem, these dependencies will not be met.
Removing xcodeproj
Successfully uninstalled xcodeproj-0.19.3
$ sudo gem install xcodeproj -v 0.19.2
Successfully installed xcodeproj-0.19.2
Installing ri documentation for xcodeproj-0.19.2
Done installing documentation for xcodeproj after 2 seconds
1 gem installed

このあともう一度

$ pod setup
Checking out files: 100% (6742/6742), done.
Setup completed

Rails+Grape

Grapeのインストール

$ vim Gemfile
gem 'grape'
gem 'grape-jbuilder'
$ bundle install

APIディレクトリの作成

$ cd app/
$ mkdir api
$ vim api/api.rb
class API < Grape::API
  prefix "api"
  version 'v1', :using => :path
  format :json
  mount Users_API
end
$ vim /api/users_api.rb
class Users_API < Grape::API
  resource "users" do

    desc "returns all users"
    get do
      Books.all
    end
    
    desc "return a users"
    params do
      requires :id, type: Integer
    end
    get ':id' do
      Users.find(params[:id])
    end

  end
end

パスの設定

$ vim config/application.rb
module Fiddlercrab
  class Application < Rails::Application
    ・・・・
    config.autoload_paths += %W(#{config.root}/api)
  end
end

ルーティングをチェック

$ rake routes

テーブルの作成例

rails g model users name:text comment:text icon_url:text
rails g model feeds user_id:integer user_name:text icon_url:text comment:text 
rails g model feed_comments feed_id:integer user_id:integer user_name:text icon_url:text comment:text 
rake db:create
rake db:migrate
rake db:migrate:reset

Railsアプリ作成memo

新規アプリを作る

$ rails new sample -d mysql
$ cd sample
(bundleをスキップする場合)
$ rails new sample -d mysql --skip-bundle

コントローラーを作る

cd /root/sample/app/controllers
rails generate controller test

コントローラーtest

class TestController < ApplicationController

def hello
  render:text=>'hello'
end

def bye
  render:text=>'bye'
end

end

MySQL接続

//config/database.ymlの内容でデータベースを作る
$ rake db:create

ルーティングを作成

$ vim config/routes.rb
-------------
Rails.application.routes.draw do
  match ':controller(/:action(/:id))', via: [ :get, :post, :patch ]
end
-------------

ルーティングをcheck

$ rake routes

サーバー起動

$ rails s --port=80

Railsインストールmemo

Git Installation

$ sudo yum install git

rbenv install

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ exec $SHELL
$ rbenv

ruby-build Installation

$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

OpenSSL install

$ sudo yum -y install openssl-devel

Ruby Installation

$ rbenv install 2.1.0
$ rbenv rehash
$ rbenv global 2.1.0

RDoc Installation

gem install rdoc

Ruby on Rails Installation

$ gem install rails
$ rbenv rehash
$ rails -v

bundler Installation

gem install bundler

MySQL Installation

$ sudo yum install -y mysql-server mysql-devel 
$ sudo service mysqld start
$ sudo chkconfig mysqld on
$ mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* to 'rails'@'localhost' IDENTIFIED BY 'password';

VersionCheck

$ ruby --version
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails --version
Rails 4.1.6
$ gem -v
2.2.0