Skip to content

Instantly share code, notes, and snippets.

View rafaelsq's full-sized avatar
🇧🇷
¯\(°_o)/¯

Rafael Quintela rafaelsq

🇧🇷
¯\(°_o)/¯
View GitHub Profile
@rafaelsq
rafaelsq / main.go
Created June 29, 2022 13:14
httprouter easy middlewares
func main() {
router := httprouter.New()
r := Middlewares{router: router}
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("First Middleware")
next.ServeHTTP(w, r)
})
})
@rafaelsq
rafaelsq / PKCS1v15.go
Last active November 12, 2020 17:25
Encrypt/Decrypt with KeyPair
package main
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"log"
@rafaelsq
rafaelsq / webcryptoapi.html
Created April 23, 2020 12:25 — forked from deiu/webcryptoapi.html
Web Crypto API example: RSA keygen & export & import & sign & verify & encrypt & decrypt
<!-- MIT License -->
<html>
<head>
<script>
function generateKey(alg, scope) {
return new Promise(function(resolve) {
var genkey = crypto.subtle.generateKey(alg, true, scope)
genkey.then(function (pair) {
resolve(pair)
})
@rafaelsq
rafaelsq / svg2png.js
Created February 18, 2020 11:49
SVG to PNG
function svg_to_png(svg, callback) {
var svgData = (new XMLSerializer()).serializeToString(svg);
var canvas = document.createElement("canvas");
var svgSize = svg.getBoundingClientRect();
canvas.width = svgSize.width;
canvas.height = svgSize.height;
var ctx = canvas.getContext("2d");
var img = document.createElement("img");
@rafaelsq
rafaelsq / print-request.go
Last active August 13, 2020 19:15
Print Request
package main
import (
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"os"
)
@rafaelsq
rafaelsq / index.html
Last active June 10, 2024 07:20
TOTP with Web Crypto API
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css">
<title>TOTP</title>
</head>
<body>
<section class="section">
@rafaelsq
rafaelsq / app.py
Created December 17, 2019 13:40
Hello Word with Gunicorn
def app(environ, start_response):
data = bytes("<!DOCTYPE html>\nOlá\n", 'utf-8')
start_response("200 OK", [
["Content-Type", "text/html; charset=utf-8"],
["Content-Length", str(len(data))],
])
return iter([data])
@rafaelsq
rafaelsq / encdec.sh
Last active April 29, 2020 16:36
Encode/Decode file with openssl
#!/bin/bash
echo "limon" > encdec.dec
echo "Encrypt"
openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 10000 -salt -in encdec.dec -out encdec.enc
ls encdec.*
# encdec.enc encdec.dec
@rafaelsq
rafaelsq / pre-push
Last active October 9, 2019 11:54
golangic-lint modified Go files
#!/bin/sh
git diff --name-status --no-renames ss/development | ag -v vendor | ag -v "\.qtpl" | ag -v "/gqlgen.go" | ag -v "^D" | cut -f2 | ag "\.go$" | xargs -r dirname | sort | uniq | xargs -r golangci-lint run --config ${PWD}/.golangci.yml
@rafaelsq
rafaelsq / keybase.md
Created September 12, 2019 19:22
keybase.md

Keybase proof

I hereby claim:

  • I am rafaelsq on github.
  • I am rafaelsq (https://keybase.io/rafaelsq) on keybase.
  • I have a public key ASC51pXT8Rt9W-4OReF1l4nNpfZJcCYIGWsO5gOI-5VNngo

To claim this, I am signing this object: