Skip to content

Instantly share code, notes, and snippets.

View marcelobbfonseca's full-sized avatar
🎯
Focusing

Marcelo marcelobbfonseca

🎯
Focusing
View GitHub Profile
@marcelobbfonseca
marcelobbfonseca / middleware.js
Last active September 18, 2020 12:42
ExpressJS JWT authentication middleware example
// JWT authentication middleware example.
// Uses RS256 strategy with .pem key pair files.
const fs = require('fs');
const jwt = require('jsonwebtoken');
module.exports = (req, res, next) => {
let publicKey = process.env.PUBLIC_KEY;
@marcelobbfonseca
marcelobbfonseca / Terminal
Created February 22, 2019 13:51
Generate RSA key pair with OpenSSL
$ openssl genrsa -des3 -out private.pem 2048
$ openssl rsa -in private.pem -outform PEM -pubout -out public.pem
@marcelobbfonseca
marcelobbfonseca / middleware.rb
Last active September 27, 2023 02:36
Sinatra ruby JWT authentication middleware
# To connect this middleware.rb file to your sinatra app
# add 'use JWTAuthorization' as one of your first lines in
# your Application class.
# e.g.
# require 'middlewares.rb'
# class Application < Sinatra::Base
# use JWTAuthorization
# ...
# end
@marcelobbfonseca
marcelobbfonseca / users.js
Last active September 18, 2020 12:41
ExpressJS user sign-in route with JWT RSA algorithm example
// User sign-in route with JWT RSA algorithm example
var User = require('../models/user')
var express = require('express');
var router = express.Router();
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const fs = require('fs');
@marcelobbfonseca
marcelobbfonseca / models.py
Last active April 25, 2020 23:38
Django model find by name example
from django.db import models
class Something(models.Model):
name = models.CharField(max_length=200)
@staticmethod
def find_by_name(name):
try:
something = Something.objects.get(name=name)
@marcelobbfonseca
marcelobbfonseca / software_update.py
Last active April 1, 2021 02:38
Python april fool prank
# pip install pyautogui
# pip install pyobjc-core
# pip install pyobjc
# python3 software_update.py
# Opens baby shark And mouse will freak out.
import time
import random
import pyautogui
import webbrowser
@marcelobbfonseca
marcelobbfonseca / .coveragerc
Created April 1, 2019 20:01
configuration file example for coverage.py. A python code coverage library https://coverage.readthedocs.io/en/v4.5.x/ for more info
# .coveragerc to control coverage.py
[run]
branch = True
omit =
my_env/*
*/migrations/*
*/__init__.py
[report]
@marcelobbfonseca
marcelobbfonseca / Dockerfile
Created May 13, 2019 22:16
Both Dockerfile and docker-compose example files for a regular python Flask and postgresql environment
FROM python:3.7.3-stretch
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
EXPOSE 5000
@marcelobbfonseca
marcelobbfonseca / Dockerfile
Created May 14, 2019 13:56
Dockerfile and docker-compose development example configuration for python Django+postgresql environment. Application runs on port 3000
FROM python:3.7.3-stretch
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
EXPOSE 3000
@marcelobbfonseca
marcelobbfonseca / LaravuePostgisCIExample.yaml
Created September 23, 2019 14:25
Working Github actions CI example for Laravel+Vue+Postgis project
name: LaravuePostgisCIExample
on:
push:
branches:
- master
- stage
pull_request:
branches:
- stage