Tuesday, October 27, 2009

grep命令参数-显示查询内容的所在行号

使用grep命令时,添加行号(-n)可以显示查询内容的所在行的行号,如:
$> grep -n ls ~/.bashrc
1:# ~/.bashrc: executed by bash(1) for non-login shells.
47: else
54:else
77:# enable color support of ls and also add handy aliases
80: alias ls='ls --color=auto'
81: alias ll='ls -la'
90:# some more ls aliases
91:#alias ll='ls -l'
92:#alias la='ls -A'
93:#alias l='ls -CF'

Sunday, September 27, 2009

svn 批量添加新文件

$> svn status |grep '^\?'|awk -F " " '{print $2}'|xargs svn add

或者是
$> svn st|grep '^\?'|sed 's/^\?\s*//g'|xargs svn add

Monday, September 07, 2009

Helpers Outside Views

How to access helper methods outside of the view layer?


# models/category.rb
def description
  "This category has #{helpers.pluralize(products.count, 'product')}."
end

def helpers
  ActionController::Base.helpers
end

# products_controller.rb
def create
  @product = Product.new(params[:product])
  if @product.save
    flash[:notice] = "Successfully created #{@template.link_to('product', @product)}."
    redirect_to products_url
  else
    render :action => 'new'
  end
end


Reference: http://railscasts.com/episodes/132-helpers-outside-views