Skip to content

Instantly share code, notes, and snippets.

View fdorantesm's full-sized avatar

Fernando Dorantes fdorantesm

View GitHub Profile
@fdorantesm
fdorantesm / conekta.js
Created August 31, 2019 06:34
Conekta Tokenizer
if (process.client) {
if (window.Conekta) {
window.Conekta.setPublicKey('key_AVyNyZZdY5AsiEEvhpm5crA')
}
}
export default class ConektaService {
static createToken (tokenParams) {
const response = new Promise((resolve, reject) => {
if (!window.Conekta.card.validateNumber(tokenParams.card.number)) {
@fdorantesm
fdorantesm / functions.php
Created August 26, 2019 15:56
Convert base64 to image and validation helpers
function base64ToImage($imageData, $path){
$data = 'data:image/png;base64,AAAFBfj42Pj4';
list($type, $imageData) = explode(';', $imageData);
list(,$extension) = explode('/',$type);
list(,$imageData) = explode(',', $imageData);
$fileName = uniqid().'.'.$extension;
$imageData = base64_decode($imageData);
file_put_contents($path."/".$fileName, $imageData);
return $fileName;
}
@fdorantesm
fdorantesm / token-generator.js
Created July 30, 2019 17:58 — forked from ziluvatar/token-generator.js
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@fdorantesm
fdorantesm / uploader.js
Created May 5, 2019 15:50
Cloudinary uploader
import fs from 'fs'
import streamifier from 'streamifier'
import cloudinary from 'cloudinary'
cloudinary.config({
cloud_name: process.env.CLOUDINARY_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
@fdorantesm
fdorantesm / common.js
Last active March 11, 2019 17:05
Send emails using nodemailer
import fs from 'fs'
const $app = process.env.APP_PATH
const $src = process.env.SRC_PATH
export function view(path) {
const file = `${$app}/views/${path}.pug`
if (fs.existsSync(file)) {
@fdorantesm
fdorantesm / helpers,js
Last active October 2, 2018 17:21
Base64 File helpers
function toBytes(value){
var unit = value.substr(-2)
var size = value.replace(unit, '')
var result
switch(unit){
case 'kb': result = size * 1000; break;
case 'mb': result = size * 1000000; break;
case 'gb': result = size * 1000000000; break;
case 'tb': result = size * 1000000000000; break;
@fdorantesm
fdorantesm / README.md
Created June 13, 2018 15:11 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@fdorantesm
fdorantesm / form-shortcut-submit.js
Created June 4, 2018 19:36
Submit forms with ctrl/cmd + enter
window.addEventListener('load', function(){
forms = document.getElementsByTagName('form')
for (form of forms) {
form.addEventListener('keydown', function(e) {
if (e.keyCode == 13 && e.metaKey) {
$button = form.querySelector('button[type="submit"]')
$button.click()
return false
}
})
@fdorantesm
fdorantesm / media.sass
Last active April 22, 2018 15:38
Media query sass mixin helper
$screen-xs-max: 480px
$screen-sm-min: 481px
$screen-sm-max: 960px
$screen-md-min: 961px
$screen-md-max: 1280px
$screen-lg-min: 1281px
@mixin xs($max-width: true)
@if $max-width
@media only screen and (max-width: $screen-xs-max)
@fdorantesm
fdorantesm / flexbox.css
Last active April 22, 2018 05:41
Grid generator sass mixin
.col {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-preferred-size: 0;
flex-basis: 0;
max-width: 100%;
}
.start-xs {