Skip to content

Instantly share code, notes, and snippets.

View rodrigopinto's full-sized avatar

Rodrigo Pinto rodrigopinto

  • Berlin, Germany
  • 07:51 (UTC +01:00)
View GitHub Profile
#Colors
NO_COLOR="\[\e[0m\]"
BLACK="\[\033[0;30m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
MAGENTA="\[\033[0;35m\]"
CYAN="\[\033[0;36m\]"
WHITE="\[\033[0;37m\]"
@rodrigopinto
rodrigopinto / 2012-04-24
Created May 2, 2012 13:41
code coverage and refactory evolution
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 233 | 203 | 3 | 19 | 6 | 8 |
| Helpers | 4 | 4 | 0 | 0 | 0 | 0 |
| Models | 93 | 71 | 6 | 8 | 1 | 6 |
| Libraries | 651 | 554 | 24 | 79 | 3 | 5 |
| Integration tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Functional tests | 7 | 3 | 1 | 0 | 0 | 0 |
| Unit tests | 99 | 66 | 7 | 0 | 0 | 0 |
@rodrigopinto
rodrigopinto / photo_duplication_verify.rb
Created June 2, 2012 18:28
script pra verificar fotos duplicadas
allowed_dirs = Dir["/Users/homedir/Pictures/*"].select { |dir| dir if dir.match(/(au)/) }
allowed_dirs.each do |current_directory|
allowed_dirs.each do |another_directory|
next if current_directory == another_directory
Dir["#{current_directory}/*"].each do |current_photo|
Dir["#{another_directory}/*"].each do |another_photo|
puts ">> Current: #{current_photo} == Another: #{another_photo}" if current_photo == another_photo
end
end
@rodrigopinto
rodrigopinto / Command
Created June 4, 2012 20:10
Generate a rails app with mongodb
#start a rails app without activerecord
rails new app_name --skip-active-record
# Start rspec configuration
rails g rspec:install
# Generate mongo configuration
rails g mongoid:config
@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)
@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
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
desc 'Run factory specs.'
RSpec::Core::RakeTask.new(:factory_specs) do |t|
t.pattern = './spec/factories_spec.rb'
end
task spec: :factory_specs
@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
class Game
#...
def print_average_game_rating
if ratings_count == 0
"Nota média:"
else
"Nota média: #{average_game_rating}"
end
end
end