Skip to content

Instantly share code, notes, and snippets.

View mergulhao's full-sized avatar

Sylvestre Mergulhão mergulhao

View GitHub Profile
class Linkedin
include HTTParty
base_uri 'https://api.linkedin.com/v2'
def initialize(token)
@token = token
end
def me
self.class.get('/me', options)
@mergulhao
mergulhao / gist:6269789
Last active April 6, 2017 13:33
How to convert a PFX ssl certificate to PEM? If you are in Brazil and buy an A1 (e-CNPJ) certificate from CertSign it comes as a PFX. We need to convert it to PEM format so we can use the certificate to sign documents electronically and use it to access a lot of APIs, incluing NFe.
### pfx to pem, complete edition:
$ openssl pkcs12 -in filename.pfx -nocerts -out key.pem
$ openssl pkcs12 -in filename.pfx -clcerts -nokeys -out cert.pem
$ openssl pkcs12 -in filename.pfx -cacerts -out ca_cert.pem
@mergulhao
mergulhao / gist:4349475
Created December 20, 2012 23:15
Stats do projeto Orçamento Rápido, realizado num Startup DEV. http://startupdev.com.br/
ruby-1.9.3@orcamentorapido mergulhao@darkstar:~/code/startupdev/orcamentorapido(master)$ rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 134 | 126 | 6 | 21 | 3 | 4 |
| Helpers | 2 | 2 | 0 | 0 | 0 | 0 |
| Models | 168 | 146 | 8 | 14 | 1 | 8 |
| Libraries | 15 | 13 | 0 | 1 | 0 | 11 |
| Model specs | 451 | 439 | 0 | 2 | 0 | 217 |
| Controller specs | 540 | 530 | 0 | 24 | 0 | 20 |
@mergulhao
mergulhao / gist:4158386
Created November 28, 2012 01:16
Cursor rápido no Mac OSX
# Basta rodar os 2 comandos abaixo no console e reiniciar.
# Mais coisas legais em https://gist.github.com/2260182
defaults write NSGlobalDomain KeyRepeat -int 0.02
defaults write NSGlobalDomain InitialKeyRepeat -int 12
@mergulhao
mergulhao / user_spec.rb
Created October 18, 2012 16:00
Testing scopes with rspec
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe User do
describe :scopes do
describe :want_email_notifications do
create!(:user__want) { {email_notifications: true} }
create!(:user__notwant) { {email_notifications: false} }
subject { User.want_email_notifications }
it { should include(user__want) }
# -*- encoding : utf-8 -*-
require "spec_helper"
describe Notification do
describe "new_question" do
let(:user) { Factory.create(:user, name: 'Dart Vader', email: 'dart@example.com') }
let(:category) { Factory.create(:category, name: 'Saúde') }
let(:owner) { Factory.create(:user, name: 'Jaspion') }
let(:question) { Factory.create(:question, user: owner, category: category) }
let(:mailer) { Notification.new_question(question.id, user.id) }
@mergulhao
mergulhao / base_job.rb
Created July 27, 2012 19:33
DelayJob with Airbrake exception catch
class BaseJob < Struct.new(:params)
def perform
send(params[:action])
rescue Exception => exception
Airbrake.notify(exception, {
api_key: ENV['AIRBRAKE_API_KEY']
})
raise exception
end
end
@mergulhao
mergulhao / gist:3088055
Created July 11, 2012 04:36 — forked from metaskills/gist:756111
Rails 3 Models To Export Mephisto To Jekyll & Disqus
require 'builder'
require 'digest/md5'
class Content < ActiveRecord::Base
belongs_to :user
end
class Section < ActiveRecord::Base
has_many :assigned_sections
has_many :articles, :order => 'position', :through => :assigned_sections
@mergulhao
mergulhao / .rvmrc
Created March 21, 2012 20:58
Rake de deploy para o Heroku
export AMAZON_S3_BUCKET=mybucket-development
export AMAZON_ACCESS_KEY_ID=xxx
export AMAZON_SECRET_ACCESS_KEY=xxx
rvm 1.9.2@nome-da-app --create
# FIX for this issue
# https://github.com/thoughtbot/shoulda-matchers/commit/6b4035c11783a0588e78d3705bb9425b9b5f45b8
Shoulda::Matchers::ActiveRecord::AssociationMatcher.class_eval do
protected
def foreign_key
reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name
end
end