Skip to content

Commit 997978c

Browse files
committed
Merge branch 'develop' of github.com:agusrosero/roadmap-retos-programacion into develop
2 parents 8cc738b + af65c6c commit 997978c

File tree

9 files changed

+1179
-556
lines changed

9 files changed

+1179
-556
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/** #00 - Java -> Jesus Antonio Escamilla */
2+
3+
//Estas son las paginas oficiales de Java => https://www.java.com/es/ y https://www.oracle.com/java/
4+
5+
// Esta es una linea
6+
7+
/*
8+
* Este es un comentario de multiples líneas.
9+
* Y se puede agregar mas
10+
* o las que necesites
11+
*/
12+
13+
14+
public class JesusAntonioEEscamilla {
15+
public static void main(String[] args) {
16+
17+
// Declaración de una constaten
18+
final String mi_Const = "Soy una constante";
19+
20+
//BYTE
21+
byte byteVariable = 127;
22+
23+
//SHORT
24+
short shortVariable = 32767;
25+
26+
//INT
27+
int intVariable = 247483647;
28+
29+
//LONG
30+
long longVariable = 9223372036854775807L;
31+
32+
//FLOAT
33+
float floatVariable = 3.14F;
34+
35+
//DOUBLE
36+
double doubleVariable = 3.141592653589793;
37+
38+
//CHART
39+
char charVariable = 'A';
40+
41+
//BOOLEAN (true / false)
42+
boolean booleanVariable = true;
43+
44+
//STRING
45+
String stringVariable = "¡¡Hola Mundo!!";
46+
47+
// Imprimiendo la Constante
48+
System.out.println("Soy una constante " + mi_Const);
49+
50+
// Imprimiendo los datos Primitivos
51+
System.out.println("byte: " + byteVariable);
52+
System.out.println("short: " + shortVariable);
53+
System.out.println("int: " + intVariable);
54+
System.out.println("long: " + longVariable);
55+
System.out.println("float: " + floatVariable);
56+
System.out.println("double: " + doubleVariable);
57+
System.out.println("char: " + charVariable);
58+
System.out.println("boolean: " + booleanVariable);
59+
System.out.println("string: " + stringVariable);
60+
61+
//Imprimiendo en terminal
62+
System.out.println("¡Hola, Java!");
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://www.python.org/
2+
3+
"""
4+
Comentario
5+
1
6+
"""
7+
'''
8+
Comentario
9+
2
10+
'''
11+
12+
my_var='Hola soy Erick :)'
13+
14+
var_1 : int = 10
15+
var_2 : float = 10.0
16+
var_3 : bool = True
17+
var_4 : str = 'texto'
18+
19+
print("¡Hola, Python!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
try{
3+
myFunctionUndefined()
4+
}catch(error){
5+
console.log("There is an error")
6+
console.log(error.name)
7+
}
8+
9+
class CustomError extends Error{
10+
11+
constructor(){
12+
13+
super("Custom message");
14+
15+
}
16+
}
17+
18+
19+
function myFunction(param1,param2){
20+
if(param1 <= 3){
21+
throw new CustomError();
22+
}
23+
else if (typeof(param2)!= "number"){
24+
throw TypeError("Int was expected");
25+
}
26+
else if(param2>= 6){
27+
throw Error("Value bigger than 6");
28+
}
29+
}
30+
31+
try{
32+
//myFunction(1,4);
33+
//myFunction(8,"ed");
34+
myFunction(8,16);
35+
36+
}catch(err){
37+
38+
console.log("Exception name ", err.name);
39+
console.log("Exception message ", err.message);
40+
}
41+
42+
console.log("Execution finished ")
+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
Ejercicio
3+
"""
4+
5+
import xml.etree.ElementTree as xml
6+
import xml.dom.minidom as minidom
7+
import os
8+
9+
data = {
10+
"name" : "Luis",
11+
"age" : 25,
12+
"birthday" : "1995-09-19",
13+
"programming_languages" : ["Python", "HTML", "JavaScript"]
14+
}
15+
16+
def create_xml():
17+
root = xml.Element("data")
18+
19+
for key, value in data.items():
20+
21+
child = xml.SubElement(root, key)
22+
if isinstance(value, list):
23+
for item in value:
24+
xml.SubElement(child, "Item").text = item
25+
else:
26+
child.text = str(value)
27+
28+
tree = xml.ElementTree(root)
29+
tree.write("programador.xml")
30+
31+
#Convert the tree to a string
32+
xml_str = xml.tostring(root, encoding='unicode')
33+
34+
#Parse the string using a minidom for pretty printing
35+
dom = minidom.parseString(xml_str)
36+
pretty_xml_as_string = dom.toprettyxml()
37+
38+
with open("programador.xml", "w") as f:
39+
f.write(pretty_xml_as_string)
40+
41+
create_xml()
42+
43+
with open("programador.xml", 'r') as xml_data:
44+
print(xml_data.read())
45+
46+
#os.remove("programador.xml")
47+
48+
49+
"""
50+
Json
51+
"""
52+
53+
import json
54+
55+
json_file = "programador1.json"
56+
57+
def create_json():
58+
with open(json_file, "w") as f:
59+
json.dump(data, f, indent=4)
60+
61+
create_json()
62+
63+
with open(json_file, "r") as f:
64+
print(f.read())
65+
66+
#os.remove(json_file)
67+
68+
"""
69+
Extra
70+
"""
71+
72+
create_xml()
73+
create_json()
74+
75+
class Data:
76+
77+
def __init__(self, name, age, birthday, programming_languages) -> None:
78+
self.name = name
79+
self.age = age
80+
self.birthday = birthday
81+
self.programming_languages = programming_languages
82+
83+
84+
with open("programador.xml", "r") as f:
85+
root = xml.fromstring(f.read())
86+
name = root.find("name").text
87+
age = root.find("age").text
88+
birthday = root.find("birthday").text
89+
programming_languages = []
90+
for item in root.find("programming_languages"):
91+
programming_languages.append(item.text)
92+
93+
data_class = Data(name, age, birthday, programming_languages)
94+
print(data_class.__dict__)
95+
96+
97+
#json
98+
99+
with open(json_file, "r") as f:
100+
json_dict = json.load(f)
101+
json_class = Data(
102+
json_dict["name"],
103+
json_dict["age"],
104+
json_dict["birthday"],
105+
json_dict["programming_languages"]
106+
)
107+
print(json_class.__dict__)
108+
109+
110+
os.remove("programador.xml")
111+
os.remove(json_file)
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Autor: Héctor Adán
2+
// GitHub: https://github.com/hectorio23
3+
4+
#include <iostream>
5+
#include <string>
6+
#include <optional>
7+
8+
/////////////////////////////////////////////////
9+
/////////////////// EJERCICIO 1 /////////////////
10+
/////////////////////////////////////////////////
11+
12+
class NotDuplicity {
13+
public:
14+
static NotDuplicity& getInstance() {
15+
static NotDuplicity instance;
16+
return instance;
17+
}
18+
19+
// Eliminamos los métodos de copia y asignación para evitar múltiples instancias
20+
NotDuplicity(NotDuplicity const&) = delete;
21+
void operator=(NotDuplicity const&) = delete;
22+
23+
private:
24+
NotDuplicity() {} // Constructor privado
25+
};
26+
27+
/////////////////////////////////////////////////
28+
///////////////// EJERCICIO EXTRA ///////////////
29+
/////////////////////////////////////////////////
30+
31+
class UserSession {
32+
public:
33+
struct UserData {
34+
int id;
35+
std::string username;
36+
std::string name;
37+
std::string email;
38+
};
39+
40+
static UserSession& getInstance() {
41+
static UserSession instance;
42+
return instance;
43+
}
44+
45+
// Eliminamos los métodos de copia y asignación para evitar múltiples instancias
46+
UserSession(UserSession const&) = delete;
47+
void operator=(UserSession const&) = delete;
48+
49+
void setUser(int userId, const std::string& username, const std::string& name, const std::string& email) {
50+
userData = UserData{userId, username, name, email};
51+
}
52+
53+
std::optional<UserData> getUser() const {
54+
return userData;
55+
}
56+
57+
void clearUser() {
58+
userData.reset();
59+
}
60+
61+
private:
62+
std::optional<UserData> userData;
63+
64+
UserSession() {} // Constructor privado
65+
};
66+
67+
int main() {
68+
// Ejercicio 1: Singleton Genérico
69+
NotDuplicity& obj1 = NotDuplicity::getInstance();
70+
NotDuplicity& obj2 = NotDuplicity::getInstance();
71+
72+
std::cout << "ID Objeto 1 => " << &obj1 << std::endl;
73+
std::cout << "ID Objeto 2 => " << &obj2 << std::endl;
74+
std::cout << "¿Los objetos 1 y 2 son iguales? " << (&obj1 == &obj2) << std::endl;
75+
76+
std::cout << "\n********************************\n";
77+
78+
// Ejercicio Extra: Sesión de Usuario
79+
UserSession& session = UserSession::getInstance();
80+
session.setUser(1, "hectorio23", "Adán", "[email protected]");
81+
82+
auto user = session.getUser();
83+
if (user) {
84+
std::cout << "Usuario: " << user->username << ", Nombre: " << user->name << ", Email: " << user->email << std::endl;
85+
}
86+
87+
session.clearUser();
88+
89+
user = session.getUser();
90+
if (!user) {
91+
std::cout << "Datos del usuario borrados" << std::endl;
92+
}
93+
94+
// Verificación de singleton:
95+
UserSession& anotherSession = UserSession::getInstance();
96+
std::cout << "¿Las sesiones son iguales? " << (&session == &anotherSession) << std::endl;
97+
98+
return 0;
99+
}

0 commit comments

Comments
 (0)