Skip to content

Instantly share code, notes, and snippets.

View viceo's full-sized avatar
🇲🇽
Working from home

Leopoldo Muñoz viceo

🇲🇽
Working from home
  • Fermilab
  • Batavia IL
View GitHub Profile
@viceo
viceo / unique elements in a slice
Created August 8, 2023 19:57 — forked from johnwesonga/unique elements in a slice
Go code that ensures elements in a slice are unique
package main
import "fmt"
func uniqueNonEmptyElementsOf(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, len(unique))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
@viceo
viceo / 2019-https-localhost.md
Created October 31, 2022 20:49 — forked from cecilemuller/2019-https-localhost.md
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@viceo
viceo / Formatter.js
Last active January 26, 2024 19:34
Collection of helper functions
class Formatter {
/**
*
* @param {string} x
* Input string
* - 1234-5678-4321-8765
* - $1,111.11
* @param {boolean} isMoney
* Boolean switch, default FALSE
* - If true '.' will be accepted and displayed like 1111.11
@viceo
viceo / README.md
Created October 9, 2021 00:55 — forked from mosquito/README.md
Add doker-compose as a systemd unit

Docker compose as a systemd unit

Create file /etc/systemd/system/docker-compose@.service. SystemD calling binaries using an absolute path. In my case is prefixed by /usr/local/bin, you should use paths specific for your environment.

[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
@viceo
viceo / handler.js
Last active August 24, 2021 21:06
AWS Custom authorizer para limitar 5 accesos por día ... por IP
var aws = require('aws-sdk')
var lambda = new aws.Lambda({ region: 'us-east-2' })
exports.handler = async(event, context, callback) => {
// Función helper: Obtener content type
const getContentType = (event) => {
let contentType = event.headers['content-type']
if (!contentType) {
contentType = event.headers['Content-Type'];
@viceo
viceo / authFlowCognitoReact.js
Last active August 24, 2021 21:14
AWS | Cognito / Amplify | React , logica de auth
const postData = async (values, { setStatus, setSubmitting }) => {
try {
const ping_data = await fetch(`${process.env.REACT_APP_AWS_API_BASE_URL}/auth/ping`, {
method: 'post',
headers: { 'x-api-key': process.env.REACT_APP_AWS_API_X_API_KEY },
body: JSON.stringify({ correoElectronico: values.email })
});
if (ping_data.status !== 200) throw { codigo: 'PING_FALLO', ping_data }
@viceo
viceo / postHttpPromise.js
Last active May 7, 2021 05:10
Promesa HTTP / HTTPS sin librerías externas en NodeJS
// Promesa https
const postHttpsPromise = (body) => {
// Importamos modulo
const https = require('https') // require('http')
// Retornamos promesa
return new Promise((resolve, reject) => {
// Opciones petición
@viceo
viceo / gist:ba0fab957c78d8d6a428b27f5fe121a7
Created March 26, 2021 18:37 — forked from oscar-broman/gist:3653399
UTF8 encode array/object structure in PHP
<?php
function utf8_encode_deep(&$input) {
if (is_string($input)) {
$input = utf8_encode($input);
} else if (is_array($input)) {
foreach ($input as &$value) {
utf8_encode_deep($value);
}
unset($value);
@viceo
viceo / strong-passwords.php
Created March 24, 2021 15:38 — forked from tylerhall/strong-passwords.php
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@viceo
viceo / a2dp.py
Created January 15, 2021 17:27 — forked from pylover/a2dp.py
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04, 16.10 and also debian jessie, with bluez5.
#! /usr/bin/env python3.5
"""
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04 and also debian jessie, with bluez5.
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone.
This will be only fixes the bluez5 problem mentioned above .