Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Zheng Piaodan
@zhengpd
会员
第 21370 位会员 / 2015-09-30

自由职业
Guangdong
8 篇帖子 / 157 条回帖
12 关注者
0 正在关注
2 收藏
GitHub Public Repos
  • cape 0

    🦸cape.el - Completion At Point Extensions

  • modus-themes.nvim 0

    Highly accessible themes for Neovim, conforming with the highest standard for color contrast betw...

  • zenbones.nvim 0

    🪨 A collection of contrast-based Vim/Neovim colorschemes

  • toggleterm.nvim 0

    A neovim lua plugin to help easily manage multiple terminal windows

  • nvim-lspconfig 0

    Quickstart configs for Nvim LSP

  • bamboo.nvim 0

    Warm Green Theme for Neovim and Beyond

  • trim.nvim 0

    This plugin trims trailing whitespace and lines.

  • Gogh 0

    Gogh is a collection of color schemes for various terminal emulators, including Gnome Terminal, P...

  • monokai-pro.nvim 0

    Monokai Pro theme for Neovim written in Lua, with multiple filters: Pro, Classic, Machine, Octago...

  • per-directory-history 0

    Per directory history for zsh, as well as global history, and the ability to toggle between them ...

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 简单的概率问题一直困扰着我 at 2021年08月31日

    小细节:C8-2 是 28

  • 我想知道 rails 怎麽區分大小寫查找 at 2021年08月17日

    where 要分开

    Client.where("client_address like binary(?)", "%#{email}%").where(del_flg: 0)
    
  • 更新元素的比较问题 at 2021年07月22日

    可以考虑命令行处理,通过 comm 工具获取两个文件不同的行:

    • comm -3 -2 <(sort file1) <(sort file2) 是 file1 有,file2 没有
    • comm -3 -1 <(sort file1) <(sort file2) 是 file2 有,file1 没有
  • 再见 Crud 程序员 at 2021年07月09日

    The GitHub Copilot editor extension sends your comments and code to the GitHub Copilot service, which then uses OpenAI Codex to synthesize and suggest individual lines and whole functions.

    如果我在 vscode 编辑一个带有密码的文件,不知道会不会被上传分析 🤔

  • Hotwire 环境下搭配使用传统轮播组件 Slick at 2021年06月02日

    看了下 homeland 只是做 image src 的替换,imageproxy 是支持 gif 的,所以估计是 imageproxy 配置问题

  • 都说 Ruby 性能差,GitHub 是怎么改善 Ruby on Rails 的性能的? at 2021年06月02日

    aws 是 intel 的 mac mini,m1 大概还在计划中

    Amazon EC2 Mac instances are built on Apple Mac mini computers, featuring 8th Generation 3.2GHz (4.6GHz turbo) Intel Core i7 processors with 6 physical/12 logical cores, and 32GiB of Memory

  • Ruby 脚本中执行 其他 shell 命令, 控制台如何打印子线程的输出 at 2021年06月02日

    可能需要 Open3.capture3 或者 Open3.popen3

  • Hotwire 环境下搭配使用传统轮播组件 Slick at 2021年06月01日

    感觉是 bug,提 pr 的机会来了 🤔

  • Puma worker 有内存回收/重启机制吗? at 2021年06月01日

    内存占用似乎只涨不跌。启动时内存 300m,过几天将近 2g,但是从来没有发现内存下降

    大概率是内存泄漏,慢慢排查吧

  • Rails 多线程并发占用 CPU 问题 at 2021年05月30日

    ruby 2.x 多线程主要是减少了 IO 等待时间,提高 IO 密集场景下的 CPU 利用率。由于 GVL 的存在,实际上同一时刻只会有一段 ruby 代码被执行,也就是并发而不是并行,所以不管有几个客户端请求,单进程下也只能等同于单核的效率。GVL 是进程级别的,所以要用多核心就需要多开几个进程

    ruby 3 加了 ractor 支持多核

  • 求教, Ruby 的 Git 操作库, Rugged 如何执行 git pull? at 2021年05月28日

    git pull 就是 git fetch && git merge

    感觉可以用 rugged 的 remote.fetch 和 tree.merge 搞,测试里有 fetch 和 merge 的例子

    • https://github.com/libgit2/rugged/blob/4a0b24c4065c6d977d4596cfb48b55999fecae9f/test/remote_test.rb
    • https://github.com/libgit2/rugged/blob/4a0b24c4065c6d977d4596cfb48b55999fecae9f/test/merge_test.rb
  • 怎么获取数据库 created_at 的年份和月份 at 2021年05月14日

    created_at.to_date == Date.today 的比较采用的是 ruby 内部存储结构的数据值,不是比较字符串类型的 '2021-5-14'

  • 怎么获取数据库 created_at 的年份和月份 at 2021年05月14日

    上 rails 建议用 Time.current 和 Date.current,因为 Time.now 和 Date.today 用的是操作系统的时区和时间,在 rails 时区跟系统不同时就时间不正确了

  • Rails 连接数据库出错 at 2021年05月12日

    可以看看 ENV['DATABASE_URL'] 是不是有值

  • uniqueness validation not work 现在能解决了吗? at 2021年04月28日

    500 比清除重复数据好处理,比如 rescue 之后返给前端个提示“xxx 被占用”

  • 数据库列名与 Rails 方法名冲突怎么解决? at 2021年03月05日

    https://github.com/bjones/safe_attributes

    可以看下这个 gem,好久没更新,里边的方法大概可以参考

  • ractor 有没有更简洁的写法 at 2021年02月10日

    方法里边的第二个 loop 我的想法是用 select 去取先完成的 ractor,然后执行数组的下一个待处理元素,理论上是你说的第 3 点的逻辑,不过也没仔细验证过。

    1、2 不太清楚,ractor 我只是简单看了下,还不如你有经验

  • 写了个类 markdown 编译器,欢迎指教! at 2021年02月06日

    路漫漫,楼主加油

    markdown 不够用的话,可以看看 asciidoctor.org,支持更多场景

  • ruby map 有没有更简洁的写法 at 2021年02月04日

    ruby 内置的方法应该是没有,map 不支持额外的参数,所以也没有 arr.map(&:[], :a)。自己搞一个:

    class Array
      def map_hash_value(key)
        map { |x| x[key] }
      end
    end
    
    [{a: 1}, {a: 2}].map_hash_value(:a) 
    # => [1, 2]
    
  • 【求助】刚学习 Ruby,想要开发一个填写联系表格发送邮件的网页 at 2021年02月03日

    随即使用 gem install mail_form 安装。并运行 bundle install

    楼主是不是跳过了教程的第一步:Edit Gemfile 🤔

  • ractor 有没有更简洁的写法 at 2021年01月29日

    想了个 Array#ractor_map 方法

    class Array
      def ractor_map(handler, ractors_count: 1)
        Ractor.make_shareable(handler)
    
        array_length = length
        min_count = [ractors_count, array_length].min
    
        ractors = min_count.times.map do
          Ractor.new handler do |handler|
            loop do
              recv = Ractor.receive
    
              break if recv.is_a?(Interrupt)
    
              Ractor.yield handler.call(recv)
            end
          end
        end
    
        (0...min_count).each { |index| ractors[index].send self[index] }
    
        next_index = ractors_count
        result = []
    
        loop do
          ractor, ret = Ractor.select(*ractors)
          result << ret
    
          if result.length >= array_length
            ractors.each { |r| r.send Interrupt.new }
            break
          end
    
          ractor.send(self[next_index]) if next_index < array_length
    
          next_index += 1
        end
    
        result
      end
    end
    
    handler = proc { |x| x / 2 }
    result = [1, 2, 3, 4, 5].ractor_map(handler, ractors_count: 2)
    puts result.inspect # => [1, 0, 1, 2, 2]
    
  • [深圳 Roblox China 罗布乐思 内推,长期有效] 硅谷独角兽游戏公司求贤若渴 at 2021年01月23日

    注明想申请的岗位以及来自 V2EX

    🤔

  • 求助 Docker 方式安装 Homeland 邮件配置发送不了邮件 at 2021年01月19日

    没搞过,只能说,慢慢琢磨吧,比如换个 gmail outlook 试试

  • 求助 Docker 方式安装 Homeland 邮件配置发送不了邮件 at 2021年01月19日

    google "smtp rbuf_fill eof" 有很多结果,可能其中某条结果能解决你的问题 🤔

  • null at 2021年01月17日

    你大概需要的是 resources :topics, param: :topic_name https://guides.rubyonrails.org/routing.html#overriding-named-route-parameters

  • 请教关于 Ruby 方法的一些问题 at 2021年01月16日
    1. 用楼上提到的关键词参数。def test(x = 2, y = 3) 中的 x y 是位置参数。test(y = 5) 的执行逻辑是:y = 5 -> test(5) ,所以 x 是 5
    2. f = -> (x;y) {x} 中的分号是 block local variable 语法,我很少见到用这个的。In short, block local variables shield a block from manipulating variables outside of its scope. see here
    3. 楼上说了
  • ruby quiz at 2021年01月11日

    受 scan 启发,调整了一下,似乎也可以

    str = 'idP111~nm~~nm xxx ~~~~~~~~ ~~id~~br~~~qt10'
    keys = %w[id nm qt pr]
    
    pairs = str.scan(/(#{keys.join('|')})(.+?[^~](?:~~)*(?=(?:~[^~])|$))/)
    pairs.each_with_object({}) { |(k, v), hash| hash[k] = v.gsub('~~', '~') }
    
  • ruby quiz at 2021年01月10日

    补充一下:

    把 ~~ 替换成 ^^ 可行是因为规则 2 使得 encode 后 value 里的 ~ 必然是双数,规则 3 的连接 ~ 必然是 N 个双数 ~ 的最后一个,除非 id 前会有 ~。

    ^^ 可以换成任何小概率出现在 value 的字符串,比如 ^^^^^^^^^

  • ruby quiz at 2021年01月10日
    # rebuild-hash.rb
    str = 'idP111~nm~~nm xxx ~~~~~~~~ ~~id~~br~~~qt10'
    
    KEYS = %w[id nm qt pr]
    
    # 'idP111' => ['id', 'P111']
    def unjoin(pair)
      key = KEYS.detect{ |key| pair[/^#{key}/] }
      value = pair[/(?<=#{key}).*/].gsub('^^', '~')
      [key, value]
    end
    
    puts str.gsub(/~{2}/, '^^').split('~').map{ |pair| unjoin(pair) }.to_h
    # => {"id"=>"P111", "nm"=>"~nm xxx ~~~~ ~id~br~", "qt"=>"10"}
    

    decode 的难点在 N 个~,把 ~~ 替换成 ^^ ,让正则去做复杂的事情

    这个处理没考虑 corner case,比如有两个 key: nm 和 nmok 的场景,pair[/^#{key}/] 就不准确了

    补充一下:

    把 ~~ 替换成 ^^ 可行是因为规则 2 使得 encode 后 value 里的 ~ 必然是双数,规则 3 的连接 ~ 必然是 N 个双数 ~ 的最后一个,除非 id 前会有 ~。

    ^^ 可以换成任何小概率出现在 value 的字符串,比如 ^^^^^^^^^

  • 从实践谈 Ruby 语法上的几个设计不一致带来的问题。 at 2020年11月09日

    if 后缀反思维模式

    后置条件在英文中是常见的句式,只是在中文中可能少见

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