Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
larrylv
@larrylv
高级会员
第 79 位会员 / 2011-11-14

7 篇帖子 / 161 条回帖
19 关注者
0 正在关注
50 收藏
Engineering at @stripe
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [北京] Airbnb 中国 招聘 full stack engineer/mobile engineer (长期有效, 2018 已更新) at 2018年01月06日

    好奇 Airbnb 会 sponsor L1 吗?

  • Ruby 中 each.do 集合遍历问题 at 2017年07月04日
    %w(cat dog wombat).each.with_index.inject({}) do |h, (item, index)|
      h[item] = index
      h
    end
    
  • 新手請教關於端口問題 at 2017年06月29日
    $ bundle exec rails server -h
    Usage: rails server [mongrel, thin, etc] [options]
        -p, --port=port                  Runs Rails on the specified port.
                                         Default: 3000
        -b, --binding=ip                 Binds Rails to the specified ip.
                                         Default: 0.0.0.0
        -c, --config=file                Use custom rackup configuration file
        -d, --daemon                     Make server run as a Daemon.
        -u, --debugger                   Enable ruby-debugging for the server.
        -e, --environment=name           Specifies the environment to run this server under (test/development/production).
                                         Default: development
        -P, --pid=pid                    Specifies the PID file.
                                         Default: tmp/pids/server.pid
    
        -h, --help                       Show this help message.
    

    如果是 80 的话,要 sudo.

  • Vim Surround 为啥我每次按 s 的时候就变成插入模式了. at 2017年04月18日

    viwS

  • 使用 Ruby 的大伙,你们常用的其他程序语言是什么? at 2017年03月28日

    Clojure

  • 请问为什么 accepts_nested_attributes_for 在 Rails 5.0.0.1 下不能创建新的关联对象了? at 2016年12月21日

    @GuiZi 是这个 PR 引入的 bug https://github.com/rails/rails/pull/18937

    From changelog:

    belongs_to will now trigger a validation error by default if the association is not present. You can turn this off on a per-association basis with optional: true.

    但是没有考虑你的这种情况,所以会报 validation error.

  • 请问为什么 accepts_nested_attributes_for 在 Rails 5.0.0.1 下不能创建新的关联对象了? at 2016年12月20日

    https://github.com/rails/rails/issues/25198

  • 如何做到 MySQL 未启动,Rails 应用启动不报连接 MySQL 错误? at 2016年11月26日

    我觉得应该做的是 MySQL 还没有启动前,不应该启动 Rails.

    #!/bin/bash
    function is_db_up {
      nc -z -w5 MYSQL_IP MYSQL_PORT
    }
    
    echo -n "Waiting for db to be up..."
    until is_db_up ; do
      printf '.'
      sleep 1
    done
    echo done\!
    
    # start rails application
    
  • 学技术练英语 at 2016年07月07日

    Reddit 找技术相关板块,Hacker News 看文章,Youtube 看各种技术 talk,Couserea、Khan、Udacity 跟课程。

  • array.flatten 怎么实现的 at 2016年05月24日

    是完整的,重点是这行:result = flatten(ary, level, &mod);

    flatten 方法的完整定义在这里 https://github.com/ruby/ruby/blob/eb15df1f894fa7235ccbcda7661f7d6a052045f6/array.c#L4508-L4564

    static VALUE
    flatten(VALUE ary, int level, int *modified)
    {
        long i = 0;
        VALUE stack, result, tmp, elt;
        st_table *memo;
        st_data_t id;
    
        stack = ary_new(0, ARY_DEFAULT_SIZE);
        result = ary_new(0, RARRAY_LEN(ary));
        memo = st_init_numtable();
        st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
        *modified = 0;
    
        while (1) {
        while (i < RARRAY_LEN(ary)) {
            elt = RARRAY_AREF(ary, i++);
            if (level >= 0 && RARRAY_LEN(stack) / 2 >= level) {
            rb_ary_push(result, elt);
            continue;
            }
            tmp = rb_check_array_type(elt);
            if (RBASIC(result)->klass) {
            rb_raise(rb_eRuntimeError, "flatten reentered");
            }
            if (NIL_P(tmp)) {
            rb_ary_push(result, elt);
            }
            else {
            *modified = 1;
            id = (st_data_t)tmp;
            if (st_lookup(memo, id, 0)) {
                st_free_table(memo);
                rb_raise(rb_eArgError, "tried to flatten recursive array");
            }
            st_insert(memo, id, (st_data_t)Qtrue);
            rb_ary_push(stack, ary);
            rb_ary_push(stack, LONG2NUM(i));
            ary = tmp;
            i = 0;
            }
        }
        if (RARRAY_LEN(stack) == 0) {
            break;
        }
        id = (st_data_t)ary;
        st_delete(memo, &id, 0);
        tmp = rb_ary_pop(stack);
        i = NUM2LONG(tmp);
        ary = rb_ary_pop(stack);
        }
    
        st_free_table(memo);
    
        RBASIC_SET_CLASS(result, rb_class_of(ary));
        return result;
    }
    
  • Grape API params { requires :token } 无法验证在 headers 中的 token 参数 at 2015年12月15日

    #10 楼 @rei 如果是 http basic authentication 或者是 oauth2, 可以用 Grape 内置好的。自己写 middleware 有些得不偿失,不如放在 before_validation 里面方便。

  • Grape API params { requires :token } 无法验证在 headers 中的 token 参数 at 2015年12月15日

    #8 楼 @qinix 这个是 description, 不会做 validation.

  • Grape API params { requires :token } 无法验证在 headers 中的 token 参数 at 2015年12月14日

    可以在 before_validation 里判断 https://github.com/ruby-grape/grape#before-and-after

    before_validation do
      error! "Token not found in header", 400 if headers["token"].blank?
    end
    
  • zsh_stats 查看你命令使用频率 at 2015年08月01日
    $ zsh_stats
         1  25960  31.9996%     git
         2  6960   8.57925%     ll
         3  5795   7.14321%     vim
         4  3757   4.63107%     cd
         5  2813   3.46745%     ls
         6  2248   2.771%       tigs
         7  2141   2.6391%      tig
         8  1745   2.15098%     rake
         9  1493   1.84035%     rails
        10  1286   1.58519%     j
        11  1285   1.58396%     ssh
        12  1226   1.51123%     ag
        13  1174   1.44713%     rm
        14  1155   1.42371%     brew
        15  1121   1.3818%      cap
        16  1104   1.36085%     l
        17  824    1.0157%      bi
        18  798    0.983655%    bundle
        19  781    0.9627%      tmux
        20  756    0.931884%    ping
    
  • ransack 和 scope 搭配使用方法求教 at 2015年04月28日

    @zouchaoge try Order.ransack({ :express_status => 0 }) ?

  • 如何深入学习 Rails at 2015年04月21日

    Owning Rails

  • 做个调查,大家对窗口管理工具有需求吗? at 2015年02月06日

    Moom

  • 八卦 Thoughtbot 这个公司谁介绍下? at 2015年02月04日

    #4 楼 @yukihiro_matz 对,按照规范来即可。

  • vim 命令行中能否运行 rails 命令啊? at 2015年02月03日

    Vim also allows you to execute a command directly from the editor, without needing to drop to a shell, by using bang (!) followed by the command to be run. For instance, if you're editing a file in Vim and want to find out how many words are in the file, run :! wc %

    google key word: vim run external command

  • git svn 遇到一个让人抓狂的坑, at 2015年02月01日

    #4 楼 @mogodb 文章第一步写了:

    Define the new branch in .git/config

    手动添加即可。

  • git svn 遇到一个让人抓狂的坑, at 2015年02月01日

    #2 楼 @mogodb 提示的很清楚了。git clone 下来的仓库没有对应的 svn 仓库的信息。

    http://ivanz.com/2009/01/15/selective-import-of-svn-branches-into-a-gitgit-svn-repository/

  • iTunes 上的斯坦福课程--用 Swift 开发 iOS8 应用 at 2015年01月28日

    #2 楼 @hanluner 有英文字幕。

  • 新手问题,大家看看什么情况 at 2015年01月26日

    try gem update --system first.

  • ruby-china 的存储依赖怎么那么多? at 2015年01月21日

    推荐一个适合新手学习的 codebase: https://github.com/qrush/skyway

  • Global Variables in Rails at 2014年12月26日

    #10 楼 @luikore 如果放在 request.env 里,那跟把这些写到 ApplicationController 里,搞个 memoize 的方法存下来,没什么区别啊?而且把业务逻辑结果放在了它该存在的地方,而不是 request.env ...

    warden 放在 request.env 里是为了 rack app 间的数据通信吧,warden 为了让下一层的 rack app 使用到,当然需要这么做没错,但这不代表我最后一层的 rack app 还要这么做啊。我同一层的数据共享为什么非要用到 request.env 呢...

    其实说起 Global Variables 以及写这篇 blog, 主要是因为在复杂的应用中现在的 Thread.current[] 实现方式对于管理来说很困难,所以才会想说起 PerThreadRegistry 这个 module. 而实现在 request.env 里还是没有解决到这个痛点(对于我来讲是痛点,:) ),所以我还是认为使用 request.env 是个 bad idea.

  • Global Variables in Rails at 2014年12月26日

    #8 楼 @luikore 所以就应该把所有的东西都扔到一个巨大的 hash 里吗?我不太能认同。 即使是 request 范围内的,request.env 也只是放了真正的请求信息,而不是这个请求的逻辑结果从而用来传递数据,不然为什么叫 request.env 而不是 request.data ...

    这也是 ActiveSupport::PerThreadRegistry 试图解决的问题,更好的管理逻辑相关的 global 信息。

  • Global Variables in Rails at 2014年12月26日

    #6 楼 @luikore 恩。我在最开始时说了,为了不用为每个方法都传个参数,这才是 Global Variable 的意义嘛。 不过 model 层大部分情况不需要这点我同意。

    另外,个人觉得,request.env 这个东西还是不要污染的好。如果因为 request_store 的实现不好就去选择另外一种不好的实现,似乎不太准确。毕竟 request.env 不是为了让用户去放 global variables 的。

  • Global Variables in Rails at 2014年12月26日

    #4 楼 @luikore model 层不能取到 request.env 吧。

  • Global Variables in Rails at 2014年12月26日

    #2 楼 @luikore :-) thin 那个是直接 copy 的 request_store 的 README. 我改一下吧。

    是说放在 request.env 里?这样不太好吧...

  • 使用 vi 写 rails 的朋友怎么有什么好的配色方案吗? at 2014年11月28日

    solarized

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