Skip to content

Instantly share code, notes, and snippets.

View IsaacAndres's full-sized avatar

Isaac Calavera IsaacAndres

View GitHub Profile
@IsaacAndres
IsaacAndres / curl.php
Created April 23, 2019 04:03
Petición POST usando cURL
<?php
// abrimos la sesión cURL
$ch = curl_init();
// definimos la URL a la que hacemos la petición
curl_setopt($ch, CURLOPT_URL,"http://www.aeurus.cl/api.php");
// indicamos el tipo de petición: POST
curl_setopt($ch, CURLOPT_POST, TRUE);
// definimos cada uno de los parámetros
curl_setopt($ch, CURLOPT_POSTFIELDS, "valor1=value1&valor2=value2&valor3=value3");
@IsaacAndres
IsaacAndres / autover.php
Last active May 13, 2019 14:41
Devuelve la ruta de un JS o CSS con su versión (fecha de ultima modificación)
<?php
function autoVer($url)
{
$path = pathinfo($url);
$ver = '?v='.filemtime($_SERVER['DOCUMENT_ROOT'].$url);
return $path['dirname'].'/'.$path['basename'].$ver;
}
@IsaacAndres
IsaacAndres / random_password.php
Created May 14, 2019 15:58
Genera password aleatoria
<?php
$password = substr( md5(microtime()), 1, 8);
@IsaacAndres
IsaacAndres / myisam-a-innodb.php
Last active February 12, 2020 15:02
Cambiar $table->Tables_in_dbname por $table->Tables_in_<nombre_de_tu_base_de_datos>
<?php
$dbhost = 'hostname';
$dbname = 'dbname';
$dbuser = 'dbuser';
$dbpass = 'dbpassword';
$dsn = 'mysql:dbname='.$dbname.';host='.$dbhost;
try {
$dbh = new PDO($dsn, $dbuser, $dbpass);
} catch (PDOException $e) {
@IsaacAndres
IsaacAndres / fecha_esp.php
Last active August 29, 2019 20:24
Convertir fecha a español
<?php
setlocale(LC_ALL, 'es_ES');
foreach ($listado as $key => $venta) {
$fecha = $venta->fecha;
$date = new Datetime("$fecha");
$fecha = strftime("%d %B %Y", $date->getTimestamp());
$listado[$key]->fecha = $fecha;
}
@IsaacAndres
IsaacAndres / fechas_mes.php
Created December 11, 2019 14:54
Obtener el primer y último día del mes
<?php
$fecha = new DateTime(); # Para obtener desde una fecha determinada sería de la siguente forma: $fecha = new DateTime('2019-12-11');
// obtener primer día del mes
$primer = $fecha;
$primer->modify('first day of this month');
$primer = $primer->format('Y-m-d');
echo $primer;
// obtener último día del mes
@IsaacAndres
IsaacAndres / validacion.js
Last active April 5, 2022 16:03
Validación caracteres permitidos
// Rut
oninput="this.value = this.value.replace(/[^0-9Kk.]/g, '').replace(/(\..*)\./g, '$1');"
// Numeros
onkeypress="return /[0-9]/i.test(event.key)"
// Letras
onkeypress="return /[aA-zZ ]/i.test(event.key)"
// maxLength
oninput="if(this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
@IsaacAndres
IsaacAndres / onedecimal.html
Created January 24, 2020 03:02
Permite solo un punto y un decimal
<input type="text" onkeypress="return filterFloat(event,this);">
<script>
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){
@IsaacAndres
IsaacAndres / validaciondatapicker.js
Created February 4, 2020 20:07
Validacion fecha min/max bootstrap datapicker
<script>
$(document).ready(function(){
$("#fechainicio").datepicker({
todayBtn: 1,
autoclose: true,
}).on('changeDate', function (selected) {
var minDate = new Date(selected.date.valueOf());
$('#fechatermino').datepicker('setStartDate', minDate);
});
@IsaacAndres
IsaacAndres / disabled-inputs.js
Created March 9, 2020 03:14
Desabilitar todos los input
$(function(){
$(":input").prop("disabled", true);
})