Skip to content

Instantly share code, notes, and snippets.

View CristalT's full-sized avatar

Marcelo Forclaz CristalT

View GitHub Profile
@CristalT
CristalT / env-parser
Last active December 28, 2021 16:01
Converts string values into native types for .env values
const env = (key, defaultValue = null) => {
const value = process.env[key] ?? defaultValue;
switch (String(value).toLowerCase()) {
case 'true' || '(true)':
return true;
case 'false' || '(false)':
return false;
case 'empty' || '(empty)':
return '';
case 'null' || '(null)':
$ch = curl_init();
$options = [
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
@CristalT
CristalT / cropimg.php
Last active December 30, 2019 20:41
Recorta los espacios vacíos de una imagen PNG y la guarda como JPG.
$png = 'image/path/filename.png';
$img = imagecreatefrompng($png);
//find the size of the borders
$b_top = 0;
$b_btm = 0;
$b_lft = 0;
$b_rt = 0;
//top
/**
* With axios agent
*/
axios({
url: 'url',
method: 'POST',
responseType: 'blob'
}).then(res => {
const fileURL = URL.createObjectURL(res.data);
window.open(fileURL);
await this.$axios({
url: 'apiurl',
method: 'POST',
responseType: 'blob',
data: payload
}).then(res => {
const fileURL = URL.createObjectURL(res.data);
window.open(fileURL);
})
@CristalT
CristalT / datepicker.vue
Created September 25, 2019 12:37
Componente Datepicker para quasar >= v1
<template>
<div>
<q-input
:outlined="outlined"
:dense="dense"
:filled="filled"
:class="inputClass"
:label="label"
:value="value"
mask="##/##/####"
@CristalT
CristalT / AutocompleteComponent.vue
Created August 28, 2019 14:54
## Componente Autocomplete para Vuejs. Reemplaza el Datalist HTML5 que presenta algunos problemas entre navegadores. ### Propiedades - input-class: clase css que se aplica al input text donde se realiza la búsqueda - placeholder: texto de campo vac
<template>
<div>
<div v-if="!loading">
<input
type="text"
:class="inputClass"
:placeholder="placeholder"
v-model="terms"
@focus="resetStatus"
@CristalT
CristalT / mail-test.php
Created July 22, 2019 21:33
Ejemplo de envío de mail para aplicaciones alojadas en donweb.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
const merged = [].concat.apply([], arrays)
/**
* @param data Object[] Ej.: [{ nombre: Marcelo, apellido: Forclaz }]
* @param fields Array Ej.: ['nombre', 'apellido']
* @param columns Array Ej.: ['Nombre', 'Apellido']
* @param filename String Ej.: 'archivo.csv'
* */
const generateCsv = (data, fields, columns, filename) => {
let csv = 'data:text/csv;charset=utf-8,'
csv += '"' + columnNames.join('","') + '"\n';