sudo kill -9 `ps -A | grep mem | awk ‘{print $1}’` && memcached -m 20 -d
//返回某个时候的改动
git reset —soft …
git reset —hard …
git reset是指将当前head的内容重置,不会留log信息。
* git reset HEAD filename 从暂存区中移除文件| module MyModule | |
| module ClassMethods | |
| def act_as_my_module(params) | |
| #Note that in order to avoid having to escape string delimiters, we use a #special, multiline string syntax. Text between <<-DELIM ... DELIM is treated as a #plain old string. In this case, our string is Ruby code intended to be evaluated by #class_eval. | |
| class_eval do <<-DELIM | |
| def some_method | |
| #remember , string substitution | |
| #is OK here. e.g., #{params[:foo]} | |
| end | |
| DELIM |
| 获取当前IP地址:ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6- |
| class Hash | |
| def method_missing(method, *params) | |
| #首先得把symbol转化成string,如h={}.h.a = 1,此时,method 就为:a= | |
| method_string = method.to_s | |
| if method_string[-1] == 61 | |
| self[method_string[0..-2]] = params.first | |
| else | |
| self[method_string] | |
| end | |
| end |
| //Hash to Struct | |
| class Hash | |
| def to_struct(struct_name) | |
| Struct.new(struct_name,*keys).new(*values) | |
| end | |
| end | |
| if $0 == __FILE__ | |
| h = {:name=>"Dan","age"=>33,"rank"=>"SrA","grade"=>"E4"} |
| ActionRecord 配置 | |
| 整理出来方便查询 | |
| 1.ActionRecord:Base.logger=logger | |
| 接受一个logger对象。改对象被内部使用。用于记录数据库的操作。如果应用程序须记录数据库操作,也会使用这个logger对象。 | |
| 2.ActionRecord:Base.primary_key_prefix_type=option | |
| 如果option为nil.则所有表的缺省主键字段都是id,如果改选项值为:table_name,则会在"id"前面加上表名,如果改选值 为: | |
| table_name_with_underscore,则会在表名与id之间以下画线分隔。 | |
| 3.ActionRecord:Base.table_name_prefix="prefix" | |
| 在表名前面加上指定的字符串。譬如说,如果模型类叫做User,前缀字符串是"myapp-",则Rails会寻找名为"myapp- users"的表,如果 | |
| 需要与别的应用程序共享数据库,或者必须用同一个数据库进行并发开发与测试,这个选项就能派的上用场。 |
| >> New.find(1) | |
| ActiveRecord::RecordNotFound: Couldn't find New with ID=1 | |
| from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1591:in `find_one' | |
| from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1574:in `find_from_ids' | |
| from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:in `find' | |
| from (irb):4 | |
| >> New.find_by_id(1) | |
| => nil | |
| //直接利用find方式查找,如果没有数据会跑出异常,而利用find_by_id方式会返回nil |
| >> ActionWebService | |
| => ActionWebService | |
| >> ActionWebService::Dispatcher | |
| => ActionWebService::Dispatcher | |
| >> ActionWebService::Dispatcher::ActionController | |
| => ActionWebService::Dispatcher::ActionController | |
| >> ActionWebService::Dispatcher::ActionController::Base | |
| NameError: uninitialized constant ActionWebService::Dispatcher::ActionController::Base | |
| from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant' | |
| from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `rake_original_const_missing' |
重新更新了一次cucumber,发现在定义step的时候,还不能带空格了。如:
那么 /我能看到:(.+)/ do |text|
response.should contain(text)
end
定义行为为:
那么 我能看到: 某某某
会报错
而 把空格去掉就对了。。