run 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf851cac620a98015d1614ba428a5e1e61359a2c02d399ec7fee30dd92a98bb4
4
+ data.tar.gz: e0c9dfbcd1fa6895453353f5d697a5848e6700effd29e142e707fb237453647b
5
+ SHA512:
6
+ metadata.gz: 2c10ee5c526ac5f1532d7100519781baae268c5b46ac91364b174b7ccba6c561fb396773f04f60399ad0e9935d1ae426d0ca92e553d6e1e1d71ccec1ac95002b
7
+ data.tar.gz: 9604a07c3628c2c13def7763dceeb466a1f324e2e288de3645ac861a1e9933824428ef192721c13a82882c69105bd13ba71c341e9ae62e50cd8ca297f84ab963
data/.gitignore ADDED
@@ -0,0 +1,53 @@
1
+ *
2
+ !/**/
3
+ !?*.*
4
+
5
+ # directories
6
+ .bundle/
7
+ _yardoc/
8
+ coverage/
9
+ doc/
10
+ pkg/
11
+ spec/reports/
12
+ tmp/
13
+ vendor/
14
+
15
+ # files
16
+ *.dump
17
+ *.log
18
+ *.mod
19
+ *.o
20
+ *.swp
21
+ *~
22
+ .DS_Store
23
+ .idea
24
+ .project
25
+ .rake*
26
+ .rake*
27
+ .ruby-*
28
+ .rvmrc
29
+ .secret
30
+ .yardoc
31
+ TODO.md
32
+ core.*
33
+ cscope.out
34
+ secrets.yml
35
+ tags
36
+
37
+ # don't ignore
38
+ !.gitignore
39
+ !Capfile
40
+ !Cheffile
41
+ !Gemfile
42
+ ![MR]akefile
43
+ !bin/**/*
44
+ !exe/**/*
45
+
46
+ /.bundle/
47
+ /.yardoc
48
+ /_yardoc/
49
+ /coverage/
50
+ /doc/
51
+ /pkg/
52
+ /spec/reports/
53
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ Layout/CommentIndentation:
2
+ Enabled: false
3
+
4
+ Layout/LeadingCommentSpace:
5
+ Enabled: false
6
+
7
+ Layout/SpaceAroundOperators:
8
+ Enabled: false
9
+
10
+ Layout/SpaceAfterComma:
11
+ Enabled: false
12
+
13
+ Layout/SpaceInsideBlockBraces:
14
+ Enabled: false
15
+
16
+ Naming/MethodParameterName:
17
+ Enabled: false
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
24
+
25
+ Style/FormatStringToken:
26
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in run.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ run (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ benchmark-ips (2.7.2)
11
+ builder (3.2.4)
12
+ byebug (11.0.1)
13
+ hpricot (0.8.6)
14
+ minitest (5.13.0)
15
+ minitest-reporters (1.3.8)
16
+ ansi
17
+ builder
18
+ minitest (>= 5.0)
19
+ ruby-progressbar
20
+ mustache (1.1.0)
21
+ rake (10.5.0)
22
+ rdiscount (2.2.0.1)
23
+ ronn (0.7.3)
24
+ hpricot (>= 0.8.2)
25
+ mustache (>= 0.7.0)
26
+ rdiscount (>= 1.5.8)
27
+ ruby-prof (1.0.0)
28
+ ruby-progressbar (1.10.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ benchmark-ips
35
+ bundler (~> 2.0)
36
+ byebug (~> 11.0.1)
37
+ minitest (~> 5.0)
38
+ minitest-reporters (~> 1.3.8)
39
+ rake (~> 10.0)
40
+ ronn (~> 0.7)
41
+ ruby-prof
42
+ run!
43
+
44
+ BUNDLED WITH
45
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 sergioro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Run
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/run`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'run'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install run
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/run.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'fileutils'
5
+
6
+ CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
7
+
8
+ task default: %i[test package]
9
+ task package: :clean
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << 'lib' << 'test'
13
+ t.test_files = FileList['test/**/*_test.rb']
14
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "run"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/run ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "run"
4
+
5
+ Run.race(ARGV)
data/lib/run.rb ADDED
@@ -0,0 +1,131 @@
1
+ require 'run/version'
2
+ require 'byebug'
3
+ require 'yaml'
4
+
5
+ class RunError < StandardError; end
6
+
7
+ module Run
8
+ extend self
9
+
10
+ def race(args)
11
+ help if !(args & %w[-h --help]).empty?
12
+
13
+ parse_options(args) unless args.empty?
14
+
15
+ trap('INT') { bye }
16
+ trap('TERM') { bye }
17
+
18
+ @eof=0x04
19
+ @max_length||=4000
20
+
21
+ if quotes.empty?
22
+ puts "No quotes with less than #{@max_length} characters found"
23
+ exit
24
+ end
25
+
26
+ @text=quotes[rand(quotes.size)]
27
+
28
+ @color="\e[4;32m"
29
+ @no_color="\e[m"
30
+
31
+ @pos=0
32
+ max_pos=text.size
33
+
34
+ # average English word length
35
+ @word_length=5
36
+
37
+ @start_time=time
38
+ print_text
39
+
40
+ loop do
41
+ update_text
42
+ break if pos==max_pos
43
+ end
44
+
45
+ puts "\nWPM: #{wpm}"
46
+ end
47
+
48
+ def help
49
+ puts <<~eof
50
+ Usage: run
51
+
52
+ Options:
53
+ -h: show this message
54
+ -s: print stats
55
+ -l: message length [1: short, 2: medium, 3: long]
56
+ -q: print quotes.yml path
57
+ eof
58
+ exit
59
+ end
60
+
61
+ def parse_options(args)
62
+ if args.first=='-s'
63
+ stats
64
+ end
65
+
66
+ if args.first=='-q'
67
+ puts quotes_file
68
+ exit
69
+ end
70
+
71
+ if args.shift=='-l' and args.first.to_i > 0
72
+ @max_length=args.first.to_i
73
+ return
74
+ end
75
+
76
+ puts "Unknown option"
77
+ bye
78
+ rescue => e
79
+ "Bad options. For help: `run -h`"
80
+ end
81
+
82
+ def stats
83
+ bye
84
+ end
85
+
86
+ def time
87
+ Time.now.to_i
88
+ end
89
+
90
+ def wpm
91
+ text.size*60/((time-@start_time)*@word_length)
92
+ end
93
+
94
+ def quotes
95
+ YAML.load(open(quotes_file))
96
+ .sort_by(&:length)
97
+ .select {|e| e.size<@max_length}
98
+ rescue => e
99
+ "Error while reading #{quotes_file}"
100
+ end
101
+
102
+ def quotes_file
103
+ "#{__dir__}/run/quotes.yml"
104
+ end
105
+
106
+ def print_text
107
+ print "\r"+text.sub(/(.{#{pos}})/,"#{@color}\\1#{@no_color}")
108
+ end
109
+
110
+ def update_text
111
+ system('stty raw -echo')
112
+ bye if (c=STDIN.getc)==@eof.chr
113
+ @pos+=1 if c==text[pos]
114
+ ensure
115
+ system('stty -raw echo')
116
+ print_text
117
+ end
118
+
119
+ def text
120
+ @text
121
+ end
122
+
123
+ def pos
124
+ @pos
125
+ end
126
+
127
+ def bye
128
+ puts "\nBye"
129
+ exit
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ - "Do nothing out of selfish ambition or vain conceit, but in humility consider others better than yourselves. - philippians 2:3"
2
+ - "It's a funny thing, but people mostly have it backward. They think they live by what they want. But really, what guides them is what they're afraid of. What they don't want. - khaled hosseini typeracer"
3
+ - "roses are red, violets are blue"
@@ -0,0 +1,3 @@
1
+ module Run
2
+ VERSION = "0.1.0"
3
+ end
data/run.gemspec ADDED
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "run/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "run"
8
+ spec.version = Run::VERSION
9
+ spec.authors = ["sergioro"]
10
+ spec.email = ["yo@sergioro.com"]
11
+
12
+ spec.summary = %q{Increase your typing speed}
13
+ spec.description = %q{Increase typing speed and keep track of WPM history}
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "benchmark-ips", ">= 0"
28
+ spec.add_development_dependency "byebug", "~> 11.0.1"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
31
+ spec.add_development_dependency "ronn", "~> 0.7"
32
+ spec.add_development_dependency "ruby-prof", ">= 0"
33
+
34
+ #spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
35
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: run
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sergioro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: benchmark-ips
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 11.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 11.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.8
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.8
97
+ - !ruby/object:Gem::Dependency
98
+ name: ronn
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ruby-prof
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Increase typing speed and keep track of WPM history
126
+ email:
127
+ - yo@sergioro.com
128
+ executables:
129
+ - run
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - exe/run
144
+ - lib/run.rb
145
+ - lib/run/quotes.yml
146
+ - lib/run/version.rb
147
+ - run.gemspec
148
+ homepage:
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Increase your typing speed
171
+ test_files: []