Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
@quakewang
VIP
NO. 162 / 2011-11-22

[email protected]
上海
26 Topics / 752 Replies
212 Followers
4 Following
22 Favorites
GitHub Public Repos
  • rfcs 1

    This repository contains proposals, standards and documentations related to Nervos Network.

  • linux 1

    Linux kernel source tree

  • cfn-node 0

  • ckb 0

    CKB is a public/permissionless blockchain, the layer 1 of Nervos network.

  • ckb-did-plc-utils 0

  • hyprnote 0

    Privacy-first AI Notepad for back-to-back meetings

  • fiber-scripts 0

  • autocorrect 0

    A linter and formatter for help you improve copywriting, to correct spaces, punctuations between ...

  • ckb-light-client 0

    CKB light client reference implementation

  • ractor 0

    Rust actor framework

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 记一次 Redis 实战,实现答题系统 at August 05, 2016

    我来做的话,会选择用多一次查询:

    Topic.find (Topic.pluck(:id) - current_user.answered_topic_ids).sample
    
  • 请问有没有现成页面过期方案 at August 02, 2016

    ActiveRecord 有 Optimistic Locking,设置 lock_version 即可

  • 只有状态不同的条件可以如何重构? at July 08, 2016

    用 Hash 来替换 case when 是常见的重构方法:

    h = Hash.new(:opened).merge('closed' => :closed, 'foo' => :foo, 'bar' => :bar)
    Project.includes(:todos).sorted_by_alias_asc.send(h[params[:filter]])
    
  • 请问怎么用 Ruby 实现 1000!的末尾有多少个连续的 0 at July 01, 2016

    常见面试题: https://leetcode.com/problems/factorial-trailing-zeroes/

    n = 1000
    [1,2,3,4].map{|i| n / 5 ** i}.inject(:+)
    
  • RubyConf China 2016 赞助征集 at June 29, 2016

    #15 楼 @millim 大家会纷纷表示赞同

  • 怎让某个特定的 action 不打印 log at June 27, 2016

    换个方式,用现成的 ^_^ gem 'rack-heartbeat'

  • Git 的仓库网络和要发布的环境不在同一个网络,怎么使用 Capistrano 等工具? at June 21, 2016

    负责部署的机器应该可以同时访问 2 个网络吧,在这台机器上做个 ssh reverse tunnel 就好了

  • [北京] 幻腾科技寻找 Ruby 后端工程师 at June 12, 2016

    9 行 Ruby 求平均值的算法搞定 11600 分,有空用拟合算法试试看

  • [北京] 幻腾科技寻找 Ruby 后端工程师 at June 12, 2016

    这个加分题有意思,值得一战

  • rake assets:precompile RAILS_ENV=production 没有生成*.gz 文件 at June 08, 2016

    果然,后来又被加回来了 https://github.com/rails/sprockets/pull/193

    2 个项目的 gem 版本不一样吧

  • rake assets:precompile RAILS_ENV=production 没有生成*.gz 文件 at June 07, 2016

    在某个版本被移除了,官方说法是服务器(nginx/apache) 都提供了动态压缩,觉得没必要生成一个 gz 文件,就算一些 CDN 需要静态缓存,也只要额外执行一行命令,还可以让用户自己选择用什么压缩命令和压缩等级(推荐 zopfli,压缩率最高,但是压缩速度最慢),所以被移除了。

  • RailsConf 2016 - 我们如何为三万人的公司横向伸缩 GitLab at June 03, 2016

    关于 SSH 密钥,我在以前项目中是通过将用户上传的公钥保存在数据库,然后 sshd 通过配置 AuthorizedKeysCommand 和 AuthorizedKeysCommandRunAs 执行相关的脚本从数据库获取公钥,这个方案比多服务器同步更简单

  • [Problem, Ruby, Array] 如何检测一个字符串中包括某个数组中的元素? at May 24, 2016

    不用考虑效率的写法:

    keywords.any?{|k| string.include?(k)}
    
  • [杭州] App 招聘开发人员 at May 06, 2016

    #7 楼 @sunfjun 简历已发 ^_^

  • [杭州] App 招聘开发人员 at May 06, 2016

    好想为这个项目写代码啊,支持远程么?

  • 如何根据数据库表唯一索引生成唯一的随机字符串 at May 03, 2016

    http://hashids.org/ruby/

  • 用 slim,如何动态给个标签的 class 赋值? at April 22, 2016

    按原来的样子去掉<%就可以了

    div class="alert alert-#{message_type}"
      = message
    
  • 同时需要 API 和 Web 页面的 Rails 项目,怎样结合 Grape 和 Rails? at April 19, 2016

    #44 楼 @numbcoder 换个角度思考,如果 rails 配合一个 controller 层面的参数校验 gem,比如 https://github.com/nicolasblanco/rails_param ,是不是就和 grape 一样很方便做 api 了?或者根据项目需求,类似我举的 ransack 扩展,是不是就比 grape 更灵活?

    其实归结到一句正确的废话,对于 grape vs rails api,或者 webpack vs asset pipeline 等类似问题,答案都是你熟悉哪个用哪个,哈哈哈哈

  • 同时需要 API 和 Web 页面的 Rails 项目,怎样结合 Grape 和 Rails? at April 19, 2016

    #35 楼 @42thcoder RESTful api 关于 create/update api 数据校验是在 model 做的,关于 read/delete by id,这个并没有什么可说的。

    你举的关于复合查询 api,我通常会选择引入 ranksack ( https://github.com/activerecord-hackery/ransack ) ,然后写一个 hash 的 filter 扩展方法,用起来是这样:

    params.ransack_filter!(title: :cont, code: :eq, id: :eq, state: {predicate: :eq, values: [:closed, :done]})
    Order.search(params)
    

    不过不满足你例子里面的 dsl all_or_none_of,需要再做一些扩展,和 grape 的 dsl 相比,缺点是文档和代码不同步,优点是 2 行代码可以搞定(包括查询)

  • 同时需要 API 和 Web 页面的 Rails 项目,怎样结合 Grape 和 Rails? at April 19, 2016

    #37 楼 @numbcoder #38 楼 @jicheng1014 根据 id 或者根据 email 来查找,通过验证格式来减少数据库查询,这个是否要做,完全看项目需求和编码规范。

    但是 order by 或者其他查询直接依赖传入参数如果不做校验的话,不单单是潜在的性能 DDOS 问题,还有 sql 注入问题,这不是新手的问题,或者说是 rails、grape 的选择依据,完全是因为没有意识到这里的安全问题导致

  • PG 上线升级修好啦! at January 26, 2016

    #40 楼 @huacnlee 用户页面错误应该是这里查询改成等号就好了:

    https://github.com/ruby-china/ruby-china/blob/master/app/models/user.rb#L196

    where(login: slug).first || fail(ActiveRecord::RecordNotFound.new(slug: slug))
    
  • 我们将会在 2016-01-23 (本周六) 对服务器停机升级 at January 22, 2016

    手工点赞 +1

  • 大家刚参加工作时的待遇、福利都是怎么样的? at January 18, 2016

    2001 年,上海,3000,最大的福利是 15 天的年假...

  • Rails sanitize allowed_attributes 不安全 at January 18, 2016

    #4 楼 @rei 嗯,这样改更好,提个 PR 看看他们会不会收

  • Rails sanitize allowed_attributes 不安全 at January 18, 2016

    白名单没有考虑属性的内容,如果有需求,可以自定义 scrubber,不需要引入额外的 gem

    sanitize(html, scrubber: CustomPermitScrubber.new)
    
    class CustomPermitScrubber < Rails::Html::PermitScrubber
      def scrub(node)
        node.remove if node.name == 'a' && node["href"].present? && !node["href"].start_with?('http')
        super
      end
    end
    
  • 一些短小的例子:101 Ruby Code Factoids at January 15, 2016

    #3 楼 @z_ach 单身狗操作符... 跪了

  • mina 部署时遇到的问题 at January 14, 2016

    你执行 mina setup 以后会帮你创建好 shared 目录,这个目录下面有 config/database.yml 检查一下吧

  • mina 部署时遇到的问题 at January 14, 2016

    mina 的 database.yml 是需要另外 link,而不是 git pull 下来的,是不是 link 的文件里面没有配置 production 的数据库?

  • [找到答案,bundle] Ruby 有想 Python 的 virtualenv 工具吗? at January 14, 2016

    #4 楼 @eailfly 用 bundle 安装以后,加 bundle exec 无需全路径:

    bundle exec rails s
    
  • [leetcode] 316 Remove Duplicate Letters at January 14, 2016

    我的解法,用一个 hash 来保存最右侧字符的 index,可以减少判断时间

    def remove_duplicate_letters(s)
        cs, r = s.chars, []
        h = cs.map.with_index.to_h
        cs.each_with_index do |c, i|
            unless r.include?(c) 
                r.pop while r.last && c < r.last && i < h[r.last]
                r << c
            end
        end
        r.join
    end
    
  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 24
  • 25
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English