my_scripts 0.0.13 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.gitignore +21 -21
- data/LICENSE +20 -20
- data/README.rdoc +98 -98
- data/Rakefile +57 -57
- data/VERSION +1 -1
- data/bin/citi +4 -4
- data/bin/dummy +4 -4
- data/bin/gitto +4 -4
- data/bin/jew +5 -5
- data/bin/mybones +5 -5
- data/bin/newscript +5 -0
- data/bin/rabbit +5 -5
- data/bin/wake +5 -0
- data/features/my_scripts.feature +9 -9
- data/features/support/env.rb +4 -4
- data/lib/my_scripts/citi.rb +70 -71
- data/lib/my_scripts/cli.rb +39 -39
- data/lib/my_scripts/dummy.rb +17 -17
- data/lib/my_scripts/extensions.rb +43 -43
- data/lib/my_scripts/gitto.rb +33 -33
- data/lib/my_scripts/jew.rb +19 -19
- data/lib/my_scripts/mybones.rb +19 -19
- data/lib/my_scripts/rabbit.rb +19 -17
- data/lib/my_scripts/script.rb +29 -29
- data/lib/my_scripts/wake.rb +40 -0
- data/lib/my_scripts.rb +12 -12
- data/my_scripts.gemspec +82 -79
- data/spec/my_scripts/extensions_spec.rb +60 -60
- data/spec/my_scripts_spec.rb +81 -81
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +9 -9
- metadata +31 -13
data/lib/my_scripts/citi.rb
CHANGED
@@ -1,72 +1,71 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# This script converts given QIF file (with downloaded citibank statement)
|
3
|
-
# into Quicken 2008 compatible format, and outputs it into new file for
|
4
|
-
# import into Quicken
|
5
|
-
#
|
6
|
-
class Citi < Script
|
7
|
-
INFILE_ENCODING = 'CP1251:UTF-8' # Encoding pair of input file ('File external:Ruby internal')
|
8
|
-
OUTFILE_ENCODING = 'CP1252:UTF-8' # Encoding pair of output file ('File external:Ruby internal')
|
9
|
-
# STDOUT_ENCODING = 'CP866:UTF-8' # Encoding pair of stdout ('Stdout external:Ruby internal')
|
10
|
-
|
11
|
-
REPLACE = {
|
12
|
-
'Universam '=> '',
|
13
|
-
'Supermarket '=> '',
|
14
|
-
'Pokupka Masterkard ' => '',
|
15
|
-
/.*(Detskiy Mir).*/ => "Detski Mir\nLChildcare",
|
16
|
-
/.*(Legioner).*/ => "Legioner\nLBooks & Media:DVDs",
|
17
|
-
/.*(Gudman).*/ => "Goodman\nLDining",
|
18
|
-
/.*(Sushi Vesla).*/ => "\\1\nLDining",
|
19
|
-
/.*(Starbucks).*/ => "\\1\nLDining",
|
20
|
-
/.*(Medicina).*/ => "AO Medicina\nLMedical:Medicine",
|
21
|
-
/.*(Pharmacy).*/ => "\\1\nLMedical:Medicine",
|
22
|
-
/.*(Alye Parusa).*/ => "\\1\nLGroceries",
|
23
|
-
/.*(Perekrestok).*/ => "\\1\nLGroceries",
|
24
|
-
/.*(Ile De Beaute).*/ => "\\1\nLPersonal Care",
|
25
|
-
/.*(Beeline).*/ => "\\1\nLCommunications:Telephone",
|
26
|
-
/(.+) (Moscow Ru.*|Moskva Ru.*)/ => "\\1\nM\\2\nLHousehold",
|
27
|
-
/Vkhodyashchij Platezh(.+Bank Moskvy)/ => "Incoming transfer\nM\\1\nL[BM 2yr Prestige]",
|
28
|
-
/Platezh Cherez Citibank Online/ => "Incoming transfer\nL[Citi RUB]",
|
29
|
-
/Oplata Dolg Kr Karta(.+)/ => "Transfer to Credit card\nM\\1\nL[Citi MC]",
|
30
|
-
/Snyatie Nalichnykh(.+)/ => "Cash withdrawal\nM\\1\nL[Cash RUB]",
|
31
|
-
/Vznos Nalichnykh(.+)/ => "Cash deposit\nM\\1\nL[Cash RUB]",
|
32
|
-
/Kom Za Obsluzhivanie/ => "Citibank\nMService fee\nLFinance:Bank Charge",
|
33
|
-
/Komissiya Za Snyatie Nalichnykh/ => "Citibank\nMCash withdrawal fee\nLFinance:Bank Charge"
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
line
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# This script converts given QIF file (with downloaded citibank statement)
|
3
|
+
# into Quicken 2008 compatible format, and outputs it into new file for
|
4
|
+
# import into Quicken
|
5
|
+
#
|
6
|
+
class Citi < Script
|
7
|
+
INFILE_ENCODING = 'CP1251:UTF-8' # Encoding pair of input file ('File external:Ruby internal')
|
8
|
+
OUTFILE_ENCODING = 'CP1252:UTF-8' # Encoding pair of output file ('File external:Ruby internal')
|
9
|
+
# STDOUT_ENCODING = 'CP866:UTF-8' # Encoding pair of stdout ('Stdout external:Ruby internal')
|
10
|
+
|
11
|
+
REPLACE = {
|
12
|
+
'Universam '=> '',
|
13
|
+
'Supermarket '=> '',
|
14
|
+
'Pokupka Masterkard ' => '',
|
15
|
+
/.*(Detskiy Mir).*/ => "Detski Mir\nLChildcare",
|
16
|
+
/.*(Legioner).*/ => "Legioner\nLBooks & Media:DVDs",
|
17
|
+
/.*(Gudman).*/ => "Goodman\nLDining",
|
18
|
+
/.*(Sushi Vesla).*/ => "\\1\nLDining",
|
19
|
+
/.*(Starbucks).*/ => "\\1\nLDining",
|
20
|
+
/.*(Medicina).*/ => "AO Medicina\nLMedical:Medicine",
|
21
|
+
/.*(Pharmacy).*/ => "\\1\nLMedical:Medicine",
|
22
|
+
/.*(Alye Parusa).*/ => "\\1\nLGroceries",
|
23
|
+
/.*(Perekrestok).*/ => "\\1\nLGroceries",
|
24
|
+
/.*(Ile De Beaute).*/ => "\\1\nLPersonal Care",
|
25
|
+
/.*(Beeline).*/ => "\\1\nLCommunications:Telephone",
|
26
|
+
/(.+) (Moscow Ru.*|Moskva Ru.*)/ => "\\1\nM\\2\nLHousehold",
|
27
|
+
/Vkhodyashchij Platezh(.+Bank Moskvy)/ => "Incoming transfer\nM\\1\nL[BM 2yr Prestige]",
|
28
|
+
/Platezh Cherez Citibank Online/ => "Incoming transfer\nL[Citi RUB]",
|
29
|
+
/Oplata Dolg Kr Karta(.+)/ => "Transfer to Credit card\nM\\1\nL[Citi MC]",
|
30
|
+
/Snyatie Nalichnykh(.+)/ => "Cash withdrawal\nM\\1\nL[Cash RUB]",
|
31
|
+
/Vznos Nalichnykh(.+)/ => "Cash deposit\nM\\1\nL[Cash RUB]",
|
32
|
+
/Kom Za Obsluzhivanie/ => "Citibank\nMService fee\nLFinance:Bank Charge",
|
33
|
+
/Komissiya Za Snyatie Nalichnykh/ => "Citibank\nMCash withdrawal fee\nLFinance:Bank Charge"
|
34
|
+
}
|
35
|
+
|
36
|
+
def run
|
37
|
+
usage "in_file.qif [out_file.qif]" if @argv.empty?
|
38
|
+
|
39
|
+
in_file = @argv.first
|
40
|
+
|
41
|
+
# If 2nd Arg is given, it is out_file name, otherwise derive from in_file name
|
42
|
+
out_file = @argv[1] ? @argv[1] : in_file.sub(/\.qif|$/i, '_out.qif')
|
43
|
+
|
44
|
+
# $stdout.set_encoding(STDOUT_ENCODING, :undef=>:replace)
|
45
|
+
File.open(out_file, 'w:'+ OUTFILE_ENCODING, :undef => :replace) do |outfile|
|
46
|
+
File.open(in_file, 'r:'+ INFILE_ENCODING, :undef => :replace).each_line do |line|
|
47
|
+
type = line[0]
|
48
|
+
text = line[1..-1]
|
49
|
+
case type # Indicates type of field
|
50
|
+
when 'D' # Date field - convert to MM/DD/YYYY format expected by Quicken
|
51
|
+
text.gsub! /(\d+)\/(\d+)\/(\d+)/, '\2/\1/\3'
|
52
|
+
when 'P' # Payee field
|
53
|
+
# Convert payee from Cyrillic to Latin translit
|
54
|
+
text.translit!
|
55
|
+
# Capitalize each word and remove extra whitespaces (leaves first char intact)
|
56
|
+
text = text.scan(/[\w&]+/).map{|word| word.capitalize}.join(' ')
|
57
|
+
# Preprocess Payee field making pre-defined replacements
|
58
|
+
REPLACE.each {|key, value| text.gsub!(key, value)}
|
59
|
+
when 'M' # Memo field - drop if empty
|
60
|
+
if text.rstrip.empty?
|
61
|
+
text.clear
|
62
|
+
type.clear
|
63
|
+
end
|
64
|
+
end
|
65
|
+
line = type+text
|
66
|
+
outfile.puts line unless line.empty?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end
|
data/lib/my_scripts/cli.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# This class encapsulates Command Line Interface for running scripts. It can be instantiated
|
3
|
-
# with stubbed stdin and stdout if you want to run tests on your scripts
|
4
|
-
class CLI
|
5
|
-
class ScriptNameError < NameError # :nodoc:
|
6
|
-
def initialize(message=nil)
|
7
|
-
message ? super(message) : super
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_accessor :stdout, :stdin
|
12
|
-
|
13
|
-
# Instantiates new CLI(command line interface) and runs script with given name (token)
|
14
|
-
# and argv inside new CLI instance
|
15
|
-
def self.run( script_name, argv )
|
16
|
-
new.run script_name, argv
|
17
|
-
end
|
18
|
-
|
19
|
-
# Creates new command line interface
|
20
|
-
def initialize( stdin=$stdin, stdout=$stdout )
|
21
|
-
@stdin = stdin
|
22
|
-
@stdout = stdout
|
23
|
-
end
|
24
|
-
|
25
|
-
# Runs a script with given name (token) and argv inside this CLI instance
|
26
|
-
def run( script_name, argv )
|
27
|
-
script = script_class_name(script_name).to_class
|
28
|
-
raise ScriptNameError.new("Script #{script_class_name(script_name)} not found") unless script
|
29
|
-
|
30
|
-
script.new(script_name, argv, self).run
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def script_class_name(script_name)
|
36
|
-
"MyScripts::#{script_name.to_s.camel_case}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# This class encapsulates Command Line Interface for running scripts. It can be instantiated
|
3
|
+
# with stubbed stdin and stdout if you want to run tests on your scripts
|
4
|
+
class CLI
|
5
|
+
class ScriptNameError < NameError # :nodoc:
|
6
|
+
def initialize(message=nil)
|
7
|
+
message ? super(message) : super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :stdout, :stdin
|
12
|
+
|
13
|
+
# Instantiates new CLI(command line interface) and runs script with given name (token)
|
14
|
+
# and argv inside new CLI instance
|
15
|
+
def self.run( script_name, argv )
|
16
|
+
new.run script_name, argv
|
17
|
+
end
|
18
|
+
|
19
|
+
# Creates new command line interface
|
20
|
+
def initialize( stdin=$stdin, stdout=$stdout )
|
21
|
+
@stdin = stdin
|
22
|
+
@stdout = stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
# Runs a script with given name (token) and argv inside this CLI instance
|
26
|
+
def run( script_name, argv )
|
27
|
+
script = script_class_name(script_name).to_class
|
28
|
+
raise ScriptNameError.new("Script #{script_class_name(script_name)} not found") unless script
|
29
|
+
|
30
|
+
script.new(script_name, argv, self).run
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def script_class_name(script_name)
|
36
|
+
"MyScripts::#{script_name.to_s.camel_case}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/my_scripts/dummy.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# Dummy script skeleton that is ready for your usage. Just put your script code
|
3
|
-
# inside run method (if you use ARGV, change it to @argv). Done!
|
4
|
-
# You can immediately run your script anywhere using following command:
|
5
|
-
# $ dummy Whatever arguments your code expects and processes
|
6
|
-
#
|
7
|
-
class Dummy < Script
|
8
|
-
def run
|
9
|
-
# here you do all actual work for your script
|
10
|
-
# you have following instance vars at your disposal:
|
11
|
-
# @name - your script name,
|
12
|
-
# @argv - your ARGV (Array of argument Strings passed at command line),
|
13
|
-
# @cli - CLI runner (holds references to stdin and stdout)
|
14
|
-
#...
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# Dummy script skeleton that is ready for your usage. Just put your script code
|
3
|
+
# inside run method (if you use ARGV, change it to @argv). Done!
|
4
|
+
# You can immediately run your script anywhere using following command:
|
5
|
+
# $ dummy Whatever arguments your code expects and processes
|
6
|
+
#
|
7
|
+
class Dummy < Script
|
8
|
+
def run
|
9
|
+
# here you do all actual work for your script
|
10
|
+
# you have following instance vars at your disposal:
|
11
|
+
# @name - your script name,
|
12
|
+
# @argv - your ARGV (Array of argument Strings passed at command line),
|
13
|
+
# @cli - CLI runner (holds references to stdin and stdout)
|
14
|
+
#...
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
class String
|
4
|
-
TRANSLIT_CYRILLIC = %Q{АБВГДЕЁЗИЙКЛМНОПРСТУФЪЫЬЭабвгдеёзийклмнопрстуфъыьэ}
|
5
|
-
TRANSLIT_LATIN = %Q{ABVGDEEZIJKLMNOPRSTUF"Y'Eabvgdeezijklmnoprstuf"y'e}
|
6
|
-
TRANSLIT_DOUBLES = {'Ж'=>'ZH', 'Х'=>'KH', 'Ц'=>'TS', 'Ч'=>'CH', 'Ш'=>'SH', 'Щ'=>'SHCH', 'Ю'=>'YU', 'Я'=>'YA',
|
7
|
-
'ж'=>'zh', 'х'=>'kh', 'ц'=>'ts', 'ч'=>'ch', 'ш'=>'sh', 'щ'=>'shch', 'ю'=>'yu', 'я'=>'ya'}
|
8
|
-
|
9
|
-
# Performs basic transliteration from Cyrillic to Latin characters and standard character combinations
|
10
|
-
def translit!
|
11
|
-
TRANSLIT_DOUBLES.each {|key, value| self.gsub!(key, value)}
|
12
|
-
self.tr!(TRANSLIT_CYRILLIC, TRANSLIT_LATIN)
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
# Turns string into appropriate class constant, returns nil if class not found
|
17
|
-
def to_class
|
18
|
-
klass = self.split("::").inject(Kernel) do |namespace, const|
|
19
|
-
const == '' ? namespace : namespace.const_get(const)
|
20
|
-
end
|
21
|
-
klass.is_a?(Class) ? klass : nil
|
22
|
-
rescue NameError
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
|
26
|
-
# Turns string into snake_case
|
27
|
-
def snake_case
|
28
|
-
gsub(/([a-z])([A-Z0-9])/, '\1_\2' ).downcase
|
29
|
-
end
|
30
|
-
|
31
|
-
# Turns string into CamelCase
|
32
|
-
def camel_case
|
33
|
-
if self.include? '_'
|
34
|
-
self.split('_').map{|e| e.capitalize}.join
|
35
|
-
else
|
36
|
-
unless self =~ (/^[A-Z]/)
|
37
|
-
self.capitalize
|
38
|
-
else
|
39
|
-
self
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class String
|
4
|
+
TRANSLIT_CYRILLIC = %Q{АБВГДЕЁЗИЙКЛМНОПРСТУФЪЫЬЭабвгдеёзийклмнопрстуфъыьэ}
|
5
|
+
TRANSLIT_LATIN = %Q{ABVGDEEZIJKLMNOPRSTUF"Y'Eabvgdeezijklmnoprstuf"y'e}
|
6
|
+
TRANSLIT_DOUBLES = {'Ж'=>'ZH', 'Х'=>'KH', 'Ц'=>'TS', 'Ч'=>'CH', 'Ш'=>'SH', 'Щ'=>'SHCH', 'Ю'=>'YU', 'Я'=>'YA',
|
7
|
+
'ж'=>'zh', 'х'=>'kh', 'ц'=>'ts', 'ч'=>'ch', 'ш'=>'sh', 'щ'=>'shch', 'ю'=>'yu', 'я'=>'ya'}
|
8
|
+
|
9
|
+
# Performs basic transliteration from Cyrillic to Latin characters and standard character combinations
|
10
|
+
def translit!
|
11
|
+
TRANSLIT_DOUBLES.each {|key, value| self.gsub!(key, value)}
|
12
|
+
self.tr!(TRANSLIT_CYRILLIC, TRANSLIT_LATIN)
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
# Turns string into appropriate class constant, returns nil if class not found
|
17
|
+
def to_class
|
18
|
+
klass = self.split("::").inject(Kernel) do |namespace, const|
|
19
|
+
const == '' ? namespace : namespace.const_get(const)
|
20
|
+
end
|
21
|
+
klass.is_a?(Class) ? klass : nil
|
22
|
+
rescue NameError
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Turns string into snake_case
|
27
|
+
def snake_case
|
28
|
+
gsub(/([a-z])([A-Z0-9])/, '\1_\2' ).downcase
|
29
|
+
end
|
30
|
+
|
31
|
+
# Turns string into CamelCase
|
32
|
+
def camel_case
|
33
|
+
if self.include? '_'
|
34
|
+
self.split('_').map{|e| e.capitalize}.join
|
35
|
+
else
|
36
|
+
unless self =~ (/^[A-Z]/)
|
37
|
+
self.capitalize
|
38
|
+
else
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/my_scripts/gitto.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# This script wraps up all work done on project in current directory,
|
3
|
-
# adds all new(unversioned) files to git, commits all work done so far,
|
4
|
-
# optionally bumps project version and pushes changes to remote repo
|
5
|
-
#
|
6
|
-
class Gitto < Script
|
7
|
-
def run
|
8
|
-
usage "[bump: 1 - patch, 10 - minor, 100 - major] Commit message goes here" if @argv.empty?
|
9
|
-
|
10
|
-
# If first Arg is a number, it indicates version bump
|
11
|
-
bump = @argv[0].to_i > 0 ? @argv.shift.to_i : 0
|
12
|
-
|
13
|
-
# All the other args lumped into message, or default message
|
14
|
-
message = @argv.empty? ? 'Commit' : @argv.join(' ')
|
15
|
-
# Timestamp added to message
|
16
|
-
message += " #{Time.now.to_s[0..-6]}"
|
17
|
-
|
18
|
-
puts "Committing (versionup =#{bump}) with message: #{message}"
|
19
|
-
|
20
|
-
case bump
|
21
|
-
when 1..9
|
22
|
-
system %Q[rake version:bump:patch]
|
23
|
-
when 10..99
|
24
|
-
system %Q[rake version:bump:minor]
|
25
|
-
when 10..99
|
26
|
-
system %Q[rake version:bump:major]
|
27
|
-
end
|
28
|
-
system %Q[git add --all]
|
29
|
-
system %Q[git commit -a -m "#{message}" --author arvicco]
|
30
|
-
system %Q[git push]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# This script wraps up all work done on project in current directory,
|
3
|
+
# adds all new(unversioned) files to git, commits all work done so far,
|
4
|
+
# optionally bumps project version and pushes changes to remote repo
|
5
|
+
#
|
6
|
+
class Gitto < Script
|
7
|
+
def run
|
8
|
+
usage "[bump: 1 - patch, 10 - minor, 100 - major] Commit message goes here" if @argv.empty?
|
9
|
+
|
10
|
+
# If first Arg is a number, it indicates version bump
|
11
|
+
bump = @argv[0].to_i > 0 ? @argv.shift.to_i : 0
|
12
|
+
|
13
|
+
# All the other args lumped into message, or default message
|
14
|
+
message = @argv.empty? ? 'Commit' : @argv.join(' ')
|
15
|
+
# Timestamp added to message
|
16
|
+
message += " #{Time.now.to_s[0..-6]}"
|
17
|
+
|
18
|
+
puts "Committing (versionup =#{bump}) with message: #{message}"
|
19
|
+
|
20
|
+
case bump
|
21
|
+
when 1..9
|
22
|
+
system %Q[rake version:bump:patch]
|
23
|
+
when 10..99
|
24
|
+
system %Q[rake version:bump:minor]
|
25
|
+
when 10..99
|
26
|
+
system %Q[rake version:bump:major]
|
27
|
+
end
|
28
|
+
system %Q[git add --all]
|
29
|
+
system %Q[git commit -a -m "#{message}" --author arvicco]
|
30
|
+
system %Q[git push]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/my_scripts/jew.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# This script uses Jeweler to create new project skeleton, local git repo and
|
3
|
-
# initiate remote repo on github
|
4
|
-
#
|
5
|
-
class Jew < Script
|
6
|
-
def run
|
7
|
-
usage "project_name Summary or description goes here" if @argv.empty?
|
8
|
-
|
9
|
-
# First Arg should be project name
|
10
|
-
project = @argv.shift
|
11
|
-
|
12
|
-
# All the other args lumped into summary, or default summary
|
13
|
-
summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
|
14
|
-
|
15
|
-
puts "Creating Jeweler project #{project} with summary/description: #{summary}"
|
16
|
-
|
17
|
-
system %Q[jeweler --rspec --cucumber --create-repo --summary "#{summary}" --description "#{summary}" #{project}]
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# This script uses Jeweler to create new project skeleton, local git repo and
|
3
|
+
# initiate remote repo on github
|
4
|
+
#
|
5
|
+
class Jew < Script
|
6
|
+
def run
|
7
|
+
usage "project_name Summary or description goes here" if @argv.empty?
|
8
|
+
|
9
|
+
# First Arg should be project name
|
10
|
+
project = @argv.shift
|
11
|
+
|
12
|
+
# All the other args lumped into summary, or default summary
|
13
|
+
summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
|
14
|
+
|
15
|
+
puts "Creating Jeweler project #{project} with summary/description: #{summary}"
|
16
|
+
|
17
|
+
system %Q[jeweler --rspec --cucumber --create-repo --summary "#{summary}" --description "#{summary}" #{project}]
|
18
|
+
end
|
19
|
+
end
|
20
20
|
end
|
data/lib/my_scripts/mybones.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
module MyScripts
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def run
|
7
|
-
usage "project_name Summary or description goes here" if @argv.empty?
|
8
|
-
|
9
|
-
# First Arg should be project name
|
10
|
-
project = @argv.shift
|
11
|
-
|
12
|
-
# All the other args lumped into summary, or default summary
|
13
|
-
summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
|
14
|
-
|
15
|
-
puts "Creating Bones project #{project} with summary: #{summary}"
|
16
|
-
|
17
|
-
system %Q[bones create --github "#{summary}" -s basic #{project}]
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# This script uses Mr.Bones gem to create new project skeleton, local git repo and
|
3
|
+
# initiate remote repo on github
|
4
|
+
#
|
5
|
+
class Mybones < Script
|
6
|
+
def run
|
7
|
+
usage "project_name Summary or description goes here" if @argv.empty?
|
8
|
+
|
9
|
+
# First Arg should be project name
|
10
|
+
project = @argv.shift
|
11
|
+
|
12
|
+
# All the other args lumped into summary, or default summary
|
13
|
+
summary = @argv.empty? ? "New project #{project}" : @argv.join(' ')
|
14
|
+
|
15
|
+
puts "Creating Bones project #{project} with summary: #{summary}"
|
16
|
+
|
17
|
+
system %Q[bones create --github "#{summary}" -s basic #{project}]
|
18
|
+
end
|
19
|
+
end
|
20
20
|
end
|
data/lib/my_scripts/rabbit.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# Starts and controls rabbitmq server
|
3
|
-
class Rabbit < Script
|
4
|
-
def run
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# Starts and controls rabbitmq server
|
3
|
+
class Rabbit < Script
|
4
|
+
def run
|
5
|
+
rabbit_hole = ENV['ERLANG_HOME'] + '/lib/rabbitmq_server-1.7.0/sbin'
|
6
|
+
case @argv.shift
|
7
|
+
when /start/
|
8
|
+
system "#{rabbit_hole}/rabbitmq-server.bat #{@argv.join(' ')}"
|
9
|
+
when /stop/
|
10
|
+
system "#{rabbit_hole}/rabbitmqctl.bat stop #{@argv.join(' ')}"
|
11
|
+
when /ctl/
|
12
|
+
system "#{rabbit_hole}/rabbitmqctl.bat #{@argv.join(' ')}"
|
13
|
+
else
|
14
|
+
usage ["start [args] - starts rabbitmq node", "stop [args] - stops running rabbitmq node",
|
15
|
+
"ctl [args] - controls rabbitmq node"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/my_scripts/script.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
module MyScripts
|
2
|
-
# Base class for all scripts. Subclass it and override run method with actual
|
3
|
-
# work your script will be doing
|
4
|
-
class Script
|
5
|
-
def initialize( name, argv, cli )
|
6
|
-
@name = name
|
7
|
-
@argv = argv
|
8
|
-
@cli = cli
|
9
|
-
end
|
10
|
-
|
11
|
-
def run
|
12
|
-
end
|
13
|
-
|
14
|
-
def puts *args
|
15
|
-
@cli.stdout.puts *args
|
16
|
-
end
|
17
|
-
|
18
|
-
def usage examples, explanation = nil
|
19
|
-
puts "Usage:"
|
20
|
-
puts (examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| " #{@name} #{line}"}
|
21
|
-
puts explanation if explanation
|
22
|
-
exit 1
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
"#{@name} #{@argv.join(' ')} -> #{self.class}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
module MyScripts
|
2
|
+
# Base class for all scripts. Subclass it and override run method with actual
|
3
|
+
# work your script will be doing
|
4
|
+
class Script
|
5
|
+
def initialize( name, argv, cli )
|
6
|
+
@name = name
|
7
|
+
@argv = argv
|
8
|
+
@cli = cli
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
end
|
13
|
+
|
14
|
+
def puts *args
|
15
|
+
@cli.stdout.puts *args
|
16
|
+
end
|
17
|
+
|
18
|
+
def usage examples, explanation = nil
|
19
|
+
puts "Usage:"
|
20
|
+
puts (examples.respond_to?(:split) ? examples.split("\n") : examples).map {|line| " #{@name} #{line}"}
|
21
|
+
puts explanation if explanation
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"#{@name} #{@argv.join(' ')} -> #{self.class}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MyScripts
|
2
|
+
# This script prevents screen saver from locking down Windows by randomly moving
|
3
|
+
# mouse pointer a bit every 4 minutes or so. Why would you need this? Well, if your
|
4
|
+
# XP box is in a domain with security-crazy admins who have immutable policy of
|
5
|
+
# forced screen saver after 5 minutes of inactivity you'd feel the pain...
|
6
|
+
#
|
7
|
+
class Wake < Script
|
8
|
+
SLEEP_TIME = 4 * 60 # seconds
|
9
|
+
|
10
|
+
def initialize( name, argv, cli )
|
11
|
+
|
12
|
+
require 'win/gui/input'
|
13
|
+
|
14
|
+
define_method :move_mouse_randomly do
|
15
|
+
x, y = Win::Gui::Input::get_cursor_pos
|
16
|
+
x1, y1 = x+rand(3)-1, y+rand(3)-1
|
17
|
+
Win::Gui::Input::mouse_event(Win::Gui::Input::MOUSEEVENTF_ABSOLUTE, x1, y1, 0, 0)
|
18
|
+
puts "Cursor positon set to #{x1}, #{y1}"
|
19
|
+
end
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
case @argv.size
|
26
|
+
when 0
|
27
|
+
sleep_time = SLEEP_TIME
|
28
|
+
when 1
|
29
|
+
sleep_time = @argv.first * 60
|
30
|
+
else
|
31
|
+
usage "[minutes] - prevents screen auto lock-up by moving mouse pointer every (4) [minutes]"
|
32
|
+
end
|
33
|
+
|
34
|
+
loop do
|
35
|
+
move_mouse_randomly
|
36
|
+
sleep sleep_time
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|