会一点点 CSharp,超喜欢 Ruby。

  • 有一部分人相信换 go 得永生

  • 🚄 换 🚌

  • Twitter 上被 Hey 刷屏了 at 2020年06月24日

    @honglix @lazybios 求码求码

  • 说个思路吧,

    我以前搞过一个, 超级难爬, 实在没法, 换 javascript 写 chrome 插件, run 在 chrome 里.

    打开浏览器,登陆目标网站, call 出插件,显示个 button ,点击,该爬的都爬到了,组织好数据, post 到自己的 api 上.

    done.

    多买几个运营妹子点按钮 😄

  • ruby abc.ruby

  • 敏感词过滤实现 at 2020年05月14日

    贴一个我的吧

    # frozen_string_literal: true
    # DFA 算法实现敏感词扫描
    module Yfxs
      class SensitiveWords
        @@sensitiveMap = Hash.new
        class << SensitiveWords
          def addWord(word)
            nowMap = @@sensitiveMap
    
            for i in 0..word.strip.length - 1
              c = word[i].chr
              if nowMap.has_key? c
                nowMap = nowMap[c]
              else
                child        = Hash.new
                child["end"] = 0
                nowMap[c]    = child
                nowMap       = nowMap[c]
              end
            end
            nowMap["end"] = 1
          end
    
          def initWordMap
    
            return true if @@sensitiveMap.size > 0
    
            stop_words = Setting.stop_words.uniq
            stop_words.each_with_index do |word, index|
              addWord word
            end
            true
          end
    
          def p
            initWordMap
            @@sensitiveMap.size
          end
    
          def scan(word)
    
            initWordMap
    
            word = word.to_s
            words = Array.new
            for i in 0..word.length - 1
              c = word[i]
              if @@sensitiveMap.has_key? c
                theword = "".freeze
                nowMap = @@sensitiveMap
                for j in i..word.length - 1
                  c = word[j]
                  if nowMap.has_key? c
                    theword += c
                    nowMap = nowMap[c]
                    if nowMap['end'] == 1
                      words.push theword
                    end
                  else
                    break
                  end
                end
              end
            end
            return words
          end
        end
      end
    end
    

    在 rails 内写个 自定义的 validates 丢到 concern 用起来更顺手

    # frozen_string_literal: true
    module WithSensitiveWords
      extend ActiveSupport::Concern
      module ClassMethods
        def sensitive_words_safe(*args)
          args.each do |key|
            define_method("#{key.to_s}_without_stopwords") do
              Yfxs::Stopword.safe self[key]
            end
          end
        end
    
        def sensitive_words_validates(*args)
          validates_each args do |record, attr, value|
            # record.errors.add(attr, '包含不允许出现的词语') if Yfxs::SensitiveWords.scan(value).length > 0
            if Yfxs::SensitiveWords.scan(value.to_s).length > 0
              record.errors[:base] << "请不要发布会给我们带来伤害的内容"
              record.errors.add(attr, "包含不允许出现的词语")
            end
          end
        end
      end
    end
    
    # frozen_string_literal: true
    
    module Yfxs
      class Stopword
        def self.safe(text)
          words = SensitiveWords.scan text
          if words.present?
            words.each_with_index do |word, index|
              text = text.gsub(/#{word}/, "***")
            end
          end
          text
        end
      end
    end
    
    # frozen_string_literal: true
    
    class Comment < ApplicationRecord
      include WithSensitiveWords
    
      belongs_to :commentable, polymorphic: true
      belongs_to :user, optional: true
    
      sensitive_words_safe :title
      sensitive_words_validates :body
    end
    
  • Android studio 香!

  • 这是个经典问题了。正向遍历的过程中改变了集合的长度

    一边从桶里舀水出来,一边把桶高锯掉一些。

    这种情况类 for 循环需要倒着遍历,或者用 while … do 这样的循环

  • 过过过儿过过的生活?

会一点点 CSharp,超喜欢 Ruby。