Skip to content

Instantly share code, notes, and snippets.

View tanrax's full-sized avatar

Andros Fenollosa tanrax

View GitHub Profile
https://1drv.ms/p/s!AiYUbsW8-PRoiuFj0c8TxPdP1RxZDA?e=GYKFFO
@tanrax
tanrax / list_of_country_calling_codes.py
Last active September 13, 2022 11:46
Django models TextChoices: List of country calling codes
from django.db import models
"""
# As it is an Enum, the keys cannot be repeated, but the phone codes are repeated. One solution is to turn the Enum around and when it is displayed, make a map to change the order.
country_calling_code = models.CharField(
max_length=39,
choices=map(lambda x: (f"{x[1]}|{x[0]}", x[0]), ListOfCountryCallingCodes.choices),
verbose_name="Pais origen número de teléfono",
)
def long_text(text: str, repeat: int) -> str:
if repeat > 0:
return "".join(
map(
lambda letter: letter * repeat
if letter in "aeiou"
else letter,
text,
)
)
@tanrax
tanrax / ready.js
Last active June 26, 2018 09:20
Javascript: Ready
document.addEventListener('DOMContentLoaded', function () {
// Aquí tu código
});
@tanrax
tanrax / gist:9745424
Created March 24, 2014 17:50
JS: Drag and drop (arrastrar y soltar)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Drag and drop</title>
<style>
.ficha {
width: 100px;
height: 100px;
float: left;
@tanrax
tanrax / gist:9682232
Created March 21, 2014 08:53
JS: Campo vacío (validar o comprobar)
if(nom.value == null || nom.value.length == 0 || /^\s+$/.test(nom.value)) {
bError = true;
}
@tanrax
tanrax / gist:9682209
Created March 21, 2014 08:51
JS: Comprobar correo (e-mail)
//Comprobar que es un e-mail válido
var sExpr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!sExpr.test(correo.value)) {
bError = true;
}
@tanrax
tanrax / gist:9681952
Created March 21, 2014 08:27
JQuery: Scroll suave (mover lento)
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@tanrax
tanrax / BD.class.php
Created March 18, 2014 11:41
PHP POO: Clase base de datos (Class object SQL)
<?php
/**
* Clase para utilizar la base de datos
* 1.1v
*/
class DB {
//Variables
public static $DB_HOST = 'localhost';
@tanrax
tanrax / gist:9544289
Created March 14, 2014 08:52
AJAX: Envío de datos (Enviar por GET)
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Ejemplo de formulario con AJAX</title>
<style>
body {
font-size: 14px;
text-align: center;
}