Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
吕成鹏
@onemagicant
会员
第 5597 位会员 / 2013-02-04

杭州
3 篇帖子 / 84 条回帖
8 关注者
5 正在关注
5 收藏
铁板烧的日子
GitHub Public Repos
  • parse-server-jobs-sche... 2

  • GB2260.rs 1

    The Rust implementation for looking up the Chinese administrative divisions.

  • chinese_pinyin 1

  • dota2_api 1

  • wxapp_phoenix_websocke... 1

    Phoenix Framework Websocket Client For WeChat App

  • helm-charts 0

  • kendra-video-to-audio 0

    Split video into audios

  • ngx-drag-drop 0

    Angular directives using the native HTML Drag And Drop API

  • nginx-ebpf-trace 0

  • trojan-manager 0

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 为 Rails 项目升级使用 ElasticSearch 5.x 版本 at 2017年11月06日

    https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl

    写个更漂亮更好维护的 query.

  • 利用快照来测试 Controller 和 View at 2016年09月06日
    it 'should work' do
      @replies = create_list(:reply, 3, user: user, topic: topic)
      get "/api/v3/users/#{user.login}/replies.json", offset: 0, limit: 2
      expect(json['replies'].size).to eq 2
      fields = %w(id user body_html topic_id topic_title)
      expect(json['replies'][0]).to include(*fields)
      expect(json['replies'][0]['id']).to eq @replies[2].id
      expect(json['replies'][0]['topic_title']).to eq topic.title
      expect(json['replies'][1]['id']).to eq @replies[1].id
    
     expect(response.body).to match_snapshot('users/:login/replies') # 其他信息快照记录
    end
    

    @hz_qiuyuanxin

  • 利用快照来测试 Controller 和 View at 2016年09月05日

    @hz_qiuyuanxin 测试更多的时候是希望及时的发现错误和潜在的错误

  • ActiveRecord 和 Ecto 的联系与对立 at 2016年07月25日
    module MysqlConnection
      extend ActiveSupport::Concern
    
      included do
        establish_connection ActiveRecord::Base.configurations[Rails.env]["xxx"]
      end
    
      # 如果是只读的话
      def readonly?
        true
      end
    end
    
    class ModelName < ActiveRecord::Base
      include MysqlConnection
    end
    
    default: &default
      adapter: postgresql
      encoding: unicode
      pool: 5
    
      xxx:
        adapter: mysql2
        pool: 5
        timeout: 5000
        database:  xxxx
        username: root
        host: 123.123.123.123
        password: xxxxx
    
    development: &development
      <<: *default
      database: xxxxxxx
    
  • 存在内存泄露的 Gem 列表 at 2016年03月02日

    ruby-pinyin <= 0.4.8

  • Grape + Serializer,如何在 JSON 输出中增加 current_user 这样的变量? at 2015年10月15日

    #3 楼 @xlaok https://github.com/jrhe/grape-active_model_serializers/blob/master/lib%2Fgrape-active_model_serializers%2Fendpoint_extension.rb#L27

    但是我还是建议你不要使用这样的插件,可以直接使用active_model_serializers, 你的这个问题可以https://github.com/rails-api/active_model_serializers/blob/master/lib%2Factive_model%2Fserializer.rb#L148

    可以直接出入参数的方式将 current_user 传入,像 @martin 所说. 调用的方式就是 如:https://github.com/rails-api/active_model_serializers#using-a-serializer-without-render
    ActiveModel::SerializableResource.new(@message, scope: current_user).serializable_hash

  • Grape + Serializer,如何在 JSON 输出中增加 current_user 这样的变量? at 2015年10月14日

    active_model_serializers 默认会将 current_user 方法传入

    def is_viewed
       scope.is_viewed
    end
    

    如果你想将其他方法传入,https://github.com/rails-api/active_model_serializers/tree/0-9-2#customizing-scope

  • [杭州] [C 轮] 大搜车招聘 Ruby 工程师 2 名. 税后 10 - 20K , 期权以及其他 at 2015年07月28日

    #7 楼 @42thcoder 离职后一段时间我发现确实之前有些地方是不对,不过很想听听你说的坑在哪里,这也有助于我的成长,谢谢。

  • [杭州] [C 轮] 大搜车招聘 Ruby 工程师 2 名. 税后 10 - 20K , 期权以及其他 at 2015年07月28日

    #7 楼 @42thcoder 吐槽来听听呢

  • [杭州] [C 轮] 大搜车招聘 Ruby 工程师 2 名. 税后 10 - 20K , 期权以及其他 at 2015年07月28日

    拍卖... 话说健身房会有游泳池吗。

  • Rails ActiveRecord 如何获取 Mysql column comment? at 2015年07月17日

    其实还是 sql,
    偷懒的话呢,就用 migration_comments, 这个 gem 写了 adapter,

    这样调用就可以了

    klass = User
    column_comments = klass.connection.retrieve_column_comments(klass.table_name)
    

    返回是 字段 => 解释 的 hash

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月18日

    @rubyu2 先给你点个赞,存业务需要的两个时间戳, post_id 这个怎么算的

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月17日
    require "benchmark"
    require "redis"
    
    class MemoryWatcher
      def self.measure(no_gc = true, current_redis, &block)
        current_redis.flushdb
        no_gc ? GC.disable : GC.start
        memory_before = current_memory
        gc_before = GC.stat
    
        info_before = MemoryWatcher.redis_info(current_redis)
        time = Benchmark.realtime { yield(current_redis) }
        info_after  = MemoryWatcher.redis_info(current_redis)
    
        gc_after = GC.stat
        GC.start unless no_gc
        memory_after = current_memory
    
        puts <<-INFOS
          gc: #{no_gc ? "关闭" : "开启"}
          time: #{time}
          gc_count: #{gc_after[:count] - gc_before[:count]}
          memory: #{(memory_after - memory_before).round(2)}M
          redis used_memory: #{info_after['used_memory'].to_i - info_before['used_memory'].to_i}
        INFOS
        current_redis.flushdb
      end
    
      def self.current_memory
        `ps -o rss= -p #{Process.pid}`.to_i/1024
      end
    
      def self.redis_info(current_redis)
        current_redis.info
      end
    end
    
    # 用户IDs 100_000_000..110_000_000
    # 动态IDs 1_000_000..1_100_000
    # 时间戳做 分值
    user_ids = (100_000_000..100_001_000).to_a
    post_ids = (100_000_000..100_000_100).to_a
    timestamps = Time.now.to_i # 写死
    
    current_redis = Redis.current
    
    MemoryWatcher.measure(current_redis) do |redis|  
      redis.pipelined do
        user_ids.each do |user_id|
          post_ids.each do |post_id|
            redis.ZADD "#{user_id}/#{post_id}", timestamps, timestamps
          end
        end
      end
    end
    
    p '-' * 60
    
    # 假定每个大v发一个 文章
    v_ids = post_ids
    
    MemoryWatcher.measure(current_redis) do |redis|
      redis.pipelined do
        # 不计算其他存储消耗, 因为这里没有存业务需要的两个时间戳, post_id
        user_ids.each do |user_id|
          v_ids.each do |v_id|
            redis.SETBIT v_id, user_id, 1
          end
        end
      end
    end
    
    

    我测出来,随着 id 的增大,setbit 会耗时变久,setbit 会超出值的范围. redis 内存使用 后者比前者多很多 喷喷看哪里有问题,谢谢

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月16日

    恩,存时间戳是更耗内存,不过如何解决 redis 收集大量内存处理 setbit 大 offset 情况?会不会堵塞?

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月16日

    #19 楼 @rubyu2 走数据库的话,20ms 好不啦

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月16日

    #19 楼 @rubyu2 不是耗时间的问题啊,第一次的时候需要消耗的内存随着 offset 的增大,会变大

  • Redis 实战之薄荷 timeline 的优化 at 2015年06月16日

    #13 楼 @rubyu2 offset 大的时候,第一次内存分配有点多,用户 id 自增话,意味着 offset 也越大。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月08日

    求小伙伴一起啪啪啪....

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月08日

    #25 楼 @jmmbite 不知道嘞,我用 emacs 的,基本不用改....没折腾过....

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月08日

    #20 楼 @kgen 我看到你的 推文 了。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月08日

    #22 楼 @jmmbite 还不错吧,你喜欢就好了

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月07日

    #13 楼 @nightire @yesmeck 这个人的键盘声音特别大,啪啪啪啪,我得搞个大点的。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月07日

    你们为什么不早点来,我都发货了.........

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    #7 楼 @jmmbite 我旺旺上面叫你了,你看下图片,我发给你的就是这个机器,我晚上擦过了。看下你的收货地址对不对,旺旺上面确认下吧。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    #9 楼 @peter 不会的啊....

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    #7 楼 @jmmbite 明天发货给你哈。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    #5 楼 @jmmbite 好吧,你拍吧 楼上 @yesmeck 人头担保。

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    http://2.taobao.com/item.htm?id=45283812690&grade=7.0

  • 出 HHKB pro2 - Type-S 一个 at 2015年05月06日

    #2 楼 @jmmbite 杭州哪里的,我可以当面验货

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