Skip to content

Instantly share code, notes, and snippets.

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

Marco Alejandro MarcoAlejandro

🏠
Working from home
View GitHub Profile
@MarcoAlejandro
MarcoAlejandro / gist:5aec320cd322bd997aa38cd6f858387d
Created December 2, 2022 21:02
Read Tokens from Lines from cin
# include <string>
# include <iostream>
# include <vector>
# include <sstream>
# include <utility>
# include <map>
# include <algorithm>
using namespace std;
@MarcoAlejandro
MarcoAlejandro / pythonstructure.md
Created November 26, 2020 12:57
Resume of good practices to consider when structuring your Python code.

References


When creating code, decisions are made. This decisions will determine the structure of the code. Programmers should take decisions that allows structure to best leverage Python features.

Signs of a poor code structure

  • Multiple and messy circular dependencies. You don't want to rely on hacks such as using import statements inside your methods or functions.
@MarcoAlejandro
MarcoAlejandro / pysites.md
Last active February 21, 2020 04:30
Python sites that I use.
@MarcoAlejandro
MarcoAlejandro / Jest Unist testing.md
Last active October 17, 2019 20:29
Jest unit testing.

Qué es una prueba unitaria?

Las pruebas unitarias lo que hacen es tomar todos tus proyectos o esos bloques de código y descomponerlo en pequeñas partes que vamos a probar. Así, todo lo que vamos pasando sabemos que esta funcionando correctamente y que no hay ningún inconveniente o bug.

Las pruebas unitarias comprueban lo que son casos estándares (suposición explícita) es decir, no son perfectas.

Características de las pruebas unitarias

@MarcoAlejandro
MarcoAlejandro / EnumerationsExample.java
Created October 12, 2019 20:41
Java enumerations example
/*
https://www.w3schools.com/java/java_enums.asp
*/
public enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
//You can create references to enumeration like this:
@MarcoAlejandro
MarcoAlejandro / LocalClassExample.java
Created October 10, 2019 15:55
Example of local classes in Java SE 8+
/**
Local classes. They can be defined inside a block {...}
In this example the local class PhoneNumber is defined inside the method validatePhoneNumbers.
Facts:
- A local class has access to the members of its enclosing class. The class PhoneNumber accesses
the regex variable.
- A local class has access to local variables in the scope where It is defined. But this access is only
@MarcoAlejandro
MarcoAlejandro / NestedClasses.java
Last active October 10, 2019 14:48
Nested static classes and inner classes in Java.
/*App.java*/
class App {
public static void main(String[] args) {
FootballPlayer player = new FootballPlayer("Pele");
FootballPlayer.Stats stats = player.new Stats(10,20,30);
FootballPlayer.FootballShoes shoes1 = new FootballPlayer.FootballShoes("green", 9.5f);
FootballPlayer.FootballShoes shoes2 = new FootballPlayer.FootballShoes("red", 9.5f);
player.addFootballShoes(shoes1);
player.addFootballShoes(shoes2);
System.out.println(player.printInfo());
@MarcoAlejandro
MarcoAlejandro / PlayingMemory.java
Created October 6, 2019 10:04
Java memory internals stack & heap.
public class PlayingMemory {
public static void main(String[] args){
Doctor d1 = new Doctor(1);
Doctor d2 = new Doctor(2);
//outputs:
//1
//2
System.out.println(d1.getId());
System.out.println(d2.getId());
@MarcoAlejandro
MarcoAlejandro / Some.java
Last active October 6, 2019 09:30
Basic class syntax java
public class Some {
private int ping;
private String pong;
//Static members belongs to the class. There is no need of an object creation for use static members.
public static final String birth = "Since 1895";
Some(int pi, String po) {
this.ping = pi;
this.pong = po;
@MarcoAlejandro
MarcoAlejandro / doesAnArrayPassAsReference.java
Created October 1, 2019 20:26
Arrays as references Java.
/**
Primitive types in Java are passed by value to functions.
Objects are passed as reference.
So Arrays should pass as reference to...
*/
public class doesAnArrayPassAsReference {
private static final int aSize = 20;
public static void main(String[] args) {