This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class String | |
| #only support number which greater than 1 and less than 100 | |
| def simple_similar_number_to_number | |
| return 2 if self == '两' | |
| ascii_numeric_chars = "0123456789" | |
| utf_numeric_chars = | |
| if self =~ /[[:digit:]]+/ | |
| "\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19" | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.prototype.renameProperty = function (oldName, newName) { | |
| if (this.hasOwnProperty(oldName)) { | |
| this[newName] = this[oldName]; | |
| delete this[oldName]; | |
| } | |
| return this; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Array | |
| def uniq? | |
| hash = {} | |
| self.each do |e| | |
| obj = block_given? ? yield(e) : e | |
| return false if hash[obj] | |
| hash[obj] = obj | |
| end | |
| hash.size == self.size | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Array | |
| def custom_split &block | |
| tmp = self.each_with_index.inject({}) do |hash, (obj, index)| | |
| if block.call(obj) || (index == 0) | |
| hash[index] = [] | |
| else | |
| hash[hash.keys.last] << obj | |
| end | |
| hash | |
| end.map{|h| (h[0] = self[h[0]], h[1]=h[1]).flatten} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def build_courses | |
| subjects = %w{语文 数学 英语 物理 化学 生物 历史 地理 文综 理综} | |
| grades = { | |
| 1 => "七年级", | |
| 2 => "八年级", | |
| 3 => "九年级", | |
| 4 => "十年级" | |
| } | |
| terms = { | |
| 1 => "2013-2014学年", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_support/all' | |
| class Object | |
| def to_json_without_escape | |
| self.to_json.gsub(/\\u([0-9a-z]{4})/){|s| [$1.to_i(16)].pack("U")} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby -run -e httpd . -p 8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ruby code_statistics.rb [<source dir> <test or spec dir>] | |
| class CodeStatistics | |
| def initialize(src, test) | |
| @pairs = [ | |
| ["Codes",src + "/"], | |
| ["Tests",test + "/"] | |
| ].collect { |name, dir| [ name, "#{dir}" ] }.select { |name, dir| File.directory?(dir) } | |
| @statistics = calculate_statistics | |
| @total = calculate_total if @pairs.length > 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /(?:X(?:X(?:V(?:I(?:I?I)?)?|X(?:I(?:I?I)?)?|I(?:[VX]|I?I)?)?|V(?:I(?:I?I)?)?|I(?:[VX]|I?I)?)?|V(?:I(?:I?I)?)?|I(?:[VX]|I?I)?)/.match "-----IV----" | |
| #<MatchData "IV"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "dsdsd1.xsds\ndsdsd\n2.dsds6dsd".split(/(?=\d\.(?!\d\.).+)/) | |
| #["dsdsd", "1.xsds\ndsdsd\n", "2.dsds6dsd"] | |
| #"ds32sdsd22.xsds\nd6sdsd\n11.dsds6dsd".split(/(?=[\d]{1,2}\.(?![\d]\.).+)/) | |
| #(?=[\n\s]+[\d]+[\.](?![\d]{1,2}[\.]).+) | |
| #aaaaa\n 1.--------\n\n 32.------\n\n 3.-----2.7+8。9----2\n 24.--- |