Skip to content

Instantly share code, notes, and snippets.

View alexlatam's full-sized avatar
🏠
Working from home

Alexis Montilla alexlatam

🏠
Working from home
View GitHub Profile
@alexlatam
alexlatam / filterTwoDecimalsInInputTextJS.html
Created April 21, 2021 21:42 — forked from Javlopez/filter.html
Solo numeros con 1 punto y maximo dos decimales
<script type="text/javascript">
<!--
function filterFloat(evt,input){
// Backspace = 8, Enter = 13, ‘0′ = 48, ‘9′ = 57, ‘.’ = 46, ‘-’ = 43
var key = window.Event ? evt.which : evt.keyCode;
var chark = String.fromCharCode(key);
var tempValue = input.value+chark;
if(key >= 48 && key <= 57){
if(filter(tempValue)=== false){
return false;
@alexlatam
alexlatam / query_db.php
Last active November 15, 2022 16:53
PHP Query with MySqli and PDO and Transactions using PDO
<?php
/*------------------------- \Mysqli -------------------------*/
/*------------------------- \Mysqli -------------------------*/
// Conexion con DB, usando la clase global(propia del lenguaje) mysqli
$mysqli_conection = new \mysqli($this->server, $this->username, $this->password, $this->database);
// Comprobar conexión genero error
if ($mysqli->connect_errno)
die("Falló la conexión: {$mysqli->connect_error}");
@alexlatam
alexlatam / async-await-api-query.js
Created August 28, 2022 14:44
Script para consultar con JavaScript nativo a una api, usando async await
// Hago el llamado al endpoint, y obtengo al respuesta
const response = await fetch(API_URL);
// Paso la informacion de string, a formato JSON
const data = response.json();
// Ahora con la data que retorna el endopoint, puedo procesarlo.
@alexlatam
alexlatam / fetch_http_request.js
Last active December 21, 2023 21:32
Http Request Api Fetch - Callbacks - JavaScript
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const API = "https://api.escuelajs.co/api/v1";
//funcion principal que obtendrá la informacion del producto como un objeto
function fetchData(urlApi, callback) {
//inicializar un objeto de tipo XMLHttpRequest
let xhttp = new XMLHttpRequest();
//El metodo .open realiza la petición de apertura de comunicación, el metodo puede ser 'GET' o 'POST',
// luego se envia la URL, si es asincrono (true o false), usuario y contraseña. En esta caso solo se utiliza el metodo, la url y async
xhttp.open('GET', urlApi, true);
@alexlatam
alexlatam / fetch-api-with-promise.js
Last active December 21, 2023 21:32
Consultas a una API de manera concatenada usando fetchData Promises - JavaScript
/*
* npm i node-fetch // Instalamos el paquete
* Necesario agregar en el archivo package.json la directiva "type": "module"
*/
import fetch from "node-fetch";
const API = 'https://api.escuelajs.co/api/v1';
/*--------------------GET---------------------------*/
function fetchData(urlApi){
@alexlatam
alexlatam / concurrencia.go
Created February 14, 2023 13:25
Example of concurrencie using GO(Golang)
package main
import (
"fmt"
"runtime" // Este paquete permite trabajar con las Go rutinas
"sync" // Permite crear sincronizar las rutinas de Go
)
// Variable que permite crear grupos de rutinas
var wg sync.WaitGroup
@alexlatam
alexlatam / typed_array.php
Last active January 29, 2024 18:17
Get an array typed with an specific class on PHP. NameClass[]
<?php
/**
* Creamos una clase de la cual se crearan los objetos que contendra el array
* El array tendra solo objetos de esta clase. [Product, Product, ...]
*/
readonly class Product
{
public function __construct(
private string $name,
@alexlatam
alexlatam / promises_async_await.js
Last active January 11, 2024 02:57
How it works: Promises - Async/Await - [JavaScript]
/**
* Create a promise and assign it to a variable
*/
let promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Success!')
}, 2000)
});
/**
@alexlatam
alexlatam / simple_php_api.php
Created May 30, 2024 13:19
Simple Api on Pure PHP - Without frameworks
<?php
init_set('display_errors', 0);
init_set('html_errors', 0);
$message = new stdClass();
$message->content[0] = "Hi there!";
$message->content[1] = "See you later";
/** Headers Response **/
header('Content-Type: application/json; charset=utf-80); // response tpye