chid 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +67 -0
- data/README.md +221 -0
- data/Rakefile +17 -0
- data/chid.gemspec +32 -0
- data/etc/img/stack.png +0 -0
- data/lib/chid.rb +100 -0
- data/lib/chid/chid_config.rb +127 -0
- data/lib/chid/currency_api.rb +69 -0
- data/lib/chid/github_api.rb +41 -0
- data/lib/chid/main.rb +112 -0
- data/lib/chid/news_api.rb +60 -0
- data/lib/chid/paginator.rb +57 -0
- data/lib/chid/stack_overflow_api.rb +35 -0
- data/lib/chid/version.rb +3 -0
- data/lib/chid/yandex_translate_api.rb +39 -0
- data/tasks/chid/config.rake +5 -0
- data/tasks/chid/init.rake +19 -0
- data/tasks/chid/start.rake +26 -0
- data/tasks/chid/update.rake +14 -0
- data/tasks/currency/convert.rake +9 -0
- data/tasks/currency/current.rake +11 -0
- data/tasks/currency/list.rake +10 -0
- data/tasks/github.rake +12 -0
- data/tasks/help.rake +8 -0
- data/tasks/install/node.rake +18 -0
- data/tasks/install/postgres.rake +18 -0
- data/tasks/install/rvm.rake +21 -0
- data/tasks/install/yadr_dotfiles.rake +26 -0
- data/tasks/news.rake +11 -0
- data/tasks/run/postgres.rake +12 -0
- data/tasks/stack_overflow.rake +20 -0
- data/tasks/tmux/config_windows.rake +21 -0
- data/tasks/tmux/new_session.rake +10 -0
- data/tasks/translate/yandex_list.rake +7 -0
- data/tasks/translate/yandex_translate.rake +8 -0
- data/tasks/update/os.rake +14 -0
- data/tasks/workstation/create.rake +23 -0
- data/tasks/workstation/destroy.rake +14 -0
- data/tasks/workstation/list.rake +10 -0
- data/tasks/workstation/open.rake +29 -0
- metadata +158 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
class StackOverflowApi
|
2
|
+
|
3
|
+
Question = Struct.new(:title, :creation_date, :link) do
|
4
|
+
def summary
|
5
|
+
published_at = creation_date.nil? ? 'unkown' : creation_date.strftime("%B %d, %Y")
|
6
|
+
print "\n"
|
7
|
+
print "--- #{title} ---".blue
|
8
|
+
print "\n"
|
9
|
+
print " Posted #{published_at} by ".brown
|
10
|
+
print "\n"
|
11
|
+
print " Link: "
|
12
|
+
print "#{link}".cyan.underline
|
13
|
+
print "\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.questions(search)
|
18
|
+
uri = URI("https://api.stackexchange.com/2.2/search/advanced?order=desc&sort=activity&site=stackoverflow&q=#{search}")
|
19
|
+
response = HTTP.get(uri)
|
20
|
+
body_decoded = decode_body(response.body.to_s)
|
21
|
+
json_news = JSON.parse(body_decoded)
|
22
|
+
|
23
|
+
json_news[ 'items' ].collect do |i|
|
24
|
+
Question.new(i['title'], Time.at(i[ 'creation_date' ]), i['link'])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def self.decode_body(body_str)
|
31
|
+
gz = Zlib::GzipReader.new(StringIO.new(body_str))
|
32
|
+
gz.read
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/chid/version.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class YandexTranslateApi
|
2
|
+
API_TOKEN = 'trnsl.1.1.20170318T165136Z.005f29f713d3e410.1d52e55d7e9a3f125e38645215a101e743b16b98'
|
3
|
+
|
4
|
+
def self.translate(options = {})
|
5
|
+
text = options.fetch(:text, "")
|
6
|
+
from = options.fetch(:from, :en).to_sym
|
7
|
+
to = options.fetch(:to, :pt).to_sym
|
8
|
+
|
9
|
+
uri = URI("https://translate.yandex.net/api/v1.5/tr.json/translate?lang=#{from}-#{to}&key=#{API_TOKEN}&text=#{text}")
|
10
|
+
|
11
|
+
response = HTTP.get(uri)
|
12
|
+
json = JSON.parse response
|
13
|
+
json['text'].first
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
puts "Language Code Language Code".green
|
18
|
+
puts "Azerbaijan az Maltese mt"
|
19
|
+
puts "Albanian sq Macedonian mk"
|
20
|
+
puts "Amharic am Maori mi"
|
21
|
+
puts "English en Marathi mr"
|
22
|
+
puts "Armenian hy Mongolian mn"
|
23
|
+
puts "Afrikaans af German de"
|
24
|
+
puts "Bashkir ba Norwegian no"
|
25
|
+
puts "Bulgarian bg Persian fa"
|
26
|
+
puts "Bosnian bs Polish pl"
|
27
|
+
puts "Welsh cy Portuguese pt"
|
28
|
+
puts "Vietnamese vi Russian ru"
|
29
|
+
puts "Italian it Telugu te"
|
30
|
+
puts "Spanish es Udmurt udm"
|
31
|
+
puts "Chinese zh French fr"
|
32
|
+
puts "Xhosa xh Croatian hr"
|
33
|
+
puts "Latin la Czech cs"
|
34
|
+
puts "Latvian lv Swedish sv"
|
35
|
+
puts "Lithuanian lt Scottish gd"
|
36
|
+
puts "Luxembourgish lb Estonian et"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
desc 'Initial configuration for Chid app'
|
2
|
+
task :init do
|
3
|
+
print "Chid is an assistant to help your day-to-day life.\n\n"
|
4
|
+
print "You can use it as "
|
5
|
+
print "a terminal App ".green
|
6
|
+
print "or through "
|
7
|
+
print "Rake Tasks".green
|
8
|
+
print", having a greater interaction with it.\n\n"
|
9
|
+
|
10
|
+
print "To initialize the app you can run the command: "
|
11
|
+
print "$ rake\n".blue
|
12
|
+
print "Or the command: "
|
13
|
+
print "$ chid\n".blue
|
14
|
+
print "But the command "
|
15
|
+
print "$ chid ".blue
|
16
|
+
print "will work after you reload your profile\n"
|
17
|
+
|
18
|
+
@chid_config.configure
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
desc 'Start the Chid app'
|
2
|
+
task :chid do
|
3
|
+
prompt = TTY::Prompt.new(help_color: :green)
|
4
|
+
confirm_install = -> (action, &block) {
|
5
|
+
matched = /^install:(.*)/.match(action)
|
6
|
+
return block.() unless matched
|
7
|
+
|
8
|
+
action_name = matched.captures.first
|
9
|
+
if prompt.yes?("Can I install the #{action_name}?")
|
10
|
+
block.()
|
11
|
+
else
|
12
|
+
puts "\nNo problem. What do you need?"
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
Main.new(@chid_config).init do |action, args|
|
17
|
+
rake_task = Rake::Task[action]
|
18
|
+
task_args = Rake::TaskArguments.new(rake_task.arg_names, args)
|
19
|
+
|
20
|
+
confirm_install.(action) do
|
21
|
+
rake_task.execute(task_args)
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "\nDone! What else?"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :currency do
|
2
|
+
|
3
|
+
desc 'You can convert an amount between types. Eg.: convert 10 USD to BRL'
|
4
|
+
task :convert, [:amount, :from, :to] do |t, args|
|
5
|
+
amount = CurrencyApi.convert(args)
|
6
|
+
puts "The converted #{args[:from]} to #{args[:to]} is: #{amount}"
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
data/tasks/github.rake
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
desc 'List all repositories'
|
2
|
+
task :github, [:search] do |t, args|
|
3
|
+
search_expression = args[:search]
|
4
|
+
|
5
|
+
repositories = GitHubApi.repositories(search_expression)
|
6
|
+
|
7
|
+
Paginator.new(repositories).paginate do |repository|
|
8
|
+
repository.summary
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
data/tasks/help.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :install do
|
2
|
+
|
3
|
+
desc 'Install Node'
|
4
|
+
task :node do
|
5
|
+
puts "\nInstalling the Node..."
|
6
|
+
|
7
|
+
@chid_config.on_linux do
|
8
|
+
system('sudo apt-get install nodejs')
|
9
|
+
end
|
10
|
+
|
11
|
+
@chid_config.on_osx do
|
12
|
+
system('brew install node')
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "\nNode installed successfully"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :install do
|
2
|
+
|
3
|
+
desc 'Install Postgres'
|
4
|
+
task :postgres do
|
5
|
+
puts "\nInstalling the Postgres..."
|
6
|
+
|
7
|
+
@chid_config.on_linux do
|
8
|
+
system('sudo apt-get install postgresql postgresql-contrib')
|
9
|
+
end
|
10
|
+
|
11
|
+
@chid_config.on_osx do
|
12
|
+
system('brew install postgres')
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "\nPostgres installed successfully"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :install do
|
2
|
+
|
3
|
+
desc 'Install RVM'
|
4
|
+
task :rvm do
|
5
|
+
puts "\nInstalling the RVM..."
|
6
|
+
|
7
|
+
@chid_config.on_linux do
|
8
|
+
system('sudo apt-add-repository -y ppa:rael-gc/rvm')
|
9
|
+
system('sudo apt-get update')
|
10
|
+
system('sudo apt-get install curl')
|
11
|
+
system('sudo apt-get install rvm')
|
12
|
+
end
|
13
|
+
|
14
|
+
@chid_config.on_osx do
|
15
|
+
system('\curl -sSL https://get.rvm.io | bash')
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "\nRVM installed successfully"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :install do
|
2
|
+
|
3
|
+
desc 'Install YADR Dotfiles'
|
4
|
+
task :dotfiles do
|
5
|
+
puts "\nInstalling the YADR Dotfiles..."
|
6
|
+
@chid_config.on_linux do
|
7
|
+
system('sudo apt-get update')
|
8
|
+
system('sudo apt-get install curl')
|
9
|
+
system('sudo apt-get install zsh')
|
10
|
+
system('sudo apt-get install git-core')
|
11
|
+
end
|
12
|
+
|
13
|
+
system('sh -c "`curl -fsSL https://raw.githubusercontent.com/skwp/dotfiles/master/install.sh`"')
|
14
|
+
|
15
|
+
puts 'Updating YARD...'
|
16
|
+
path = "#{@chid_config.home_path}/.yadr"
|
17
|
+
Dir.chdir path
|
18
|
+
system('git pull --rebase')
|
19
|
+
system('rake update')
|
20
|
+
|
21
|
+
puts "\nYARD Dotfiles installed successfully"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
data/tasks/news.rake
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
desc 'Search questions in StackOverflow'
|
2
|
+
task :stack, [:search] do |t, args|
|
3
|
+
|
4
|
+
search_param = args[:search]
|
5
|
+
|
6
|
+
unless search_param
|
7
|
+
print "Tell me, what do you want to search?\n".blue
|
8
|
+
print "> "
|
9
|
+
search_param = STDIN.gets.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
questions = StackOverflowApi.questions(search_param)
|
13
|
+
|
14
|
+
Paginator.new(questions).paginate do |question|
|
15
|
+
question.summary
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
desc 'Configure default windows for development'
|
2
|
+
task :tmux_config, [:name] do |t, args|
|
3
|
+
name = args.fetch(:name, 'development')
|
4
|
+
if name == 'development'
|
5
|
+
system("tmux rename-window bash")
|
6
|
+
system("tmux new-window -n app")
|
7
|
+
system("tmux new-window -n server")
|
8
|
+
elsif name == 'stant-api'
|
9
|
+
system("tmux rename-window app")
|
10
|
+
system("tmux new-window -n tests")
|
11
|
+
system("tmux new-window -n server")
|
12
|
+
system("tmux new-window -n bash")
|
13
|
+
elsif name == 'stant-traceability'
|
14
|
+
system("tmux rename-window ios-traceability")
|
15
|
+
system("tmux new-window -n ios-infrastructure")
|
16
|
+
system("tmux new-window -n ios-core")
|
17
|
+
system("tmux new-window -n bash")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :workstation do
|
2
|
+
|
3
|
+
desc 'Create a new workstation'
|
4
|
+
task :create do
|
5
|
+
prompt = TTY::Prompt.new
|
6
|
+
|
7
|
+
puts 'Tell me the name of the new Workstation'
|
8
|
+
print "> "
|
9
|
+
workstation_name = STDIN.gets.strip
|
10
|
+
|
11
|
+
@chid_config.on_osx do
|
12
|
+
choices = %x{ls /Applications}.strip
|
13
|
+
choices = choices
|
14
|
+
.gsub(/\n/, ' - ')
|
15
|
+
.gsub('.app', '')
|
16
|
+
.split(' - ')
|
17
|
+
result = prompt.multi_select('Select all apps for that workstation?', choices)
|
18
|
+
@chid_config.create_workstation(workstation_name, result)
|
19
|
+
puts "\n#{workstation_name} Workstation was created!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :workstation do
|
2
|
+
|
3
|
+
desc 'Destroy workstations'
|
4
|
+
task :destroy do
|
5
|
+
prompt = TTY::Prompt.new
|
6
|
+
workstations = @chid_config.all_workstations
|
7
|
+
choices = workstations.keys
|
8
|
+
result = prompt.multi_select('Select all workstations to destroy', choices)
|
9
|
+
|
10
|
+
@chid_config.destroy_workstations(result)
|
11
|
+
puts "\nWorkstations removed!"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|