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 / bcrypt.go
Last active July 29, 2021 21:13 — forked from manishtpatel/main.go
encrypt data!
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func main() {
pass := []byte("pa$$w0rd")
@rafaelsq
rafaelsq / canvasDataToJPG.py
Last active September 10, 2015 17:25
Canvas Data to JPG
# -*- coding:utf-8 -*-
from cStringIO import StringIO
from PIL import Image
def _saveAsPNG(data, path):
output = open(path, 'wb')
output.write(data)
output.close()
@rafaelsq
rafaelsq / GCM.js
Last active January 3, 2020 00:12
WebCrypto - PBKDF2-HMAC-256 + encode AES-CBC/AES-GCM
export const EncodeGCM = (pass, salt, iv, iterations, data) =>
new window.Promise((ok, fail) => {
pbkdf2(strToBuf(pass), salt, iterations, 'SHA-256', 'AES-GCM')
.then(key => {
const chunkSize = 2 << 10
let len = data.byteLength / chunkSize + (data.byteLength % chunkSize ? 1 : 0) | 0
let out = new window.Uint8Array([...salt, ...iv])
for (let i = 0; i < len; i++) {
@rafaelsq
rafaelsq / content_editable.js
Created April 12, 2017 16:24
Vue ContentEditable
export default {
name: 'content_editable',
template: '<div ref="element" v-html="text"></div>',
props: {
text: [String],
customTag: [String],
},
mounted: function() {
let newElement = document.createElement(this.customTag || 'div')
@rafaelsq
rafaelsq / proxy.go
Created June 19, 2017 14:10
Golang Simple Proxy
package main
import (
"fmt"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
@rafaelsq
rafaelsq / svg_to_png.js
Last active October 25, 2021 22:02
SVG to Base64 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 / parseJWT.js
Created August 22, 2017 14:38
Parse JWT base64 string
const parseJwt = token => JSON.parse(window.atob(token.split('.')[1].replace('-', '+').replace('_', '/')))
@rafaelsq
rafaelsq / main.go
Created January 30, 2018 15:31
Hide terminal input
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
)
func raw(start bool) error {
@rafaelsq
rafaelsq / .eslintrc.js
Last active August 29, 2018 13:40
ESLint + Prettier
module.exports = {
extends: 'eslint:recommended',
env: {
browser: true,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true,
},
@rafaelsq
rafaelsq / MultiWriter.go
Last active September 20, 2019 11:55
io.MultiWriter example with cancelable context
package main
import (
"context"
"fmt"
"io"
"math/rand"
"os"
"sync"
"time"