What's the "NERDTree"?
It's open file plugin by VIM.
http://www.flickr.com/photos/30496122@N07/2862367534/sizes/o/
How to install NERDTree
=========Create Folder============
cd ~
mkdir .vim
mkdir -p ~/.vim/autoload ~/.vim/bundle #Create Folder "autoload" and "bundle"
=========Load files===============
cd ~/.vim/bundle
git clone https://github.com/scrooloose/nerdtree.git
cd ~/.vim/autoload
curl -O https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
=========Setting .vimrc============(If you don't have .vimrc...touch .vimrc)
execute pathogen#infect()
syntax on
filetype plugin indent on
=========Open NERDTree===========
Open VIM and type ":NERDTree"
or
vim ~/.vimrc
nnoremap <silent> <F5> :NERDTree<CR>
push F5 open NERDTree
Reference:
http://www.vim.org/scripts/script.php?script_id=1658
https://github.com/scrooloose/nerdtree
https://github.com/tpope/vim-pathogen
https://www.youtube.com/watch?v=-GdaZ-Fuk9w
2016年3月19日 星期六
2016年1月29日 星期五
postgresql accept tcp/ip connections on port 5432
Modify two files and Restart PostgreSQL
1.pg_hba.conf
+ host all all 0.0.0.0/0 password
file path:
/etc/postgresql/9.4/main/pg_hba.conf
2.postgresql.conf
Remove the mark
#listen_addresses = '*'
#post = 5432
file path:
/etc/postgresql/9.4/main/postgresql.conf
Tyep Command Line:
service postgresql restart
2016年1月14日 星期四
Rails JSON API
可以用三種方式讓瀏覽器讀取URL顯示JSON
下面這種是撈取member這個table所有資料
http://localhost:3000/api/member
下面這種是撈取member的第一筆資料,如果要撈第50筆資料把數字改成50就好
http://localhost:3000/api/member/1
...
http://localhost:3000/api/member/50
下面這種跟http://localhost:3000/api/member/1 一樣都是撈第一筆資料只是URL寫法不同而已
http://localhost:3000/api/member/1.json
Model:
$rails g model member name:string email:string
Controller:
$rails g controller /api member
member_controller.rb
def index
@member = Member.all
render json: @member
end
def show
@member = Member.find(params[:id])
render json: @member
end
def create
@member = Member.new()
if @member.save
render json: @member
else
render json: @member.errors, status: :unprocessable_entity
end
end
def update
if@member.update()
render json: @member
else
render json: @member.errors, status: :unprocessable_entity
end
end
def destroy
@member.destroy
head :no_content
end
Routes:
namespace :api do
resource :members, only: [:index, :create, :show, :update, :destroy]
end
查詢資料
curl -i http://localhost:3000/api/member/
寫入資料
curl -i -X POST -H "Content-Type: application/json" -d '{"member": {"name":"Apple","email':"ABC@gmail.com"}}' http://localhost:3000/api/member
更新指定資料
curl -i -X PUT -H "Content-Type: application/json" -d '{"name":"Apple","email':"ABC@gmail.com"}}' http://localhost:3000/api/member/1
刪除指定資料
curl -i -X DELETE http://localhost:3000/api/member/1
下面這種是撈取member這個table所有資料
http://localhost:3000/api/member
下面這種是撈取member的第一筆資料,如果要撈第50筆資料把數字改成50就好
http://localhost:3000/api/member/1
...
http://localhost:3000/api/member/50
下面這種跟http://localhost:3000/api/member/1 一樣都是撈第一筆資料只是URL寫法不同而已
http://localhost:3000/api/member/1.json
Model:
$rails g model member name:string email:string
Controller:
$rails g controller /api member
member_controller.rb
def index
@member = Member.all
render json: @member
end
def show
@member = Member.find(params[:id])
render json: @member
end
def create
@member = Member.new()
if @member.save
render json: @member
else
render json: @member.errors, status: :unprocessable_entity
end
end
def update
if
end
def destroy
@member.destroy
head :no_content
end
Routes:
namespace :api do
resource :members, only: [:index, :create, :show, :update, :destroy]
end
查詢資料
curl -i http://localhost:3000/api/member/
寫入資料
curl -i -X POST -H "Content-Type: application/json" -d '{"member": {"name":"Apple","email':"ABC@gmail.com"}}' http://localhost:3000/api/member
更新指定資料
curl -i -X PUT -H "Content-Type: application/json" -d '{"name":"Apple","email':"ABC@gmail.com"}}' http://localhost:3000/api/member/1
刪除指定資料
curl -i -X DELETE http://localhost:3000/api/member/1
訂閱:
文章 (Atom)