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 +4 -4
- data/lib/chris_lib/chris_math.rb +7 -8
- data/lib/chris_lib/shell_methods.rb +99 -51
- data/lib/chris_lib/version.rb +1 -1
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a77612982d1e205fb772a8403f40c679e5f6edb
|
4
|
+
data.tar.gz: fedcc2c2837b0e3d4bb6f2ec617ef95c5881d22d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49557451071f3148f67eb457dbfc7160e85f0e5fa6c14b62855cb6937ee737934983a1c841b5b07b2a7f3104368814a0c67b961c9391a7a4ad48c120b6146319
|
7
|
+
data.tar.gz: c70962d469796981abfb8598254fc9e83c65bf8fbfece7c2998f5013be11f9813596ac880527436aab71ba2e1479cabdf98b1151275952d21664735716a13278
|
data/lib/chris_lib/chris_math.rb
CHANGED
@@ -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
|
13
|
+
fail 'Length must be greater than 0.' if length < 1
|
14
14
|
sum = self.inject { |s, v| s + v }
|
15
|
-
sum.to_f /
|
15
|
+
sum.to_f / length
|
16
16
|
end
|
17
17
|
|
18
18
|
def var
|
19
|
-
fail 'Length must be greater than 1' if
|
20
|
-
|
21
|
-
|
22
|
-
|
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.
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
data/lib/chris_lib/version.rb
CHANGED
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
|
+
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:
|
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:
|
20
|
-
type: :
|
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:
|
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:
|
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:
|
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.
|
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
|