Last active
December 14, 2015 10:09
-
-
Save upsuper/5069549 to your computer and use it in GitHub Desktop.
Counting non-printable characters in .js and .css files.
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 FileInfo | |
| def initialize(name, data) | |
| @name = name | |
| @length = data.length | |
| @space = data.each_char.inject(0) { |n, c| | |
| n += case c | |
| when '\t' then 8 | |
| when /\s/ then 1 | |
| else 0 | |
| end | |
| } | |
| end | |
| attr_reader :name, :length, :space | |
| def rate | |
| (space / length.to_f * 10000).round / 100.0 | |
| end | |
| end | |
| Dir.entries('.').map{ |filename| | |
| if ['.js', '.css'].include?(File.extname(filename)) | |
| data = File.read(filename) | |
| FileInfo.new(filename, data) | |
| end | |
| }.select{ |obj| obj and obj.length >= 100 }.sort{ |x, y| | |
| x.rate <=> y.rate | |
| }.each do |file| | |
| puts "#{file.name.ljust(20)}#{file.length.to_s.rjust(8)}" + | |
| "#{file.space.to_s.rjust(8)}\t#{file.rate}%" | |
| 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
| steelseries-min.js 222018 2217 1.0% | |
| bootstrap.min.js 3880 48 1.24% | |
| jquery-1.9.1.min.js 92629 1212 1.31% | |
| jquery-1.6.1.min.js 91342 1331 1.46% | |
| jquery-1.4.2.min.js 72174 1222 1.69% | |
| bootstrap.min.css 50517 2451 4.85% | |
| dude.js 15 1 6.67% | |
| hello.js 61 7 11.48% | |
| empty.js 30 4 13.33% | |
| http.js 50085 11376 22.71% | |
| classes.js 1488 340 22.85% | |
| classes-old.js 1348 308 22.85% | |
| json2_backbone.js 45618 10529 23.08% | |
| jquery-1.6.1.js 234995 57258 24.37% | |
| jquery-1.7.2.js 252881 61939 24.49% | |
| bootstrap-modal.js 5677 1413 24.89% | |
| style.css 917 231 25.19% | |
| intro.js 890 242 27.19% | |
| intro-old.js 880 242 27.5% | |
| modernizr.js 47402 13351 28.17% | |
| app.js 3319 1338 40.31% | |
| uglify.js 52665 22177 42.11% | |
| parser.js 80634 38364 47.58% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment