Skip to content

Instantly share code, notes, and snippets.

View rodrigopinto's full-sized avatar

Rodrigo Pinto rodrigopinto

  • Berlin, Germany
  • 08:38 (UTC +02:00)
View GitHub Profile
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"
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 }
@rodrigopinto
rodrigopinto / rm-collaborator-on-codeplane.rb
Created December 12, 2012 15:52
Remove collaborator from all repos on codeplane!!!
# 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
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)
class Game
#...
def print_average_game_rating
if ratings_count == 0
"Nota média:"
else
"Nota média: #{average_game_rating}"
end
end
end
@rodrigopinto
rodrigopinto / spec_helper.rb
Created October 25, 2012 15:53 — forked from caike/spec_helper.rb
missing translations
##
# 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
desc 'Run factory specs.'
RSpec::Core::RakeTask.new(:factory_specs) do |t|
t.pattern = './spec/factories_spec.rb'
end
task spec: :factory_specs
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
@rodrigopinto
rodrigopinto / parser_worker.rb
Created June 15, 2012 22:02
design code suggestions?
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
@rodrigopinto
rodrigopinto / ideia_de_parser.rb
Created June 14, 2012 14:34
Ideia cru de como implementar os parses independente de ORM
class ToolParser
def to_json
self.to_json
end
def to_hash # or attributes
self.to_hash
end
def execute(xml)