Skip to content

Instantly share code, notes, and snippets.

View alefra88's full-sized avatar
💻

Alan.dev alefra88

💻
View GitHub Profile
@alefra88
alefra88 / ejercicio1.js
Created January 13, 2023 10:57
1) Programa una función que cuente el número de caracteres de una cadena de texto, pe. miFuncion("Hola Mundo") devolverá 10. si el dato no es string, pasarlo a string y contar los caracteres
const contarChar = (dato) => {
if (typeof dato === "string") {
return dato.length;
}
if (typeof dato === "number") {
let numToString = dato.toString();
return numToString.length;
}
if (typeof dato === "object") {
let objToString = dato.toString();
@alefra88
alefra88 / cuttext.js
Created January 13, 2023 11:05
Program a function that returns the text trimmed according to the number of characters indicated, eg. myFunction("Hello World", 4) will return "Hello".
const cut = (text, cut) => {
return text.slice(0, cut);
};
// connect
$dsn = 'mysql:host=nombre_de_servidor;dbname=nombre_de_base_de_datos';
$usuario = 'nombre_de_usuario';
$contraseña = 'contraseña';
try {
$dbh = new PDO($dsn, $usuario, $contraseña);
} catch (PDOException $e) {
echo 'Conexión fallida: ' . $e->getMessage();
}
@alefra88
alefra88 / app.js
Last active March 9, 2023 10:46
APIs: Buscador de Shows con Fetch y TVMAZE API
const d = document,
$shows = d.getElementById("shows"),
$template = d.getElementById("show-template"),
$fragment = d.createDocumentFragment();
d.addEventListener("keypress", async (e) => {
if (e.target.matches("#search")) {
// console.log(e.key, e.keyCode);
if (e.key === "Enter") {
try {
@alefra88
alefra88 / app.js
Last active March 11, 2023 12:15
consumo de api wordpress con POO JS
// const d = document,
// $site = d.getElementById("site"),
// $posts = d.getElementById("posts"),
// $loader = d.querySelector(".loader"),
// $template = d.getElementById("post-template"),
// $fragment = d.createDocumentFragment(),
// DOMAIN = "https://malvestida.com",
// SITE = `${DOMAIN}/wp-json`,
// API_WP = `${SITE}/wp/v2`,
// POSTS = `${API_WP}/posts`,
@alefra88
alefra88 / app.js
Last active September 2, 2024 01:22
Codigo js de la clase 141 wordpress API rest fetch
const d = document,
$site = d.getElementById("site"),
$posts = d.getElementById("posts"),
$loader = d.querySelector(".loader"),
$template = d.getElementById("post-template"),
$fragment = d.createDocumentFragment(),
DOMAIN = "https://malvestida.com",
SITE = `${DOMAIN}/wp-json`,
API_WP = `${SITE}/wp/v2`,
POSTS = `${API_WP}/posts?_embed`,
@alefra88
alefra88 / app.js
Created March 12, 2023 10:36
142. WordPress REST API y Fetch
const d = document,
$site = d.getElementById("site"),
$posts = d.getElementById("posts"),
$loader = d.querySelector(".loader"),
$template = d.getElementById("post-template"),
$fragment = d.createDocumentFragment(),
DOMAIN = "https://malvestida.com",
SITE = `${DOMAIN}/wp-json`,
API_WP = `${SITE}/wp/v2`,
POSTS = `${API_WP}/posts?_embed`,
@alefra88
alefra88 / managerClick.js
Created July 14, 2024 01:18
Proteger de multiples clicks
function eventManager(){
let executing = false;
return async ()=>{
if(!executing){
executing = true;
await fn();
setTimeout(()=>{executing = false},2000);
}
}
}
Scaffold-DbContext "Server=LAPTOP-S8HOTDC5\SQLEXPRESS;Database=DBName;User ID=sa; password=password;" Microsoft.EntityFrameWorkCore.SqlServer -Tables TableName -Context NameContext -ContextDir Models/Context -OutputDir Models/Entities -NoPluralize -Force
@alefra88
alefra88 / program.cs
Created July 30, 2024 16:30
builder service into Program MVC core
// Add services to the container.
builder.Services.AddDbContext<NameContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DBConnectionName")));
// Add Authorization services
builder.Services.AddAuthorization();