`
mvj3
  • 浏览: 24117 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
Object.constants.map(&:constantize).select {|c| c.included_modules.include?(Mongoid::Document) rescue nil }.compact.map(&:create_indexes)
$ redis-stat ------- data ------ --------------------- load -------------------- - child - keys       mem      clients blocked requests            connections          3          1.30M    1       0       150000 (+150000)    751         3          1.30M    1       0       150001 (+1)         751    ...
服务器信息: [mvj3@sdk2 ~]$ cat /proc/version Linux version 2.6.18-194.el5 (mockbuild@ca-build10.us.oracle.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Mon Mar 29 22:10:29 EDT 2010 出错信息: [mvj3@sdk2 ~]$ sudo yum install gettext-devel httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-dev ...
Rails里多项目公用models时定义了default_scope,在别的项目里,虽然可以用unscoped,或with_exclusive_scope来取消或覆写,但是RailsAdmin的框架机制不方便直接改写。 因为scope的机制是更新或添加条件,但是不能删除条件,所以在添加default_scope的时候判断一下即可: default_scope where(:status => 1) unless defined? RailsAdmin
Rails项目里同事发现配置的 exception_notification_rails3 没有正常的发出异常错误邮件 对比了下我这边正常的配置,把config.middleware.use ExceptionNotifier 放到config/application.rb里最后就可以了,虽然没有从源码里看出问题来 = =
统计分析需要跑各个时间粒度的任务,如果异常中断后重新选择某个时间删除后再跑的时候,有时候还是会有重复的统计数据。 在mongodb中建立唯一索引时加上dropDups选项可以解决此问题: A unique index cannot be created on a key that has pre-existing duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent d ...
帮同事在一台centos上安装nokogiri,记载如下: 系统信息: [root@localhost ~]# uname -a Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]# cat /proc/version Linux version 2.6.18-194.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 200807 ...
sqlite3-ruby的1.3版本在CentOS不兼容,访问数据库时报如下错误: /usr/local/ruby/ruby-enterprise-1.8.7-2011.03/bin/ruby: symbol lookup error: /usr/local/ruby/ruby-enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_open_v2 退回到1.2.5版本,问题解决 gem install sqlit ...
如果Gemfile所列出来的gem全在Gemfile.lock里,加上--local选项可以直接绕过 请求rubygems.org的gem列表,从而达到加速本地生成Gemfile.lock。
irb(main):023:0> html =<<-HTML <div class="doc-description toggle-overflow-contents"> <div id="doc-original-text">“Shave Me!” combines touchscreen game fun with close-shave precision perfection.<p>The iOS shaving sensation has arrived in the Android ...
发现一个诡异的现象,Rails在production模式下启动后找不到资源,报如下错误: Started GET "/images/people.jpg" for 127.0.0.1 at Mon Jul 25 14:21:35 +0800 2011 ActionController::RoutingError (No route matches [GET] "/images/people.jpg"):   Rendered /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/actionpack-3.1.0.rc4 ...
在Gemfile里引用一个没有gemspec的gem时,运行bundle install的时候会提示 Could not find gem 'mechanize (>= 0)' in git://github.com/mvj3/mechanize.git (at master). Source does not contain any versions of 'mechanize (>= 0)' 解决方案: 指定gem的版本即可,如 gem 'mechanize', '2.0', :git => 'git://github.com/mvj3/mechanize.git' ...

二分查找和插入

    博客分类:
  • ruby
# 二分查找(又称折半查找)是在一个有序表里查找元素的复杂度为O(log(n))的算法。先从中# 二分查找(又称折半查找)是在一个有序表里查找元素的复杂度为O(log(n))的算法。先从中间位置开始比较,相等则返回,如小于中间值 ...
换用sphinx后,产品同事发现旧的数据也能搜索出新数据来,查了下官方文档 http://sphinxsearch.com/docs/manual-0.9.9.html#index-merging, 发现更新索引时thinking-sphinx没有把它自定义的sphinx_deleted属性同时更新上去,导致在执行增量索引时用的--merge-dst-range选项无效。现解决方案如下: 1,在config/production.sphinx.conf的searchd部分加上 attr_flush_period = 5 ,让sphinx在更新sphinx_deleted属性后写入到磁盘里。 ...
# 一个简单的姓名拼音匹配 # # 姓名一般是由两三个汉字组成,选其顺序且连续的拼音缩略的组合就算匹配成功。 # require 'chinese_pinyin' @name = "成吉思汗" pinyins = Pinyin.t(@name).split # 把姓名生成对应的拼音数组 array = [] pinyins.each_with_index do |han, index| array[index] = [] han.size.times {|num| array[index] << han[0..(num - 1 ...
Global site tag (gtag.js) - Google Analytics