This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
attr_accessor :first_name, :last_name | |
end | |
# sem o método tap | |
user = User.new | |
user.first_name = "Rodrigo" | |
user.last_name = "Pinto" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NumberPercentageExtension | |
module InstanceMethods | |
# the idea converting english to numbers taken from http://www.ruby-forum.com/topic/132735#591799 | |
ENGLISH_VALUE = {} | |
%w| zero one two three four five six seven eight nine ten eleven | |
twelve thirteen fourteen fifteen sixteen seventeen eighteen | |
nineteen |.each_with_index{ |word,i| ENGLISH_VALUE[word] = i } | |
%w| zero ten twenty thirty forty fifty sixty seventy eighty | |
ninety|.each_with_index{ |word,i| ENGLISH_VALUE[word] = i*10 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'codeplane' | |
Codeplane.configure do |config| | |
config.username = ENV['username'] | |
config.api_key = ENV['cp_api_key'] | |
end | |
cp = Codeplane::Client.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rows_msg(number) | |
(number >= 9000)? "already hit 9000 rows" : "has #{number} rows" | |
end | |
rows = `heroku pg:info --app managerbook|grep Rows` | |
result = rows.match(/(\d+)/)[1].to_i | |
puts "Your app 'managerbook' %s" % rows_msg(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Game | |
#... | |
def print_average_game_rating | |
if ratings_count == 0 | |
"Nota média:" | |
else | |
"Nota média: #{average_game_rating}" | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Raises error if missing translation key | |
## | |
config.before(:all, type: :controller) do | |
@_i18n_exception_handler = I18n.exception_handler | |
I18n.exception_handler = lambda { |*args| raise args.first.to_s } | |
end | |
config.after(:all, type: :controller) do | |
I18n.exception_handler = @_i18n_exception_handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Run factory specs.' | |
RSpec::Core::RakeTask.new(:factory_specs) do |t| | |
t.pattern = './spec/factories_spec.rb' | |
end | |
task spec: :factory_specs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ToolParserWorker | |
include Sidekiq::Worker | |
def perform(scan) | |
## On a near futute NessusParser will die an become a ParserFactory based on scan tool type | |
report = NessusParser.execute(self.file.current_path) # execute returns a Report object | |
scan.update_parsed_report(report.to_json) # scan is mongo document | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ToolParser | |
def to_json | |
self.to_json | |
end | |
def to_hash # or attributes | |
self.to_hash | |
end | |
def execute(xml) |