chris_lib 1.0.11 → 1.1.0

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
  SHA256:
3
- metadata.gz: 289ced265cbc0ec6874f0af6e225fe72bd0a348e6a12a3263141086ac8f41d60
4
- data.tar.gz: 3c628754db631e07c695e44d5ffdfc0d13c3085224b625f18d4ea4cbfbdbca1a
3
+ metadata.gz: 5e76deaa3a7824340278bd4eb24898ca3ad0ded771c0fab25ada63ef77bd850e
4
+ data.tar.gz: febe97bd1fc1c7eb4c55c218961685d35dea75eba78bc0d4b1cf2a26607f4f0c
5
5
  SHA512:
6
- metadata.gz: dd00269d4d497cf53793f157837ce118b25da7ca57f5706c086408eda0d6b18d522e130d776c52b3cbfa008589b677dfd9e32080268bc0b4e1c29f67fad5beec
7
- data.tar.gz: c5b90b9cd5e0facf4e4374eb67c9f20e43802da779a3583732f26bee9f763ec5b665c1b9f3ab1b68e41d6ea5f0619f176533c5dcff22714104e9b0fceb529190
6
+ metadata.gz: d99b4d0e88fd728b064212aed2d3bd87ec1921583c2a20e70a906501ec3c175be3f684f444a2495d7c422352eea0a740cfc935568a6e5cf16af261ee6cd8dba3
7
+ data.tar.gz: bc0a1a439fce1c6e8b8ef6a36b0b557e893e2bab208b694602f2ff2e85393a494dd1da62e261b2c41828864720042bfeb3af7ff0b9020c309c9bc72c69cb3500
@@ -9,12 +9,16 @@ Integer.class_eval do
9
9
  end
10
10
  end
11
11
  Array.class_eval do
12
+ # mean of array
12
13
  def mean
14
+ # s=c(7.08195525827783, 10.831582068121444, 9.288611270369554, 9.054684238411918, 12.268532229606647)
15
+ # returns 9.705073
13
16
  fail 'Length must be greater than 0.' if length < 1
14
17
  sum = self.inject { |s, v| s + v }
15
18
  sum.to_f / length
16
19
  end
17
20
 
21
+ # unbiased sample variance of array
18
22
  def var
19
23
  fail 'Length must be greater than 1' if length < 2
20
24
  mu = self.mean
@@ -22,6 +26,16 @@ Array.class_eval do
22
26
  total.to_f/(length - 1)
23
27
  end
24
28
 
29
+ # sammple standard deviation
30
+ def std
31
+ Math.sqrt(var)
32
+ end
33
+
34
+ # standard error of sample mean
35
+ def std_err
36
+ std / Math.sqrt(size)
37
+ end
38
+
25
39
  def median
26
40
  return self[0] if length <= 1
27
41
  sorted = sort
@@ -38,6 +52,36 @@ Array.class_eval do
38
52
  self.each { |x| k[x] += 1 }
39
53
  k
40
54
  end
55
+
56
+ # deep dup, takes about 20 microseconds for scores arrays
57
+ # https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
58
+ def deep_dup
59
+ Marshal.load(Marshal.dump(self))
60
+ end
61
+ end
62
+
63
+ Float.class_eval do
64
+ def round_down(n=0)
65
+ # n is decimal place to round down at
66
+ int,dec=self.to_s.split('.')
67
+ "#{int}.#{dec[0...n]}".to_f
68
+ end
69
+
70
+ def round1
71
+ round(1)
72
+ end
73
+
74
+ def round2
75
+ round(2)
76
+ end
77
+
78
+ def round3
79
+ round(3)
80
+ end
81
+
82
+ def round4
83
+ round(4)
84
+ end
41
85
  end
42
86
 
43
87
  module ChrisMath
@@ -2,8 +2,50 @@
2
2
  module ShellMethods
3
3
  require 'dotenv'
4
4
  require 'bundler'
5
+ require 'optparse'
5
6
  Dotenv.load
6
7
 
8
+ def parse_options
9
+ @options = {}
10
+ OptionParser.new do |opts|
11
+ opts.on("-s", "--skip_migration", "Skip migrations") do
12
+ @options[:skip_migration] = true
13
+ end
14
+ opts.on("-f", "--fast", "Deploy without warnings and skip migrations") do
15
+ @options[:fast] = true
16
+ end
17
+ opts.on("-r", "--special_rake", "Run special rake task") do
18
+ @options[:special_rake] = true
19
+ end
20
+ end.parse!
21
+ @options[:skip_migration] = true if @options[:fast]
22
+ end
23
+
24
+ def run_special_rake_task
25
+ fail 'Need to implement by asking for name of rake task and
26
+ also requiring confirmation'
27
+ end
28
+
29
+ def backup_database
30
+ file_path = "../backups/prod#{time_hash}.dump"
31
+ system('./script/getSnapShot.sh production ' + file_path)
32
+ end
33
+
34
+ def warn_users
35
+ system('heroku run rake util:three_min_warning --remote production')
36
+ # spend one minute precompiling
37
+ progress_bar = ProgressBar.create
38
+ # now 2 minutes waiting
39
+ increment = 3 * 60 / 100
40
+ (1..100).each do |_i|
41
+ sleep increment
42
+ progress_bar.increment
43
+ progress_bar.refresh
44
+ end
45
+ system('heroku run rake util:delete_newest_announcement --remote production')
46
+ system('heroku run rake util:warn_under_maintenance --remote production')
47
+ end
48
+
7
49
  def precompile_assets(target: 'local')
8
50
  puts "Precompiling assets for #{target}"
9
51
  if target == 'local'
@@ -64,9 +106,9 @@ module ShellMethods
64
106
  system('cd $OLDPWD')
65
107
  end
66
108
 
67
- def migrate_if_necessary(remote: nil,migrate: nil)
68
- if migrate == '--no_migrate'
69
- puts "No migration will be performed due to --no_migrate option"
109
+ def migrate_if_necessary(remote: nil, skip_migration: false)
110
+ if skip_migration
111
+ puts "No migration will be performed due to --fast or --skip_migration options"
70
112
  else
71
113
  destination=(remote.nil? ? nil : "--remote #{remote}")
72
114
  puts "Checking local and remote databases have same version and migrates if necessary"
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "1.0.11"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chris_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-22 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.7.6
131
+ rubygems_version: 2.7.9
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: This an eclectic collection of methods. It include maths, datetime, and rspec