Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Howl王
@mimosa
高级会员
第 5 位会员 / 2011-10-28

Autodesk
上海
39 篇帖子 / 570 条回帖
46 关注者
19 正在关注
42 收藏
┬─┬ノ❨°_°ノ❩ ..persecution mania
GitHub Public Repos
  • ansj_seg 6

  • docker-tengine 3

  • grape-erb 2

    Use erb in grape

  • shrine-tus-demo 1

    Demo integrating tus with Shrine

  • ChatGPT-Next-Web 1

    A well-designed cross-platform ChatGPT UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT 应用。

  • rest_cli 1

  • codeowners-checker 0

    Check .github/CODEOWNERS consistency

  • gatsby-starter-portfol... 0

    Playful and Colorful One-Page portfolio featuring Parallax effects and animations. Especially des...

  • logstop 0

    Keep personally identifiable information (PII) out of your logs

  • readme-code-testing 0

    Helping test "any" code in readme with GitHub Action. All you need is unit testing synchronized e...

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [杭州] 浮冬数据招聘 Ruby 工程师 (电竞大数据) 月薪 20K-30K at 2016年12月07日

    同求

  • [上海] 波辣兔招聘 Ruby 工程师 2 名,前端 1 名,15k-30k (内衣电商+社区) at 2016年12月06日

    只想去看妹纸🔞

  • 请教大家 ES 在 Rails 里怎么添加账号密码进行链接 at 2016年12月06日

    通过 elasticsearch-transport 和 自定义 faraday middleware

    PS:专修各种🐛,150 起~

  • [北京] Linkface 研发中心招聘 Ruby 研发工程师 2-3 名 (15~30K) at 2016年12月05日

    #3 楼 @babybird 赶紧下载我们的 女神经 app 测下颜值,体验下人脸识别 🔞

  • Sidekiq worker 中调用 Java at 2016年12月05日

    #4 楼 @thxagain 参看 https://github.com/mimosa/ansj_seg 中的源码。

  • Sidekiq worker 中调用 Java at 2016年12月05日

    JRuby

  • Rails 新手,请教一个关于时间格式化问题 at 2016年11月23日
    # config/initializers/time_with_zone.rb
    
    if defined?(::ActiveSupport)
      # ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
    
      class ActiveSupport::TimeWithZone
        def as_json(opts = {}) # 可配置数据格式
          opts.assert_valid_keys(:date_format)
          opts[:date_format] ||= :default # 默认时间格式
    
          if ActiveSupport::JSON::Encoding.use_standard_json_time_format
            xmlschema(ActiveSupport::JSON::Encoding.time_precision)
          else
            self.to_s opts[:date_format]
          end
        end
      end
    end
    
  • [译] Rails 数据库最佳实践 at 2016年11月21日

    #4 楼 @roclv 了解,thx 👌

  • [译] Rails 数据库最佳实践 at 2016年11月20日

    有个地方不明白,复杂的 scope 写成一个 Query 对象,这个文件放在那里?怎么看起来像个 Service 😒

    目前的做法是写成 concerns 再 include 到 model类里。

  • 如何判断 Ruby 两个数组中,是否有相同元素,求方法 at 2016年11月18日

    #11 楼 @Cger007 用减好吗 🔞

    [1] pry(main)> [4, 5, 3] & []
    => []
    [2] pry(main)> [4, 5, 3] - []
    => [4, 5, 3]
    
  • 如何判断 Ruby 两个数组中,是否有相同元素,求方法 at 2016年11月18日

    #8 楼 @Cger007 那楼上的方法就可以啦。

    同组测试:

    [1] pry(main)> # 当前用户的GROUP
    [2] pry(main)> current_user_groups = ['ADMIN', 'USER']
    => ["ADMIN", "USER"]
    [3] pry(main)> # 被指派用户的GROUP
    [4] pry(main)> assigned_user_groups = ['USER', 'TEST', 'GUEST']
    => ["USER", "TEST", "GUEST"]
    [5] pry(main)> diff_group(current_user_groups, assigned_user_groups)
    => false
    

    异组测试:

    [1] pry(main)> # 当前用户的GROUP
    [2] pry(main)> current_user_groups = ['ADMIN', 'USER', 'TEST']
    => ["ADMIN", "USER", "TEST"]
    [3] pry(main)> # 被指派用户的GROUP
    [4] pry(main)> assigned_user_groups = ['TEST', 'GUEST']
    => ["TEST", "GUEST"]
    [5] pry(main)> diff_group(current_user_groups, assigned_user_groups)
    => true
    
  • 在 Rails 中使用 Yarn 管理三方 assets at 2016年11月18日

    我在用 gem 'bower-rails', '~> 0.11.0'

  • 如何判断 Ruby 两个数组中,是否有相同元素,求方法 at 2016年11月18日

    #6 楼 @Cger007 所以请问怎样的两组才算是不同的?给两组测试数据呗😋

    def diff_group(a, b, c = ['TEST'])
      (a & b - c).empty?  
    end 
    
  • 如何判断 Ruby 两个数组中,是否有相同元素,求方法 at 2016年11月18日

    #3 楼 @Cger007 你的代码本身就有错 😜

    # 当前用户的GROUP
    current_user_groups = ['ADMIN', 'USER']
    # 被指派用户的GROUP
    assigned_user_groups = ['USER', 'TEST', 'ADMIN']
    => true
    

    起码应该这样:

    # 判断指派人与被指派人是否同组
    def diff_group(a, b)
      diff = false # 设置默认为同组
      a.each do |k|
        b.each do |e|
          puts "#{k} <=> #{e}"
          diff = (k != e && e!= "TEST")
        end
      end
      diff
    end
    

    如果是俺理解错了,那也该这样:

    # 判断指派人与被指派人是否同组
    def diff_group(a, b)
      a.each do |k|
        b.each do |e|
          if k != e && e!= "TEST"
            puts "#{k} <=> #{e}"
            return true
          end
        end
      end
      false # 设置默认为同组
    end
    
  • 如何判断 Ruby 两个数组中,是否有相同元素,求方法 at 2016年11月18日
    [1] pry(main)> [1,2,3] & [2,3,4]
    => [2, 3]
    
  • 设备分配的问题 at 2016年11月16日

    #4 楼 @thxagain [2, 3] 不会出现?

    ([2, 3, 4] | ([1, 2, 3] & [4, 5, 6] )).sample(2)
    
  • 最新的 Hanami 框架的进展 at 2016年11月16日

    有意思🔞

  • 自己编译, 让 Ruby 加速 7~10%(亲测有效) at 2016年11月14日

    默认编译参数:

    ruby -r rbconfig -e 'RbConfig::CONFIG.sort.each { |c| p c }'
    ・
    ["optflags", "-O3 -fno-fast-math"]
    ・
    ・
    

    rbenv 可以这样:

    OPTFLAGS='-O3 -fno-fast-math -mllvm -inline-threshold=5000' rbenv install 2.3.1
    
    ruby -r rbconfig -e 'puts RbConfig::CONFIG["OPTFLAGS"]'
    → -O3 -fno-fast-math -mllvm -inline-threshold=5000
    
  • 需求方说 Ruby 是什么啊?我大上海没人认识! at 2016年11月03日

    要讲求沟通技巧,小项目用什么 PHP 呀,杀鸡用牛刀 😜

  • 怎么把传到控制器的检索条件给写进语句里? at 2016年11月03日

    statistical_charging_piles 是什么,方法?

  • 怎么把传到控制器的检索条件给写进语句里? at 2016年11月02日

    #6 楼 @yu7272yu kaminari 可以分页。

  • 怎么把传到控制器的检索条件给写进语句里? at 2016年11月02日

    #3 楼 @yu7272yu

    
    params[:order_total] = case params[:order_total]
    when 'gt'
     '>'
    when 'gteq'
     '>='
    when 'lt'
     '<'
    when 'lteq'
     '<='
    else
     '='
    end
    
    
    ...
    .having("order_total_sum #{params[:order_total]} ? ", params[:order_total_cont] )
    ...
    
    
  • 你好,在使用 ActionCable,如果掉线后重连,怎么让 Rails 服务端重现推送错过的信息 at 2016年11月01日

    这需要一种建立一种机制,客户端收到消息后回执,标注过的消息从队列中删除,客户端上线(subscribed)后触发(未标示)队列。😱

    # -*- encoding: utf-8 -*-
    
    class NotificationsChannel < ApplicationCable::Channel
      def subscribed
        stop_all_streams
        stream_from channel_id
        count # 连接后可触发
      end
    
      def unsubscribed
        stop_all_streams
      end
    
      def speak(data)
        ActionCableWorker.perform_async(channel_id, data) # Sidekiq 任务
      end
    
      def count
        speak( message: "当前连接数: #{ActionCable.server.connections.count}" )
      end
    
      private
        def channel_id
          "notifications:#{self.user_id || 'public'}"
        end
    end
    
  • 把 StartCom 的 root ca 标注成不信任之后,Ruby China 的源就不能用了 at 2016年10月26日

    Let's Encrypt Authority X3 💯

  • Rails 5 如何自定义处理 ActionDispatch::ParamsParser::ParseError 异常 at 2016年10月20日

    @charleszhang 试试呗。😔

    # in app/middleware/catch_json_parse_errors.rb
    class CatchJsonParseErrors
      def initialize(app)
        @app = app
      end
    
      def call(env)
        begin
          @app.call(env)
        rescue ActionDispatch::Http::Parameters::ParseError => e
          if env['HTTP_ACCEPT'] =~ /application\/json/
            error_output = "There was a problem in the JSON you submitted: #{e.message}"
            return [
              400, { "Content-Type" => "application/json" },
              [ { status: 400, error: error_output }.to_json ]
            ]
          else
            raise error
          end
        end
      end
    end
    
    
    # in config/application.rb
    module YourApp
      class Application < Rails::Application
        # ...
        config.middleware.insert_after ActionDispatch::ShowExceptions, 'CatchJsonParseErrors'
        # ...
      end
    end
    
  • Rails 5 如何自定义处理 ActionDispatch::ParamsParser::ParseError 异常 at 2016年10月19日

    #2 楼 @charleszhang Rails5 移除了 ActionDispatch::ParamsParser

  • Rails 5 如何自定义处理 ActionDispatch::ParamsParser::ParseError 异常 at 2016年10月19日
    # insert middleware wherever you want in the stack, optionally pass initialization arguments
      config.middleware.insert_before ActionDispatch::ParamsParser, Rack::Robustness do |c|
        c.no_catch_all
        c.on(ArgumentError) { |ex| 400 }
        c.content_type 'application/json'
        c.body{ |ex| 
          { 
            error: ex.message
          }.to_json
        }
        c.ensure(true) { |ex| env['rack.errors'].write(ex.message) }
      end if Rails.env.production? # 生产环境
    
  • 求教,不知道这个语句有没有更简便的写法呢,看着太丑了。 at 2016年10月15日

    不优化你的 SQL 逻辑,简单可以这样

    plan = Plan.where('((start_time >= :start_at and start_time <= :end_at) or (end_time >= :end_at and end_time <= :end_at) or (start_time <= ? and start_time >= ?) or (start_time >= ? and start_time <= ?) or (start_time <= ? and end_time >= ?))',start_at: start_at, end_at : end_at)
    

    PS: 问号我就不帮你一一替换了,手机不方便输入。

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