Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
@gihnius
会员
第 6061 位会员 / 2013-03-10

广州
31 篇帖子 / 335 条回帖
5 关注者
0 正在关注
52 收藏
GitHub Public Repos
  • jquery.qeditor 35

    This is a simple WYSIWYG editor with jQuery.

  • http-pinger 20

    A simple tool to check website status and notify via email.

  • cl-common-blog 18

    a blog engine written in common lisp

  • gomemoize 11

    memoization function in Go

  • hunchentoot-secure-cookie 9

    encodes and decodes authenticated and optionally encrypted cookie values.

  • freebsd-wifi 7

  • ht-routes 7

    route mapping and dispatching URL's for Hunchentoot in Common Lisp.

  • gosanitize 6

    Gosanitize is a whitelist-based HTML sanitizer in Go language. Given a list of acceptable element...

  • rdb-backup 5

    redis rdb backup

  • redis_online_counter 5

    Counting online users with Redis and Go.

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [技术交流] 基于 Elixir-GraphQL-React 的新一代社区系统设计雏形 at 2019年01月27日

    👍 👍

  • 记录编辑完成后如何跳转到之前的 index 页? at 2018年06月02日

    没找到什么好办法,目前是通过 session 保存 referrer 来实现。

    # application_controller
    before_action do
      session[:return_to] = request.referrer
    end
    
    # action
    def update
      #...
      redirect_to (session[:return_to] || other_path) 
    end
    

    大致思路这样,实际使用还要其他额外处理

  • 这样的代码如何改的更符合 Ruby 哲学? at 2018年05月31日

    这样还好啦其实,你看看像 Go 没有单行 if 那代码简直了!

  • 请教一个 each_with_object / inject /tap 相关 更优雅的写法 at 2018年05月18日

    真要为了优雅不计成本了呀?!

    本来一次循环搞定的事要不要这么费劲?

    str_arr = []
    str = ''
    arr.each {|e| str == '' ? str = "#{e}" : str = "#{str}/#{e}"; str_arr << str }
    
  • 一个要把路由拆了的小轮子 at 2018年05月17日

    估计迟到会有 app/routes/ 或 config/routes/ 目录 😀 😀

  • 感觉 UI 风格比以前好看了耶 at 2018年04月19日

    黑化了。。。😎

  • 是不是 HTTPS 自带类似 Gzip 的网页压缩功能? at 2018年04月01日

    SSL 加密自带压缩,你用 gpg/openssl 加密一个文件,再 gzip 基本没有效果,小文件还会变大。

    不加 accept-encoding 默认不会返回 gzip 给客户端的。

  • Ruby 里为什么要有 unless? at 2018年03月27日

    Lisp 下还有 when 不需要 else 的 if

  • Ruby 里为什么要有 unless? at 2018年03月27日

    这段翻译错了:

      dolist (obj *neurons_list*)
      unless weights_comprehensive_regulation(obj) == 0
        modify_weights_module (neurons_name obj)(weights_comprehensive_regulation obj )
      end
    
    # =>
    neurons_list.each do |obj|
      unless obj.weights_comprehensive_regulation == 0
        modify_weights(obj.neurons_name, obj.weights_comprehensive_regulation)
      end
    end
    
    

    无聊一下:)

  • 强迫症又犯了,rails generate model 怎么生成 4 空格缩进的文件? at 2018年03月24日

    其实最好还是用 Tab,然后把 Tab Width 设置成自己想要的

  • ActionView 的組件有安全問題,請趕快更新 rails-html-sanitizer,並確定是否已經是 1.0.4 或以上 at 2018年03月23日

    ActionView 依赖的,估计都得中枪!

  • 服务器负载过高怎样优化? at 2018年03月08日

    你这负载一点不算高吧!

    可以参考一下: https://ruby-china.org/topics/34695#reply-339046

  • 如何用 Ruby 写一个图片上传到服务器的方法 at 2018年02月28日

    :

    #!/usr/bin/env ruby
    
    require 'webrick'
    include WEBrick
    
    class FileUploadServlet < HTTPServlet::AbstractServlet
      def do_POST(req, res)
        filedata = req.query["file"]
        filename = filedata.filename
        file = File.open(filename, "wb")
        file.syswrite filedata
        file.close
        res.body = "uploaded file: #{filename}"
      end
    end
    dir = Dir.pwd
    svr = HTTPServer.new(Port: ARGV[0] || 3000, DocumentRoot: dir)
    svr.mount('/', HTTPServlet::FileHandler, dir, FancyIndexing: true)
    svr.mount("/upload", FileUploadServlet)
    
    trap("INT") { svr.shutdown }
    svr.start
    

    测试:curl -F "file=@/tmp/meimei.png" http://127.0.0.1:3000/upload

  • 迭代中能否设计成不要双竖线? at 2018年02月27日

    回头看好像有戏,只要在 C 层面实现 each_as(:name)

  • 如何在任何 model 中获取 Devise 的 current_user 信息? at 2018年02月26日

    最好不这样做,但一定要的话 参考 https://github.com/steveklabnik/request_store

  • 迭代中能否设计成不要双竖线? at 2018年02月25日

    之前也想过,还企图解决一下,不过代价有点高!

    这是以前的代码:

    class Array
      def each_as(name, &block)
        define_singleton_method(name) do
          instance_variable_get("@__#{name}")
        end
    
        define_singleton_method("#{name}=") do |value|
          instance_variable_set("@__#{name}", value)
        end
    
        each do |elem|
          send("#{name}=", elem)
          instance_exec(&block)
        end
      end
    end
    
    a = [1,2,3,4,5]
    a.each_as(:x) { puts x }
    
    a.each_as(:int) do
      puts int * 2
    end
    
    

    配置编辑器有自动补全,用 || 问题不大。

  • 请教如何实现一个 Model 的修改需要 Admin 审核通过才能生效? at 2018年01月30日

    可以参考一下: https://github.com/collectiveidea/audited 加上状态控制

  • 使用 Ruby FFI 调用 Go 函数:十倍效率提升 at 2018年01月22日

    Go 很好,Go 很吊,但还是准备去玩 crystal,因为写 Go 会手抽筋!

    crystal 类似 ruby 的语法,写起来爽快,况且现在支持静态编译了 crystal build src/app.cr --release --link-flags -static 跟 Go 一样编译成无依赖单文件。

  • Rails 操作数据库如何用代码判断数据库是否连接上 at 2018年01月17日

    这样不影响启动吧?

  • Rails 操作数据库如何用代码判断数据库是否连接上 at 2018年01月17日

    本来就不会有影响呀,你怎么配置的?

    多个数据库,除了默认的,其他你要手工连接 establish_connection DB_CONFIG ,怎么会影响启动呢?

  • Rails 操作数据库如何用代码判断数据库是否连接上 at 2018年01月17日

    ActiveRecord::Base.connection.active?

  • Ruby 2.5.0 已发布 at 2017年12月31日

    从 2.4.0 升到 2.5.0 看到这个报错。

    例子 https://mensfeld.pl/2017/12/ruby-2-5-0-upgrade-remarks/

    好像旧的有些版本会有报错,有些没有报,奇怪。

  • Ruby 2.5.0 已发布 at 2017年12月28日

    我不这样写,但问题是之前的版本没有报错,现在 2.5.0 报错。

  • Ruby 2.5.0 已发布 at 2017年12月26日

    升级然后跑崩了,多个 gem 有此问题,这个没办法接受:

    $ irb
    irb(main):001:0> def m(arg, &block)
    irb(main):002:1>   pp arg
    irb(main):003:1>   block.call
    irb(main):004:1> end
    => :m
    irb(main):005:0> m(100) { puts "block" }
    100
    block
    => nil
    irb(main):006:0> m 100 { puts "block" }
    Traceback (most recent call last):
            1: from /home/ruby/.rbenv/versions/2.5.0/bin/irb:11:in `<main>'
    SyntaxError ((irb):6: syntax error, unexpected '{', expecting end-of-input
    m 100 { puts "block" }
          ^)
    irb(main):007:0>
    

    以前很多代码都是这样写的! method arg { block }

    其实严谨些是这样的写法好。method(arg) { block }

  • 才知道自己原来又蠢又不要脸 at 2017年12月13日

    妄下结论的都是耍流氓

  • 看完离编写高性能的 JavaScript 又近了一步 at 2017年12月13日

    高了

  • . at 2017年12月13日

    是招 ruby 的吗?

  • Ruby on Rails 开发的 API,能支撑多大的日请求量? at 2017年12月13日

    @small_fish__ @atlas 看更新

  • Ruby on Rails 开发的 API,能支撑多大的日请求量? at 2017年12月12日

    阿里云 4 core 8G, puma 4 workers 8 threads, 约 2100 rpm, 50-1000 ms/r avg 200ms, 每次请求都读写数据库的 api, cpu 几乎保持 80% 以上,load 都 4.x 以上。数据库不在同一台机。

    newrelic 的数据,再优化一下,单机 50rps 以上应该问题不大。看需求做横向扩容,比如单机做到 50 rps,目标是 1000rps,那堆 20 台服务器呗。


    补充一下,cpu 占有高跟业务有关,计算型的。另外还有几个 Sidekiq 在跑。可能阿里云的 cpu 配置也不高,在本地测试没这么高占用率。

    大致系统是这样的:

    [物联网设备] ---- [ Go 中心处理系统 ] --- [ Rails 业务系统 ]

    Go 处理着几千长连接,占用的资源非常少,简单处理后转发到 Rails 业务系统。

    Go htop:

    Rails puma top:

  • 用 action-cable asset/js/ 里面的 coffee 接受不到 data 更新:已经找到问题所在,求大佬解答 at 2017年11月24日

    那问题不很明确吗?你给出 view 的代码看看呗,可能调用了 Devise 或者 Request 相关的东西, 你就拿 renderer 那句去 debug 就行啦

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