Skip to content

Instantly share code, notes, and snippets.

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

Marco Rojo mrmarcondes

🏠
Working from home
View GitHub Profile
@mrmarcondes
mrmarcondes / README.md
Created April 9, 2021 15:31 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

storage = Google::Cloud::Storage.new(
project_id: ENV['GOOGLE_STORAGE_BUCKET'],
credentials: JSON.parse(ENV['GOOGLE_CREDENTIALS_FILE']),
timeout: 1_000_000
)
bucket = storage.bucket ENV['BUCKET']
files = bucket.files prefix: ENV['INTERVAL']
files.each do |file|
downloaded = file.download
@mrmarcondes
mrmarcondes / gist:21a790e1505f607ac34d
Created February 26, 2016 18:52
Certificado A3 + El Captain + Firefox
Safenet Driver: https://site.solutinet.com.br/2015/manuais/instaladores/
Instruções: http://drivers.certisign.com.br/midias/tokens/safenet/Macintosh/utilizacao_do_certificado_tipo_A3_com_SafeNet.pdf
require 'aws-sdk'
# Copy an AWS S3 object from one bucket to another
class CopyObjectFromOneBucketToAnotherService
attr_reader :logger, :object_name, :object_to_copy, :destination_bucket
attr_accessor :debug
def initialize(options = {})
create_logger(STDOUT)
Aws.config.update(
@mrmarcondes
mrmarcondes / question2.js
Created December 11, 2012 21:05
10gen: M101 MongoDB for Developers - Final - question 2
db.messages.aggregate([
{$project: {"_id": 0,
"headers.From": 1,
"headers.To": 1
}},
{$unwind: "$headers.To"},
{$group: {
"_id": {from: "$headers.From",
to: "$headers.To"},
sum: {"$sum": 1}
@mrmarcondes
mrmarcondes / homework5.js
Created November 30, 2012 19:48
10gen: M101 MongoDB for Developers - Homework 5.1 - 5.4
// homework 5.1
db.posts.aggregate([
{$project: {"_id": 0,
"comments.author": 1
}},
{$unwind: "$comments"},
{$group: {"_id": "$comments.author",
sum: {"$sum": 1}
}},
{$sort: {"sum": -1}},
@mrmarcondes
mrmarcondes / remove_lowest_homework_by_student.rb
Created November 17, 2012 16:27
10gen: M101 MongoDB for Developers - Homework 3.1
require 'mongo'
#ruby
connection = Mongo::Connection.new
db = connection.db("school")
students = db.collection("students").find().sort({student_id:1})
student_id = -1
while students.has_next? do
student = students.next
if student_id != student["_id"]
@mrmarcondes
mrmarcondes / Homework_2.2.rb
Last active October 12, 2015 11:08
10gen: M101 MongoDB for Developers - Homework 2.2
#ruby
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'm101')
grades = client[:grades].find("type" => "homework").sort({student_id:1, score:1})
student_id = nil
grades.each do |grade|
if student_id != grade["student_id"]
student_id = grade["student_id"]
client[:grades].find(_id: grade[:_id]).delete_one
end
@mrmarcondes
mrmarcondes / instrucoes.rdoc
Created September 25, 2012 13:57
Instruções para OneTarget

Instruções e configurações para utilização do OneTarget

  • Baixar o arquivo ot.js fornecido pela equipe OneTarget;

  • Colocar a instrução para o ot.js bem abaixo do elemento HTML body, como no exemplo:

    <body>
      <script type="text/javascript" src="ot.js"></script>
      ...
    </body>

Capturando pageviews

  • No elemento HTML body, acrescentar “class=cl_nome-de-uma-categoria-qualquer”, como por exemplo:

@mrmarcondes
mrmarcondes / participantes.js
Created September 22, 2012 14:50
Lista de participantes de uma pesquisa online
{"_id": "1", "nome": "Primeiro Participante", "cidade": "São Paulo", "estado": "SP"}
{"_id": "2", "nome": "Segundo Participante", "cidade": "São Paulo", "estado": "SP"}
{"_id": "3", "nome": "Terceiro Participante", "cidade": "Rio de Janeiro", "estado": "RJ"}
{"_id": "4", "nome": "Quarto Participante", "cidade": "Petrópolis", "estado": "RJ"}
{"_id": "5", "nome": "Quinto Participante", "cidade": "Marília", "estado": "SP"}
{"_id": "6", "nome": "Sexto Participante", "cidade": "Curitiba", "estado": "PR"}
{"_id": "7", "nome": "Sétimo Participante", "cidade": "Florianópolis", "estado": "SC"}
{"_id": "8", "nome": "Oitavo Participante", "cidade": "Jaraguá do Sul", "estado": "SC"}
{"_id": "9", "nome": "Nono Participante", "cidade": "Laguna", "estado": "SC"}
{"_id": "10", "nome": "Décimo Participante", "cidade": "Bauru", "estado": "SP"}