Skip to content

Instantly share code, notes, and snippets.

View fidelisrafael's full-sized avatar
🏠
Working from home

Rafael Fidelis fidelisrafael

🏠
Working from home
  • Brasil
  • 22:30 (UTC -03:00)
View GitHub Profile
@fidelisrafael
fidelisrafael / has_and_belongs_to_many.rb
Last active September 2, 2015 12:40
Course x Discipline
# course.rb
# rails g model course title:string
class Course < ActiveRecord::Base
has_and_belongs_to_many :disciplines
scope :programming, -> {
where("title LIKE ?", '%Programming%')
}
end
@fidelisrafael
fidelisrafael / dls.rb
Created August 30, 2015 16:02
Simple DSL
module MyCusthomMethods
def after(action_name, &block)
puts "(before) after action #{action_name}"
instance_eval(&block)
puts "(after) after action #{action_name}"
end
def deploy!
@fidelisrafael
fidelisrafael / rspec_model_testing_template.rb
Last active September 16, 2015 19:47
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@fidelisrafael
fidelisrafael / ruby_csr_example.rb
Last active April 29, 2016 21:04 — forked from mitfik/ruby_csr_example.rb
Ruby example of CSR with openssl
require 'openssl'
def gen_key(name)
key = OpenSSL::PKey::RSA.new 1048
file = File.new(name, "w")
file.write(key)
file.close
end
def get_key(name)
@fidelisrafael
fidelisrafael / Rakefile
Created May 5, 2016 18:43 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@fidelisrafael
fidelisrafael / gist:f63827e5ddac047cde6536998110aace
Created May 9, 2016 21:08 — forked from mikestone14/gist:11198630
Getting a GoDaddy domain to point to a Heroku app.
@fidelisrafael
fidelisrafael / nginx_parser_log.rb
Last active November 17, 2019 08:45
Nginx Logger Parser for Ruby
require 'pry'
require 'json'
require 'uri'
module Application
class NginxLogParser
DEFAULT_FORMAT_REGEXP = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s?\-\s?-\s?\[(\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\]\s?\\?"?(GET|POST|PUT|HEAD|DELETE|OPTIONS)\s?(.*?)\s(HTTP\/\d\.\d)\\?"?\s?(\d{3})\s?(\d+)\s?\\?\"\-\\?\"\s?\\?\"(.*?)\"/i
REQUEST_FORMAT = [
@fidelisrafael
fidelisrafael / br_documents.rb
Last active June 27, 2016 22:43
CPF & CNPJ validator and formatter
require './documents/base'
require './documents/cpf'
require './documents/cnpj'
module BRDocuments
VERSION = '0.0.1'
end
@fidelisrafael
fidelisrafael / albums_programming.md
Last active June 30, 2016 20:04
My top 10 of all best albums for turning music in code!

Best albums for coding (IMHO)

#1 - SBTRKT - SBTRKT (2011)

Of course I will start this list with one debut album, this self-titled album by SBTRKT(pronounced as "Subtract") is a masterpiece!!!!
A wonderful reunion of great collaborators, most of the songs has Sampa contrib in vocal, when you hear the voice of this guy for the first time, you find yourself addicted to it!
Theres a track called Ready Set Loop, I always read as Read Eval Print Loop(REPL - that kind of interactive shell you have in your programming language, such as irb, node, python, php)

@fidelisrafael
fidelisrafael / dropkick.sh
Created June 30, 2016 21:43
Turn off spy cams in airbnb rentals
#!/bin/bash
#
# DROPKICK.SH
#
# Detect and Disconnect the DropCam and Withings devices some people are using to
# spy on guests in their home, especially in AirBnB rentals. Based on Glasshole.sh:
#
# http://julianoliver.com/output/log_2014-05-30_20-52
#
# This script was named by Adam Harvey (http://ahprojects.com), who also