Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
子不语
@42thcoder
高级会员
第 6764 位会员 / 2013-04-18

[email protected]
杭州
17 篇帖子 / 327 条回帖
41 关注者
107 正在关注
96 收藏
未来的不可知, 是前进的原动力
GitHub Public Repos
  • dotfiles 1

    A set of vim, zsh, git, and tmux configuration files.

  • block_yundun 1

    Rack middleware to block requests issued by aliyun yundun

  • dust 1

    A dead simple scripting language. Not perl, not ruby, not even rock. It's just dust.

  • 42thcoder.github.com 1

    My blog

  • twitterbio 0

    Generate your Twitter bio with OpenAI and Vercel Edge Functions.

  • alipay 0

    支付宝 AliPay SDK for Go, 集成简单,功能完善,持续更新,支持公钥证书和普通公钥进行签名和验签。

  • rocketmq-client-ruby 0

  • feeds 0

    Example repository for creating your own RSS feeds using Feed me up, Scotty!

  • ransack 0

    Object-based searching.

  • lottery 0

    🎉🌟✨🎈年会抽奖程序,基于 Express + Three.js的 3D 球体抽奖程序,奖品🧧🎁,文字,图片,抽奖规则均可配置,😜抽奖人员信息Excel一键导入😍,抽奖结果Excel导出😎,给你...

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 同时需要 API 和 Web 页面的 Rails 项目,怎样结合 Grape 和 Rails? at 2016年04月17日

    #17 楼 @numbcoder 只看过简单 JSON API 项目的人很难理解 Parameter Validation and Coercion 的重要性

  • Grape 怎么定义 JSON 的默认日期格式 at 2016年04月13日

    首先,强烈建议用时间戳; 实在是喜欢字符串格式,也一定要用 iso8601.

    Grape 是有内置 data format 的,先定义一个 helper:

    module Grape
      class Entity
        format_with(:unix_time) { |dt| dt.to_i }
        format_with(:iso8601) { |dt| dt.iso8601 } 
      end
    end
    

    Entity 里面可以这样用:

    class Foo < Grape::Entity
      root 'foos', 'foo'
    
      with_options(format_with: :unix_time) do
        expose :created_at, :updated_at
      end
    end
    
  • RailsDiff - 对比每个版本 Rails 默认生成出来的文件的差别 at 2016年04月13日

    #12 楼 @numbcoder https://github.com/rails/rails/issues?q=is%3Aopen+is%3Aissue+milestone%3A5.0.0+label%3A%22release+blocker%22

    这个 release blocker 已经挂了一个月了,感觉发布碰到瓶颈了啊

  • where 的一个蛋疼设定 at 2016年04月01日

    #22 楼 @catherine 防止 SQL 注入

  • where 的一个蛋疼设定 at 2016年04月01日

    这不是 where 的锅~ MySQL 下可以用 filed 来解决

    module Extensions::ActiveRecord::FindByOrderedIds
      extend ActiveSupport::Concern
      module ClassMethods
        def find_ordered(ids, table_name)
          return where(id: ids) unless ids.present?
          sanitized_id_string = ids.map {|id| connection.quote(id)}.join(',')
          where(id: ids).order("FIELD(#{table_name}.id, #{sanitized_id_string})")
        end
      end
    end
    
    ActiveRecord::Base.include(Extensions::ActiveRecord::FindByOrderedIds)
    

    A.find_ordered([3, 1,2,5]) 就会按顺序查出来了。

  • 分享一次排查问题的过程 at 2016年03月25日

    自顶向下,逐步锁定的思路很赞~

    不过回想起来,如果在最开始就花十五分钟尝试一遍潜在的常见问题,会省不少时间。或许可以做个小工具,依次检查:

    • DNS 解析
    • 简单数据查询:包括 db, redis, memcache
    • 其他
  • ngx_mruby Benchmark at 2016年03月18日

    #4 楼 @killyfreedom 不仅 ab 不可信,mac 也不可信,参考 Passenger 给出的 benchmark 指南。

    https://www.phusionpassenger.com/library/config/apache/optimization/#benchmarking-recommendations

  • Cookpad 微服务经验总结 at 2016年03月17日

    Cookpad 不是号称全世界最大的单一 Rails App 么?怎么也搞微服务了

  • 怎么获取对象的字面值? at 2016年03月03日

    -

  • 程序员健身 App 有木有需求? at 2016年03月01日

    上班坐久了需要站立十分钟、远眺一分钟,每天的日常任务早睡早起, 这些达不到健身的效果

  • ruby 单件类的单件类,实际编程中的用途是啥 at 2016年02月29日

    Singleton Class 和 Singleton Pattern 不是一回事吧

  • 你是如何跟踪开源软件的最新技术进展的? at 2016年02月29日

    打个广告,https://github.com/souche-hero/ruby-daily/issues

  • 让我们一起来起花名吧 at 2016年02月24日

    文章比代码长系列~

  • [深圳] DJI 大疆创新 Q1 招聘 Ruby 工程师 3 + 2 名 (saberma 内推 15-30k) at 2016年02月18日

    好赞啊,啥时候来杭州开分公司啊

  • 目前 Ruby 代码维护是如何保证质量的? at 2016年02月18日

    #5 楼 @jicheng1014

    新版的还不错啊,已经很像Travis CI了,唯一的遗憾是不支持 跑不通测试不允许合并 PR

  • Grape 方法小汇! at 2016年02月17日

    #2 楼 @xiaohesong

    对外显示的也变了啊:

    present StoreCustomer.find(params[:id]), with: ::Entities::CustomerSummary
    
    present StoreCustomer.find(params[:id]), with: ::Entities::Customer
    

    多表关联的场景用 delegate 更好吧

    class Customer < ActiveRecord::Base
      has_one :girl 
      delegate :name, to: :girl
    end
    
    class Customer < Grape::Entity
      expose :name
    end
    

    又或者这样:

    class Customer < Grape::Entity
      expose :name
    
      private
      def name
        object.girl.name
      end
    end
    

    params validation 应该是 Grape 最好用的特性之一,配合 Swagger 很方便

  • 目前 Ruby 代码维护是如何保证质量的? at 2016年02月16日
    • gitlab CI. 测试环境下,跑完测试之后自动部署
    • 分支的合并要走 pull request + code review

    代码风格和质量控制的工具有使用,但是仅供参考

  • Grape 方法小汇! at 2016年02月16日

    entity 内的用法

    • 用子类代替 if
    • 别名可以用 as
    module Entities
      class CustomerSummary < Grape::Entity
        expose :age, :name
        expose :phone_number, as: :login_name
      end
    
      class Customer < CustomerSummary
        expose :phone_number, :login_name
      end
    end
    

    创建功能出现的问题

    用 Grape 的话,就用它提供的 params validation 吧,没必要再用 strong params

  • 使用 Setter 方法代替 Before Validation at 2016年01月29日
    class Something
      def title=(val)
        write_attribute :title, val.strip
      end
    end
    

    Rails 5 中有了另一种写法:attribute :title, StripString.new.

    setter 要比 callback 清晰不少。

  • 有一打《Effective Ruby》要送给你,你不要,怪我咯~ at 2016年01月28日

    42thcoder , 已注册

  • PG 上线升级修好啦! at 2016年01月26日

    人肉测试啊啊啊

  • 送几本《AngularJS 学习手册》 at 2016年01月04日

    分母 +1

  • Rails 生成 model 时,如何添加字段说明,设置默认值等属性 at 2015年12月29日

    gem 'migration_comments'

    写迁移的时候这样写:

    add_column :topics, :visitors_count, :integer, default: 0, not_null: false, comment: '围观者计数'

    这样 annotate-models 生成的注释和数据库表都会有注释的。

  • 有哪些比较好的文档撰写工具 at 2015年12月25日

    https://github.com/tripit/slate

  • 碰到个奇怪的问题,运行几十个小时后之后,puma 的 worker 就开始变少... at 2015年12月22日

    #4 楼 @acaby 几十个小时太长了,短的话,用 strace 看下,有没有什么异常吧

  • DHH 亲自给你演示, 如何用 Action Cable 做一个实时的聊天 app at 2015年12月22日

    #12 楼 @rubyu2 别提那个项目了,现在想到就做噩梦

  • 碰到个奇怪的问题,运行几十个小时后之后,puma 的 worker 就开始变少... at 2015年12月21日

    #2 楼 @acaby 没道理啊,应该可以看到进程被杀的记录,搞清楚被谁杀的,问题就好定位了

  • 碰到个奇怪的问题,运行几十个小时后之后,puma 的 worker 就开始变少... at 2015年12月21日

    dmesg -T 看一下

  • Unicorn 和 Passenger open source 的简单性能对比 at 2015年12月17日

    https://www.phusionpassenger.com/library/config/nginx/optimization/#benchmarking-recommendations

  • 一口气把公司的 11 个 Rails 网站服务器换成了 Passenger, 太爽了 at 2015年12月17日

    #11 楼 @kikyous 企业版的开了多线程,内存占用是开源版的 1/ 3, TPS 也有不小的提升,省下的机器钱也差不多啦

  • 上一页
  • 1
  • 2
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • …
  • 10
  • 11
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English