chris_lib 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 644d85e09356e803160f6562212ab9acc020c56a
4
- data.tar.gz: 51a87933aff33327eea02d05f5dc82f84290b6b3
3
+ metadata.gz: 3a77612982d1e205fb772a8403f40c679e5f6edb
4
+ data.tar.gz: fedcc2c2837b0e3d4bb6f2ec617ef95c5881d22d
5
5
  SHA512:
6
- metadata.gz: 5c3d9047bde6f90c116d56ca4e04d54f2675d3c1560a612218ff07bfa4d9c17bc3570147b2c77c7db8a5e1cbdba304c4aecf4a7d93b818f20c9b2e301c810033
7
- data.tar.gz: 6aa3a9ae320d90d650b0c57710e678d91bfc9429fdde61fa2a3f12dbc1d68c807a0b9ab1e67eb4a8af004ef57ab935d23965c20440574e0afdf86a9ab8b6357f
6
+ metadata.gz: 49557451071f3148f67eb457dbfc7160e85f0e5fa6c14b62855cb6937ee737934983a1c841b5b07b2a7f3104368814a0c67b961c9391a7a4ad48c120b6146319
7
+ data.tar.gz: c70962d469796981abfb8598254fc9e83c65bf8fbfece7c2998f5013be11f9813596ac880527436aab71ba2e1479cabdf98b1151275952d21664735716a13278
@@ -10,17 +10,16 @@ Integer.class_eval do
10
10
  end
11
11
  Array.class_eval do
12
12
  def mean
13
- fail 'Length must be greater than 1.' if count < 2
13
+ fail 'Length must be greater than 0.' if length < 1
14
14
  sum = self.inject { |s, v| s + v }
15
- sum.to_f / count
15
+ sum.to_f / length
16
16
  end
17
17
 
18
18
  def var
19
- fail 'Length must be greater than 1' if count < 2
20
- m = self.mean
21
- sum = self.inject { |s,v| s + (v**2 - m**2)}
22
- m=count-1
23
- sum.to_f/m
19
+ fail 'Length must be greater than 1' if length < 2
20
+ mu = self.mean
21
+ total = self.inject(0) { |s,v| s + (v**2 - mu**2)}
22
+ total.to_f/(length - 1)
24
23
  end
25
24
 
26
25
  def median
@@ -70,7 +69,7 @@ module ChrisMath
70
69
 
71
70
 
72
71
  def std(values)
73
- n = values.count
72
+ n = values.length
74
73
  fail 'n = #{n} but must be greater than 1' if n < 2
75
74
  m = mean(values)
76
75
  sum = values.inject { |s,v| s + (v**2 - m**2)}
@@ -1,53 +1,101 @@
1
+ # methods for bash ruby scripts
1
2
  module ShellMethods
2
- def time_hash
3
- time=Time.now
4
- time.day.to_s + time.month.to_s + time.year.to_s + '-' + time.hour.to_s + time.min.to_s
5
- end
6
- def same_db_version(remote: nil)
7
- destination=(remote.nil? ? nil : "--remote #{remote}")
8
- lv=`rake db:version`;lr=$?.success?
9
- puts "Local version: ",lv
10
- hv=`heroku run rake db:version #{destination}`;hr=$?.success?
11
- puts hv
12
- key='version: '
13
- nl=lv.index(key)+9
14
- l_version=lv.slice(nl..-1)
15
- nh=hv.index(key)+9
16
- h_version=hv.slice(nh..-1)
17
- l_version==h_version
18
- end
19
- def check_git_clean
20
- puts "Checking git status"
21
- gs=`git status`; lr=$?.success?
22
- if gs['working directory clean'].nil?
23
- puts "Exiting, you need to commit files"
24
- exit 1
25
- end
26
- end
27
- def check_chris_lib_status
28
- gs=`cd ../chris_lib;git status`; lr=$?.success?
29
- if gs['working directory clean'].nil? && gs['up-to-date'].nil?
30
- puts "Exiting, chris_lib is not up to date with master."
31
- exit 3
32
- end
33
- system('cd $OLDPWD')
34
- end
35
- def migrate_if_necessary(remote: nil,migrate: nil)
36
- if migrate == '--no_migrate'
37
- puts "No migration will be performed due to --no_migrate option"
38
- else
39
- destination=(remote.nil? ? nil : "--remote #{remote}")
40
- puts "Checking local and remote databases have same version and migrates if necessary"
41
- if same_db_version(remote: remote)
42
- puts "No migration necessary"
43
- else
44
- puts "Warning, different db versions"
45
- system('tput bel')
46
- puts "Press m<cr> to migrate or q<cr> to exit"
47
- ans=$stdin.gets()
48
- exit 2 if ans[0]!='m'
49
- system("heroku run rake db:migrate #{destination}")
50
- end
51
- end
52
- end
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ def precompile_assets(target: 'local')
7
+ puts "Precompiling assets for #{target}"
8
+ if target == 'local'
9
+ asset_host = ENV['RAILS_HOST_PATH']
10
+ elsif target == 'staging'
11
+ asset_host = 'cstaging-golf.herokuapp.com'
12
+ elsif target == 'production'
13
+ asset_host = 'www.thegolfmentor.com'
14
+ else
15
+ raise "Invalid target for precompile: #{target}"
16
+ end
17
+ puts "precompile asset_host is #{asset_host}"
18
+ system("RAILS_ENV=production RAILS_HOST_PATH=#{asset_host} rake assets:precompile")
19
+ `git add .`
20
+ commit_msg = "Add precompiled assets for #{target}"
21
+ system(%[git commit -m "#{commit_msg}"])
22
+ end
23
+
24
+ def time_hash
25
+ time = Time.now
26
+ time.day.to_s + time.month.to_s + time.year.to_s + '-' + time.hour.to_s + time.min.to_s
27
+ end
28
+
29
+ def same_db_version(remote: nil)
30
+ destination = (remote.nil? ? nil : "--remote #{remote}")
31
+ lv = `rake db:version`
32
+ puts 'Local version: ', lv
33
+ hv = `heroku run rake db:version #{destination}`
34
+ puts hv
35
+ key = 'version: '
36
+ nl = lv.index(key) + 9
37
+ l_version = lv.slice(nl..-1)
38
+ nh = hv.index(key) + 9
39
+ h_version = hv.slice(nh..-1)
40
+ l_version == h_version
41
+ end
42
+
43
+ def check_git_clean
44
+ puts "Checking git status"
45
+ gs=`git status`; lr=$?.success?
46
+ if gs['working directory clean'].nil?
47
+ puts "Exiting, you need to commit files"
48
+ exit 1
49
+ end
50
+ end
51
+
52
+ def check_chris_lib_status
53
+ gs=`cd ../chris_lib;git status`; lr=$?.success?
54
+ if gs['working directory clean'].nil? && gs['up-to-date'].nil?
55
+ puts "Exiting, chris_lib is not up to date with master."
56
+ exit 3
57
+ end
58
+ system('cd $OLDPWD')
59
+ end
60
+
61
+ def migrate_if_necessary(remote: nil,migrate: nil)
62
+ if migrate == '--no_migrate'
63
+ puts "No migration will be performed due to --no_migrate option"
64
+ else
65
+ destination=(remote.nil? ? nil : "--remote #{remote}")
66
+ puts "Checking local and remote databases have same version and migrates if necessary"
67
+ if same_db_version(remote: remote)
68
+ puts "No migration necessary"
69
+ else
70
+ puts "Warning, different db versions"
71
+ system('tput bel')
72
+ puts "Press m<cr> to migrate or q<cr> to exit"
73
+ ans=$stdin.gets()
74
+ exit 2 if ans[0]!='m'
75
+ system("heroku run rake db:migrate #{destination}")
76
+ end
77
+ end
78
+ end
79
+
80
+ def notify_rollbar_of_deploy(access_token: nil)
81
+ system("ACCESS_TOKEN=#{access_token}")
82
+ system("ENVIRONMENT=production")
83
+ system("LOCAL_USERNAME=`whoami`")
84
+ system("COMMENT=v#{TGM_VERSION}")
85
+ sha = `git log -n 1 --pretty=format:'%H'`
86
+ system("REVISION=sha")
87
+ puts "Notifiying of revision #{sha}"
88
+ cr = `curl https://api.rollbar.com/api/1/deploy/ \
89
+ -F access_token=$ACCESS_TOKEN \
90
+ -F environment=$ENVIRONMENT \
91
+ -F revision=$REVISION \
92
+ -F comment=$COMMENT \
93
+ -F local_username=$LOCAL_USERNAME`
94
+ if cr.class == Hash && cr['data'].empty?
95
+ puts "Rollbar was notified of deploy of v#{TGM_VERSION} with SHA #{sha[0..5]}"
96
+ else
97
+ system('tput bel;tput bel')
98
+ puts "Failure to notify Rollbar of deploy of v#{TGM_VERSION} with SHA #{sha[0..5]}", cr
99
+ end
100
+ end
53
101
  end
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chris_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-15 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
19
+ version: 5.1.4
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 5.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.0.rc1
47
+ version: 3.7.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.0.rc1
54
+ version: 3.7.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: It include maths, datetime, and rspec access test libraries. It include
56
70
  maths, datetime, and rspec access test libraries.
57
71
  email:
@@ -89,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
103
  version: '0'
90
104
  requirements: []
91
105
  rubyforge_project:
92
- rubygems_version: 2.4.8
106
+ rubygems_version: 2.6.13
93
107
  signing_key:
94
108
  specification_version: 4
95
109
  summary: This an eclectic collection of methods. It include maths, datetime, and rspec