├── .gitattributes ├── Golang ├── 19 - Files │ ├── file.txt │ └── main.go ├── go.png ├── README.md ├── 01 - Hello World │ └── main.go ├── 09 - Package Scope │ ├── main.go │ └── file.go ├── 05 - Sorting Arrays │ └── main.go ├── 17 - Switch │ └── main.go ├── 10 - Maps │ └── main.go ├── 06 - Loops │ └── main.go ├── 04 - Standard Library │ └── main.go ├── 18 - Parsing Numbers from strings │ └── main.go ├── 07 - Boolean and Conditionals │ └── main.go ├── 14 - Receiver Functions │ └── main.go ├── 13 - Structs and custom types │ └── main.go ├── 16 - User Input │ └── main.go ├── 11 - Pass By Value │ └── main.go ├── 08 - Functions │ └── main.go ├── 15 - Receiver Functions with Pointers │ └── main.go ├── 12 - Pointers │ └── main.go ├── 02 - variables and formatting │ └── main.go └── 03 - Arrays and Slices │ └── main.go ├── C ├── 07 - Functions │ ├── src │ │ ├── main.d │ │ ├── main.o │ │ └── main.c │ └── output │ │ └── main ├── c.png ├── 16 - Files │ └── name.txt ├── 13 - Header files │ ├── src │ │ ├── header.c │ │ └── main.c │ └── include │ │ └── header.h ├── 12 - extern Keyword │ ├── src │ │ ├── file.c │ │ └── main.c │ └── include │ │ └── header.h ├── 99extras │ ├── 05 - min-max search algorithm │ │ └── src │ │ │ └── main.o │ ├── 06 - Casting in C style │ │ └── int to char conversion │ │ │ └── src │ │ │ └── main.c │ ├── 08 - Atoi() │ │ └── src │ │ │ └── main.c │ └── 02 - snprintf usage │ │ └── src │ │ └── main.c ├── 01 - Hello World │ └── main.c ├── 10 - Static keyword │ ├── src │ │ └── file.c │ └── include │ │ └── header.h ├── HEADER FILE NOTES.txt ├── README.md ├── 18 - Bitwise Operands │ ├── NOT (~) bitwise operand │ │ └── main.c │ ├── OR (|) bitwise operand │ │ └── main.c │ ├── XOR (^) bitwise operand │ │ └── main.c │ ├── AND (&) bitwise operand │ │ └── main.c │ ├── << and >> shift operands │ │ └── main.c │ └── README.md ├── 14 - ? and : conditional operators │ └── src │ │ └── main.c ├── 08 - Preprocessor Directives │ └── src │ │ └── main.c ├── 15 - argc and argv │ └── src │ │ └── main.c ├── 19 - Union keyword │ └── struct union example │ │ └── src │ │ └── main.c ├── 09 - Enums │ └── src │ │ └── main.c ├── 03 - Loops │ └── src │ │ └── main.c └── 11 - Inline Keyword │ └── src │ └── main.c ├── Python ├── 27 - file manipulation - writing a file │ ├── loop.csv │ ├── main123.py │ └── main.py ├── 26 - file manipulation - reading a file │ ├── numbers.csv │ └── main.py ├── python.png ├── 06 - forLoop - range usage │ └── main.py ├── 09 - function - add two items │ └── main.py ├── 07 - forLoop - array iteration usage │ └── main.py ├── 19 - error handling - try except TypeError │ └── main.py ├── 11 - function - simple lambda function │ └── main.py ├── 02 - Sum with two numbers │ └── main.py ├── 05 - forLoop - basic usage │ └── main.py ├── 10 - function - substracting two items │ └── main.py ├── 12 - function - simple map function │ └── main.py ├── 08 - while loop - simple usage │ └── main.py ├── 13 - function - simple filter function │ └── main.py ├── 20 - error handling - try except else │ └── main.py ├── 03 - Simple if - else usage │ └── main.py ├── 01 - Usage of variables and Printf │ └── main.py ├── 22 - error handling - raise │ └── main.py ├── 21 - error handling - try except else finally │ └── main.py ├── 28 - file manipulation - appending a file │ └── main.py ├── 11 - function - parameters │ └── main.py ├── 17 - error handling - try except │ └── main.py ├── 18 - error handling - try except ZeroDivisionError │ └── main.py ├── 04 - Simple if - elif usage │ └── main.py ├── 30 - Object oriented programming - Methods │ └── main.py ├── 15 - function - fizzbuzz continue statement │ ├── main.py │ └── main.py.save ├── 23 - data manipulation - tuples │ └── main.py ├── README.md ├── 16 - function - fizzbuzz pass statement │ └── main.py ├── 24 - data manipulation - list │ ├── main.py │ └── example.py ├── 29 - Object oriented programming - Making a class │ └── main.py ├── 14 - function - fizzbuzz break statement │ └── main.py ├── 25 - data manipulation - dictionaries │ └── main.py └── 31 - Object oriented programming - Inheritance │ └── .main.py.swp ├── C++ ├── 26 - Files in C++ │ └── Read file with sstream and strings │ │ └── New file.txt ├── c++.png ├── 12 - Object Oriented Programming │ ├── Objects as parameters │ │ ├── CMakeFiles │ │ │ ├── progress.marks │ │ │ ├── main.dir │ │ │ │ ├── progress.make │ │ │ │ ├── depend.make │ │ │ │ ├── link.txt │ │ │ │ ├── compiler_depend.ts │ │ │ │ ├── flags.make │ │ │ │ ├── cmake_clean.cmake │ │ │ │ └── DependInfo.cmake │ │ │ ├── cmake.check_cache │ │ │ ├── 3.22.3 │ │ │ │ ├── CompilerIdC │ │ │ │ │ └── a.out │ │ │ │ ├── CompilerIdCXX │ │ │ │ │ └── a.out │ │ │ │ ├── CMakeDetermineCompilerABI_C.bin │ │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin │ │ │ │ └── CMakeSystem.cmake │ │ │ ├── TargetDirectories.txt │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ └── Makefile.cmake │ │ ├── include │ │ │ └── class.h │ │ ├── src │ │ │ ├── main.cpp │ │ │ └── class.cpp │ │ ├── CMakeLists.txt │ │ └── cmake_install.cmake │ ├── classes in .h and .cpp │ │ ├── include │ │ │ ├── libs.h │ │ │ └── class.h │ │ └── src │ │ │ ├── class.cpp │ │ │ └── main.cpp │ ├── Basic OOP with object │ │ └── src │ │ │ ├── class.h │ │ │ ├── class.cpp │ │ │ └── main.cpp │ ├── Virtual class extension │ │ ├── Operation override │ │ │ └── main.cpp │ │ └── Basic Example │ │ │ └── main.cpp │ ├── Avoiding circular depency.cpp │ ├── Friend Class │ │ ├── src │ │ │ └── main.cpp │ │ └── .vscode │ │ │ └── launch.json │ ├── The Diamond Problem │ │ └── src │ │ │ └── main.cpp │ ├── Accessing private member │ │ └── src │ │ │ └── main.cpp │ └── Simple calss with and without pointer │ │ └── src │ │ └── main.cpp ├── 18 - Sounds │ └── Playing wav file │ │ ├── gemma.wav │ │ ├── doggo1.wav │ │ └── src │ │ └── main.cpp ├── 16 - Vectors │ ├── Built-in Delete function │ │ └── src │ │ │ ├── main.o │ │ │ └── main.cpp │ ├── 4 - Input, sort, remove duplicate, output │ │ ├── src │ │ │ ├── main.cpp │ │ │ └── class.cpp │ │ └── include │ │ │ └── class.h │ ├── 3 - [IMPORTANT] Operating with vector elements - Wrong and good ways │ │ ├── src │ │ │ └── main.cpp │ │ └── include │ │ │ └── methods.h │ └── IMPORTANT NOTES.txt ├── 19 - tytpedef and alias │ └── Example │ │ ├── output │ │ └── main.exe │ │ └── src │ │ └── main.cpp ├── 14 - Casting │ ├── static cast │ │ ├── static cast - int to char │ │ │ └── src │ │ │ │ ├── main.o │ │ │ │ └── main.cpp │ │ ├── stati cast - char to int │ │ │ ├── output │ │ │ │ └── main.exe │ │ │ └── src │ │ │ │ └── main.cpp │ │ ├── casting types.txt │ │ ├── static cast - float to int │ │ │ └── src │ │ │ │ └── main.cpp │ │ └── static cast - double to float │ │ │ └── src │ │ │ └── main.cpp │ └── Reinterpret cast │ │ ├── int8_t to char * │ │ └── main.cpp │ │ ├── float to int │ │ └── src │ │ │ └── main.cpp │ │ └── uint8_t to unsigned char * │ │ └── main.cpp ├── 30 - Extern keyword │ └── Hybrid C-C++ linkage and scoping effect │ │ ├── src │ │ ├── file.c │ │ ├── main.cpp │ │ └── header.cpp │ │ └── include │ │ └── header.hh ├── 12.1 classes not OOP with static │ └── from class to class access with static members │ │ └── src │ │ ├── main.o │ │ └── main.cpp ├── 42 - std::jthread │ ├── 42.8 - [to finish] avoiding early main() termination │ │ └── main.cpp │ ├── 42.5 - std::thread::hardware_concurrency() │ │ └── main.cpp │ ├── 42.2 - std::this_thread │ │ └── main.cpp │ ├── 42.4 - std::ref │ │ └── main.cpp │ └── 42.3 - std::move │ │ └── main.cpp ├── 05- While loops │ ├── simple example │ │ └── main.cpp │ └── complex examples │ │ └── main.cpp ├── 04 - For loops │ ├── simple example │ │ └── main.cpp │ └── complex examples │ │ └── main.cpp ├── 11 - String C++ │ ├── std::String to const char * │ │ ├── src │ │ │ └── main.cpp │ │ └── CMakeLists.txt │ └── finding substring and specific characters in a string │ │ └── src │ │ └── main.cpp ├── 08 - Function Return Values │ ├── Simple Int Example │ │ └── main.cpp │ └── Complex String Example │ │ └── main.cpp ├── 20 - Pointers C++ │ ├── Access single variable memory │ │ └── src │ │ │ └── main.cpp │ └── Dynamic Matrix allocation │ │ └── src │ │ └── main.cpp ├── 39 - Bitwise operands │ ├── NOTE.txt │ ├── NOT (~) bitwise operand │ │ └── main.cpp │ ├── OR (|) bitwise operand │ │ └── main.cpp │ ├── XOR (^) bitwise operand │ │ └── main.cpp │ ├── AND (&) bitwise operand │ │ └── main.cpp │ └── << and >> shift operands │ │ └── main.cpp ├── 21 - Template example │ ├── Basic example 2 │ │ └── src │ │ │ └── main.cpp │ ├── template on vector example │ │ └── src │ │ │ └── main.cpp │ └── Basic example │ │ └── src │ │ └── main.cpp ├── README.md ├── 06 - Break and continue │ ├── For loop │ │ └── main.cpp │ └── While loop │ │ └── main.cpp ├── 23 - List, stack, tail │ └── 2 - Stack example │ │ ├── swap function │ │ └── src │ │ │ └── main.cpp │ │ └── Introduction, input, removing element, printing │ │ └── src │ │ └── main.cpp ├── C++ use of deleted function error.txt ├── 44 - Smart Pointers │ ├── 44.0 - Introduction │ │ └── main.cpp │ └── 44.2 - shared_ptr │ │ └── main.cpp ├── 40 - "continue" keyword │ └── main.cpp ├── 25 - std::map │ ├── Hash table with hex values │ │ ├── include │ │ │ ├── randomizer.h │ │ │ └── hash_table.h │ │ └── src │ │ │ └── main.cpp │ ├── Search, Delete hash │ │ └── src │ │ │ └── main.cpp │ └── Basic example │ │ └── src │ │ └── main.cpp ├── 09 - Function Parameters │ ├── Simple Int Example │ │ ├── main.cpp │ │ └── importantNote.cpp │ └── Complex Example │ │ └── main.cpp ├── 01 - Usage Of Variables and printf │ ├── simple print statements │ │ └── main.cpp │ └── complex print statements │ │ └── main.cpp ├── 36 - this pointer │ └── src │ │ └── main.cpp ├── 31 - std::array type │ └── Basic example │ │ └── src │ │ └── main.cpp ├── 02 - Arithmetic │ ├── without variables │ │ └── main.cpp │ └── with variables │ │ └── main.cpp ├── 35 - std::pair │ └── src │ │ └── main.cpp ├── 10 - Scope │ └── main.cpp ├── 15 - mutable identifier │ ├── mutable string │ │ └── src │ │ │ └── main.cpp │ └── mutbale int │ │ └── src │ │ └── main.cpp ├── C++ RAII definition.txt ├── 07 - Switch Statements │ └── main.cpp ├── 27 - Goto │ └── Basic example │ │ └── src │ │ └── main.cpp ├── 28 - New keyword │ └── Basic example │ │ └── src │ │ └── main.cpp ├── 38 - auto and decltype keyword │ └── src │ │ └── main.cpp ├── 03 - If else statements │ ├── important detail │ │ └── main.cpp │ └── simple with user input │ │ └── main.cpp ├── 13 - Getline Function │ └── src │ │ └── main.cpp ├── 17 - Exceptions │ ├── Exception Handler with classes │ │ └── src │ │ │ └── main.cpp │ └── Basic exception throw │ │ └── src │ │ └── main.cpp ├── 29 - Class constructor │ ├── basic example │ │ └── main.cpp │ └── Basic Example 2 │ │ └── src │ │ └── main.cpp ├── 24 - random.h - randomizer for C++ │ └── basic example │ │ └── src │ │ └── main.cpp ├── 32 - Namespace │ └── Basic Example │ │ └── src │ │ └── main.cpp ├── 33 - Delete keyword │ └── src │ │ └── main.cpp ├── 43 - std::chrono examples │ └── 43.2 - std::chrono available time members │ │ └── main.cpp ├── 41 - volatile keyword │ └── main.cpp └── 22 - Swap function - integrated and manual implementation │ └── swap - manual implementation │ └── src │ └── main.cpp ├── Shell ├── Readme.md ├── logo.png ├── 02 - Input and output │ └── example.sh └── 01 - Printing with echo │ └── example.sh ├── logo.png ├── R ├── index.jpeg ├── Syntax │ └── Built-inFunctions.R └── README.md ├── Arduino ├── arduino.png └── README.md ├── Assembly ├── assembly.png ├── x86 │ ├── 4 - Loops │ │ └── main.asm │ ├── 3 - jmp and cmp │ │ └── main.asm │ ├── 2 - EIP Instruction Pointer and jmp instruction │ │ └── main.asm │ ├── 5 - editing strings │ │ └── main.asm │ └── 1 - Hello World │ │ └── main.asm └── Readme.md ├── RaspberryPi ├── raspberrypi.png └── README.md └── Java ├── 03 - Mathematical operations ├── .gitignore ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── app │ ├── bin │ │ └── main │ │ │ └── example3 │ │ │ └── app │ │ │ └── App.class │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── example3 │ │ │ └── app │ │ │ └── App.java │ └── build.gradle ├── .gitattributes └── settings.gradle ├── 02 - Saving values into variables and printing ├── .gitignore ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitattributes ├── app │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── example2 │ │ │ └── app │ │ │ └── App.java │ └── build.gradle └── settings.gradle ├── README.md └── 01 - Hello world └── app └── src └── main └── java └── app └── App.java /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-detectable=false 2 | -------------------------------------------------------------------------------- /Golang/19 - Files/file.txt: -------------------------------------------------------------------------------- 1 | { 2 | "Value": 2 3 | } -------------------------------------------------------------------------------- /C/07 - Functions/src/main.d: -------------------------------------------------------------------------------- 1 | src/main.o: src/main.c 2 | -------------------------------------------------------------------------------- /Python/27 - file manipulation - writing a file/loop.csv: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /C++/26 - Files in C++/Read file with sstream and strings/New file.txt: -------------------------------------------------------------------------------- 1 | input -------------------------------------------------------------------------------- /C/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C/c.png -------------------------------------------------------------------------------- /Python/26 - file manipulation - reading a file/numbers.csv: -------------------------------------------------------------------------------- 1 | 0,1,2,3,4,5 2 | -------------------------------------------------------------------------------- /Shell/Readme.md: -------------------------------------------------------------------------------- 1 | Here you can find shell examples. 2 | 3 | ![](logo.png) 4 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/logo.png -------------------------------------------------------------------------------- /C++/c++.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/c++.png -------------------------------------------------------------------------------- /R/index.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/R/index.jpeg -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /Golang/go.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Golang/go.png -------------------------------------------------------------------------------- /Shell/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Shell/logo.png -------------------------------------------------------------------------------- /Python/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Python/python.png -------------------------------------------------------------------------------- /Arduino/arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Arduino/arduino.png -------------------------------------------------------------------------------- /Assembly/assembly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Assembly/assembly.png -------------------------------------------------------------------------------- /C/16 - Files/name.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C/16 - Files/name.txt -------------------------------------------------------------------------------- /Shell/02 - Input and output/example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Input" 4 | 5 | read x 6 | 7 | echo x -------------------------------------------------------------------------------- /C/07 - Functions/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C/07 - Functions/src/main.o -------------------------------------------------------------------------------- /RaspberryPi/raspberrypi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/RaspberryPi/raspberrypi.png -------------------------------------------------------------------------------- /C/07 - Functions/output/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C/07 - Functions/output/main -------------------------------------------------------------------------------- /C/13 - Header files/src/header.c: -------------------------------------------------------------------------------- 1 | #include "header.h" 2 | 3 | void function() { 4 | printf("Declared functions here\n"); 5 | } -------------------------------------------------------------------------------- /Python/06 - forLoop - range usage/main.py: -------------------------------------------------------------------------------- 1 | """ For loop with range function """ 2 | 3 | 4 | for x in range(8): 5 | print(x) 6 | -------------------------------------------------------------------------------- /C++/18 - Sounds/Playing wav file/gemma.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/18 - Sounds/Playing wav file/gemma.wav -------------------------------------------------------------------------------- /Shell/01 - Printing with echo/example.sh: -------------------------------------------------------------------------------- 1 | #header init. 2 | 3 | #!/bin/bash 4 | 5 | #equivalent of printf/cout. 6 | echo "Hello world!" 7 | -------------------------------------------------------------------------------- /C++/18 - Sounds/Playing wav file/doggo1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/18 - Sounds/Playing wav file/doggo1.wav -------------------------------------------------------------------------------- /C/12 - extern Keyword/src/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "header.h" 3 | 4 | int myvar = 10; 5 | 6 | const char *strings[] = {"1", "2", "3"}; -------------------------------------------------------------------------------- /C++/16 - Vectors/Built-in Delete function/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/16 - Vectors/Built-in Delete function/src/main.o -------------------------------------------------------------------------------- /C++/19 - tytpedef and alias/Example/output/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/19 - tytpedef and alias/Example/output/main.exe -------------------------------------------------------------------------------- /C/99extras/05 - min-max search algorithm/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C/99extras/05 - min-max search algorithm/src/main.o -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | CMAKE_PROGRESS_3 = 3 4 | 5 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/depend.make: -------------------------------------------------------------------------------- 1 | # Empty dependencies file for main. 2 | # This may be replaced when dependencies are built. 3 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/c++ CMakeFiles/main.dir/src/class.cpp.o CMakeFiles/main.dir/src/main.cpp.o -o main 2 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /Python/09 - function - add two items/main.py: -------------------------------------------------------------------------------- 1 | # adding two items together 2 | 3 | #Add function 4 | def add(a, b): 5 | sum = (a + b) 6 | print(sum) 7 | 8 | 9 | add(3,5) 10 | -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/static cast - int to char/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/14 - Casting/static cast/static cast - int to char/src/main.o -------------------------------------------------------------------------------- /C++/30 - Extern keyword/Hybrid C-C++ linkage and scoping effect/src/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "header.hh" 3 | 4 | void function() 5 | { 6 | printf("C function called\n"); 7 | } -------------------------------------------------------------------------------- /Python/07 - forLoop - array iteration usage/main.py: -------------------------------------------------------------------------------- 1 | """ For loop with array iteration """ 2 | 3 | heroes = ['Superman', 'Batman','Green Lantern'] 4 | 5 | for x in heroes: 6 | print(x) 7 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Java/03 - Mathematical operations/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/stati cast - char to int/output/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/14 - Casting/static cast/stati cast - char to int/output/main.exe -------------------------------------------------------------------------------- /C++/30 - Extern keyword/Hybrid C-C++ linkage and scoping effect/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "header.hh" 3 | 4 | int main(void) 5 | { 6 | print(); 7 | function(); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /C/12 - extern Keyword/include/header.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER 2 | #define HEADER 3 | 4 | extern int myvar; 5 | 6 | extern const char *strings[]; 7 | 8 | #endif /* D19A5D69_FFDE_4764_9259_4597B30D4E10 */ 9 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/app/bin/main/example3/app/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Java/03 - Mathematical operations/app/bin/main/example3/app/App.class -------------------------------------------------------------------------------- /C/01 - Hello World/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | //Prints a string into stdout buffer to display in terminal. 7 | printf("Hello World!"); 8 | } -------------------------------------------------------------------------------- /C/10 - Static keyword/src/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* variable will not be visible 5 | 6 | void function() { 7 | printf("%d\n", variable); 8 | } 9 | 10 | */ -------------------------------------------------------------------------------- /C++/14 - Casting/Reinterpret cast/int8_t to char */main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int8_t a = 90; 7 | cout << reinterpret_cast(&a) << endl; 8 | } -------------------------------------------------------------------------------- /C++/30 - Extern keyword/Hybrid C-C++ linkage and scoping effect/src/header.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "header.hh" 3 | 4 | void print() 5 | { 6 | std::cout << "Hello c++ function" << std::endl; 7 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/compiler_depend.ts: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Timestamp file for compiler generated dependencies management for main. 3 | -------------------------------------------------------------------------------- /Python/19 - error handling - try except TypeError/main.py: -------------------------------------------------------------------------------- 1 | """TypeError occurs when the wrong data is incorporated in the code""" 2 | 3 | 4 | try: 5 | print([0,1,2,a]) 6 | 7 | except: 8 | print("a is not a number") 9 | -------------------------------------------------------------------------------- /RaspberryPi/README.md: -------------------------------------------------------------------------------- 1 | #RaspberryPi 2 | 3 | #Giving Help 4 | 5 | This repository contains projects regarding the raspberry pi 6 | 7 | Thank you!!!! 8 | 9 | Happy Coding!!! 10 | 11 | ![](raspberrypi.png) 12 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/Java/02 - Saving values into variables and printing/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Python/11 - function - simple lambda function/main.py: -------------------------------------------------------------------------------- 1 | """Lambda functions are anonymous functions that can be called without 2 | a name. Below is an example """ 3 | 4 | 5 | square = lambda x: x * 2 6 | 7 | print(square(3)) 8 | -------------------------------------------------------------------------------- /C++/14 - Casting/Reinterpret cast/float to int/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | float a = 90; 6 | std::cout<< reinterpret_cast(&a) << std::endl; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Python/02 - Sum with two numbers/main.py: -------------------------------------------------------------------------------- 1 | 2 | a = int(input("enter first number: ")) #first variable, input it's used like scanf in C. 3 | b = int(input("enter second number: ")) 4 | 5 | sum = a + b 6 | 7 | print("sum:", sum) 8 | -------------------------------------------------------------------------------- /Python/27 - file manipulation - writing a file/main123.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | f = open('abc.csv') 4 | csv_f = csv.reader(f) 5 | 6 | amails = [] 7 | 8 | for row in csv_f: 9 | amails.append(row[2]) 10 | 11 | print(amails) 12 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CompilerIdC/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CompilerIdC/a.out -------------------------------------------------------------------------------- /C++/12.1 classes not OOP with static/from class to class access with static members/src/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/12.1 classes not OOP with static/from class to class access with static members/src/main.o -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CompilerIdCXX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CompilerIdCXX/a.out -------------------------------------------------------------------------------- /C++/42 - std::jthread/42.8 - [to finish] avoiding early main() termination/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief 5 | * @version 0.1 6 | * @date 2023-03-24 7 | * 8 | * @copyright Copyright (c) 2023 9 | * 10 | */ -------------------------------------------------------------------------------- /Python/05 - forLoop - basic usage/main.py: -------------------------------------------------------------------------------- 1 | """Simple for loop""" 2 | 3 | #This loop takes each item on the list and prints a statement with each item 4 | genre = ['dubstep', 'jazz', 'pop'] 5 | for x in range(len(genre)): 6 | print("I like", genre[x]) 7 | -------------------------------------------------------------------------------- /Python/10 - function - substracting two items/main.py: -------------------------------------------------------------------------------- 1 | # Subtracting two items 2 | 3 | def subtract(a, b): 4 | c = b - a 5 | if c > 0: 6 | print(c) 7 | else: 8 | print(c) 9 | print("This is a negative number") 10 | 11 | 12 | subtract(2,10) 13 | -------------------------------------------------------------------------------- /Python/12 - function - simple map function/main.py: -------------------------------------------------------------------------------- 1 | """ Map functions is another anonymous function that takes 2 | a list and function """ 3 | 4 | 5 | numbers = [0,1,2,3,4] 6 | 7 | cubed = map(lambda x: x * 3, numbers) 8 | 9 | print(list(cubed)) 10 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fabxx/Programming_Languages/HEAD/C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /C++/16 - Vectors/4 - Input, sort, remove duplicate, output/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | vectors::input(); 5 | vectors::sort(); 6 | vectors::remove_duplicated(); 7 | vectors::output(); 8 | 9 | return 0; 10 | 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /C/10 - Static keyword/include/header.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER 2 | #define HEADER 3 | 4 | #include 5 | 6 | static inline void headerfunc() { 7 | printf("Calling static function from header\n"); 8 | } 9 | 10 | #endif /* B3499355_6352_4CDF_AE6D_65F11C011E45 */ 11 | -------------------------------------------------------------------------------- /Golang/README.md: -------------------------------------------------------------------------------- 1 | # Golang-Programming 2 | 3 | # Description 4 | ======= 5 | Simple examples for Go lang. Experience from C/C++ Can help beginners with this language in understanding the concepts behind the go functions and 6 | reasoning under the hood. 7 | 8 | ![](go.png) 9 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Python/08 - while loop - simple usage/main.py: -------------------------------------------------------------------------------- 1 | """ Simple while loop """ 2 | #A while loops through an object until the condition is no longer met 3 | #In this example the loop continues until i is no longer less than 9 4 | 5 | 6 | i = 0 7 | while i < 9: 8 | print(i) 9 | i +=1 10 | -------------------------------------------------------------------------------- /C++/05- While loops/simple example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int i = 0; 8 | // prints the numbers 0-9 (i.e. 10 numbers). 9 | while (i != 10){ 10 | cout << i << endl; 11 | i += 1; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | /home/fab/Scrivania/Objects as parameters/CMakeFiles/main.dir 2 | /home/fab/Scrivania/Objects as parameters/CMakeFiles/edit_cache.dir 3 | /home/fab/Scrivania/Objects as parameters/CMakeFiles/rebuild_cache.dir 4 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/classes in .h and .cpp/include/libs.h: -------------------------------------------------------------------------------- 1 | #ifndef C4A58BCD_8817_476A_89EF_FC834873242D 2 | #define C4A58BCD_8817_476A_89EF_FC834873242D 3 | #include 4 | using namespace std; 5 | #include 6 | 7 | 8 | #endif /* C4A58BCD_8817_476A_89EF_FC834873242D */ 9 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /C/99extras/06 - Casting in C style/int to char conversion/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //using the parenthesis 4 | 5 | int main() 6 | { 7 | int a = 10; 8 | char b = (char)a; //assigning to b a char equivalent of a value 9 | 10 | printf("%c\n", &b); 11 | printf("%d\n", a); 12 | return (0); 13 | } -------------------------------------------------------------------------------- /Python/13 - function - simple filter function/main.py: -------------------------------------------------------------------------------- 1 | """Filter functions are naother type of anonymous function that takes a list and creates a new list based on the arguments """ 2 | 3 | 4 | numbers = [0,1,2,3,4,5,6] 5 | 6 | even_numbers = list(filter(lambda x: (x%2 == 0), numbers)) 7 | 8 | print(even_numbers) 9 | -------------------------------------------------------------------------------- /Python/20 - error handling - try except else/main.py: -------------------------------------------------------------------------------- 1 | """ If a program ran successfully a message can be used to alert that things ran successfully """ 2 | 3 | 4 | try: 5 | print("The program is running") 6 | 7 | except: 8 | print("An error has occurred") 9 | 10 | else: 11 | print("the program ran successfully!!!") 12 | -------------------------------------------------------------------------------- /Python/03 - Simple if - else usage/main.py: -------------------------------------------------------------------------------- 1 | """Showing a simple usage about the if-else statement""" 2 | 3 | a = int(input("enter first number: ")) 4 | b = int(input("enter second number: ")) 5 | 6 | sum = a + b 7 | 8 | if(sum > 40): 9 | 10 | print("The sum is over 40:", sum) 11 | else: 12 | 13 | print("The sum is under 40:", sum) 14 | -------------------------------------------------------------------------------- /Python/26 - file manipulation - reading a file/main.py: -------------------------------------------------------------------------------- 1 | #Reading a file comes in python comes in handy when dealing files that contain data that will later be manipulated 2 | 3 | #to read a file in python 4 | f = open("numbers.csv", "r") 5 | print(f.readline()) 6 | 7 | #Besides csv files, excel, json and other file formats can be read and later manipulated 8 | -------------------------------------------------------------------------------- /C++/04 - For loops/simple example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // prints the numbers 0-9 (i.e. 10 numbers) 8 | for (int i = 0; i < 10; i++){ 9 | cout << i << endl; 10 | } 11 | 12 | //note, you can leve empty parameters too: 13 | for(; !condition;){ 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.22 3 | 4 | # compile CXX with /usr/bin/c++ 5 | CXX_DEFINES = 6 | 7 | CXX_INCLUDES = -I"/home/fab/Scrivania/Objects as parameters/include" 8 | 9 | CXX_FLAGS = 10 | 11 | -------------------------------------------------------------------------------- /Python/01 - Usage of variables and Printf/main.py: -------------------------------------------------------------------------------- 1 | # This is a sample Python script For Beginners. 2 | 3 | # Press Maiusc+F10 to execute it or replace it with your code. 4 | # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. 5 | 6 | 7 | print("Hello world!"); 8 | 9 | print("This is a new line!"); 10 | -------------------------------------------------------------------------------- /Golang/01 - Hello World/main.go: -------------------------------------------------------------------------------- 1 | /*Specify package name based on function name. import fmt which stands for format library ot do I/O operations, declare the function and print 2 | 3 | NOTE: go does not accept the brackets of a function in a newline. 4 | 5 | */ 6 | 7 | package main 8 | 9 | import "fmt" 10 | 11 | func main() { 12 | fmt.Print("Hello") 13 | } 14 | -------------------------------------------------------------------------------- /Golang/09 - Package Scope/main.go: -------------------------------------------------------------------------------- 1 | /* We can handle the package scope to get functions and variables from other .go files 2 | 3 | NOTE: you need to run all go files to make it work. simply run go run *, or you can separately write the file names. 4 | */ 5 | 6 | package main 7 | 8 | import "fmt" 9 | 10 | func main() { 11 | hello() 12 | fmt.Println(a) 13 | } 14 | -------------------------------------------------------------------------------- /R/Syntax/Built-inFunctions.R: -------------------------------------------------------------------------------- 1 | #Built-In Functions 2 | 3 | #getwd() - prints the current directory 4 | getwd() 5 | 6 | #setwd() - changes the directory that you will perform analytics on 7 | setwd() 8 | 9 | #print() - 10 | print() 11 | 12 | #install.packages() - 13 | install.packages("tidyverse") 14 | 15 | #import a library in R 16 | library(tidyverse) 17 | -------------------------------------------------------------------------------- /Golang/09 - Package Scope/file.go: -------------------------------------------------------------------------------- 1 | /*this file takes the same package as the referenced go file, each file is a package on its own. 2 | we can reference global vars/structs in this way. But no local vars/structs tied to a function.*/ 3 | 4 | package main 5 | 6 | import "fmt" 7 | 8 | var a = 10 9 | 10 | func hello() { 11 | fmt.Println("Hello from file") 12 | } 13 | -------------------------------------------------------------------------------- /Python/22 - error handling - raise/main.py: -------------------------------------------------------------------------------- 1 | """ The raise command manually raises an exception when a condition has been met """ 2 | 3 | try: 4 | #input a negative number and an error message will print 5 | z = (input("Enter a number:")) 6 | if z < 0: 7 | raise ValueError("This is not a positive number") 8 | 9 | except ValueError as value: 10 | print(value) 11 | -------------------------------------------------------------------------------- /C++/11 - String C++/std::String to const char */src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void cstring(char *string) 4 | { 5 | std::cout << string << std::endl 6 | } 7 | 8 | int main(void) 9 | { 10 | std::string s = "hello"; 11 | 12 | //c_str() operator casts a C++ string into a C string, (aka char*/const char *) 13 | cstring(s.c_str()); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Python/21 - error handling - try except else finally/main.py: -------------------------------------------------------------------------------- 1 | """ No matter what happens to the code whatever is inside of the finally command will run """ 2 | 3 | 4 | try: 5 | print("The program is running") 6 | 7 | except: 8 | print("there is an error") 9 | 10 | else: 11 | print("the program ran successfully") 12 | 13 | finally: 14 | print("now on to the next program") 15 | -------------------------------------------------------------------------------- /Python/28 - file manipulation - appending a file/main.py: -------------------------------------------------------------------------------- 1 | #Appedning a file 2 | 3 | #creating the file 4 | filename = "example.txt" 5 | 6 | #Opening the file 7 | file = open(filename, 'a') 8 | 9 | #Inputing 3 names and then storing them in a file 10 | for i in range(0,3): 11 | name = input("Enter a name: ") 12 | file.write(name + "\n") 13 | #closing the file 14 | file.close() 15 | -------------------------------------------------------------------------------- /Python/27 - file manipulation - writing a file/main.py: -------------------------------------------------------------------------------- 1 | # Writing a filing comes in handy when analyzing data and later storing it 2 | 3 | #Creating the file 4 | filename = "example.txt" 5 | 6 | #Opening the file 7 | file = open(filename, 'w') 8 | 9 | #Storing numbers 1-10 in the file 10 | for i in range(1,11): 11 | file.write("This is line %i.\n" % i) 12 | 13 | #Closing the file 14 | file.close() 15 | -------------------------------------------------------------------------------- /C++/08 - Function Return Values/Simple Int Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int numShoes() 6 | { 7 | return 6; 8 | } 9 | 10 | int main() 11 | { 12 | // you can call a function to retrieve a value 13 | int num = numShoes(); 14 | // Prints "Bobby has 6 pairs of shoes." 15 | cout << "Bobby has " << num << " pairs of shoes." << endl; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Basic OOP with object/src/class.h: -------------------------------------------------------------------------------- 1 | #ifndef AE602913_273D_43F0_AE27_865A5A580684 2 | #define AE602913_273D_43F0_AE27_865A5A580684 3 | #include 4 | class test { 5 | public: 6 | void print1(); 7 | void print2(); 8 | }; 9 | 10 | class test2 { 11 | public: 12 | void add(); 13 | }; 14 | 15 | #endif /* AE602913_273D_43F0_AE27_865A5A580684 */ 16 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/classes in .h and .cpp/src/class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //declaring members created, so they are effective. 4 | int mainclass::a; 5 | int mainclass::b; 6 | 7 | void mainclass::inputa() { 8 | cin >> a; 9 | } 10 | 11 | void mainclass::inputb(){ 12 | cin >> b; 13 | } 14 | 15 | void mainclass::output(){ 16 | cout << "A: " << a << "B: " << b << endl; 17 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/include/class.h: -------------------------------------------------------------------------------- 1 | #ifndef A587FB58_3DE7_4760_813E_B54225A6CC31 2 | #define A587FB58_3DE7_4760_813E_B54225A6CC31 3 | #include 4 | 5 | class A { 6 | public: 7 | int b; 8 | void in(); 9 | 10 | }; 11 | 12 | class B { 13 | public: 14 | 15 | void out(A grab); 16 | 17 | }; 18 | 19 | #endif /* A587FB58_3DE7_4760_813E_B54225A6CC31 */ 20 | -------------------------------------------------------------------------------- /Python/11 - function - parameters/main.py: -------------------------------------------------------------------------------- 1 | def totalAmt(price, tip): 2 | return price + tip 3 | 4 | def tipAmt(price): 5 | return price * 0.18 6 | 7 | price = input("How much was your dinner bill?\n") 8 | 9 | # you can call a function to retrieve a value 10 | tip = tipAmt(price) 11 | print("Then you should tip at least $" + str(tip)) 12 | 13 | total = totalAmt(price, tip) 14 | print("This will be a grand total of $" + str(total)) -------------------------------------------------------------------------------- /C++/20 - Pointers C++/Access single variable memory/src/main.cpp: -------------------------------------------------------------------------------- 1 | //NOTE: works for C too. 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int *a = (int*)malloc(sizeof(int); 10 | 11 | cout << "Insert a number" << endl; 12 | 13 | for (size_t i = 0; i < 1; i++) { 14 | cin >> *a; 15 | if (a[i] == 1){ 16 | cout << "Number detected" << endl; 17 | } 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/app/src/main/java/example2/app/App.java: -------------------------------------------------------------------------------- 1 | package example2.app; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | int age = 20; 6 | int beans = 9; 7 | String profession = "A coffee machine."; 8 | 9 | System.out.println("I am "+age+" years old"); 10 | System.out.println("I am "+profession+" and I got "+beans+" coffee beans ready to grind"); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Python/17 - error handling - try except/main.py: -------------------------------------------------------------------------------- 1 | """ Error handling is a concept where programmers can customize error messages. 2 | In python try except is commonly used for error handling""" 3 | 4 | #try statement runs the code 5 | try: 6 | #type a word 7 | print(input("Enter a number:")) 8 | 9 | #except statement catches detects the error and this is where you can customize the error message 10 | except: 11 | print("The input is not a number") 12 | -------------------------------------------------------------------------------- /Golang/05 - Sorting Arrays/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | ) 7 | 8 | func main() { 9 | 10 | var ages = []int{40, 20, 15} 11 | sort.Ints(ages) 12 | fmt.Println(ages) 13 | 14 | // finds integer at index AFTER you've sorted the array 15 | var index = sort.SearchInts(ages, 40) 16 | fmt.Println(index) 17 | 18 | var names = []string{"Fabx", "SSUPII", "Hashkell"} 19 | sort.Strings(names) 20 | fmt.Println(names) 21 | } 22 | -------------------------------------------------------------------------------- /Python/18 - error handling - try except ZeroDivisionError/main.py: -------------------------------------------------------------------------------- 1 | """ There are many forms of errors in python. ZeroDivisionError is a type of error where a number is divided by 0 which is not possible""" 2 | 3 | 4 | try: 5 | 6 | print(input("Enter the number zero:", zero)) 7 | 8 | #dividing a number by zero 9 | 1/zero 10 | #when error occurs the except will print a customize message 11 | except: 12 | print("Cannot divide a number by zero") 13 | 14 | -------------------------------------------------------------------------------- /Python/04 - Simple if - elif usage/main.py: -------------------------------------------------------------------------------- 1 | 2 | #Showing a simple usgae about the elif statement 3 | 4 | a = int(input("enter the first number: ")) 5 | b = int(input("enter the second number: ")) 6 | 7 | sum = a + b 8 | 9 | if(sum < 0 ): 10 | print("The sum is below 0", sum) 11 | elif(sum > 0 and sum < 40): 12 | print("The sum is positive but below 40 ", sum) 13 | else: 14 | print("The sum is above 40") 15 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/classes in .h and .cpp/include/class.h: -------------------------------------------------------------------------------- 1 | #ifndef A1F6E7A6_AF9E_4A6C_9A91_1253968866C0 2 | #define A1F6E7A6_AF9E_4A6C_9A91_1253968866C0 3 | #include 4 | class mainclass { 5 | private: 6 | static int a, b; //creating members. 7 | public: 8 | static void inputa(); 9 | static void inputb(); 10 | static void output(); 11 | }; 12 | 13 | 14 | 15 | #endif /* A1F6E7A6_AF9E_4A6C_9A91_1253968866C0 */ 16 | -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/NOTE.txt: -------------------------------------------------------------------------------- 1 | It is important to notice that the binary lenghts of the numbers depends on the architecture we are compiling for, 2 | and the types we are using. 3 | 4 | If we use normal "int" by default it's 64bits, which is represented with 8 numbers of 4 bytes: 5 | 6 | 1 = 00000001 where 8 x 4 = 64. 7 | 8 | The bitwise operators can also be used in assignation context: 9 | 10 | a ^= 10 equivalent of: a = a ^ 10; 11 | 12 | 13 | THESE OPERANDS WORK IN C TOO. -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = '3 - Mathematical operations' 11 | include('app') 12 | -------------------------------------------------------------------------------- /Python/30 - Object oriented programming - Methods/main.py: -------------------------------------------------------------------------------- 1 | #Class is the data structure for object oriented programming 2 | class Car: 3 | def __init__(self,make,model,year): 4 | self.make = make 5 | self.model = model 6 | self.year = year 7 | 8 | #Methods are functions within a class 9 | def color(self, color): 10 | return f'My {self.make} {self.model} is ' + color 11 | 12 | b = Car("Honda", "Civic", "2007") 13 | #Printing the method 14 | print(b.color("Blue")) 15 | 16 | 17 | -------------------------------------------------------------------------------- /Assembly/x86/4 - Loops/main.asm: -------------------------------------------------------------------------------- 1 | ; we can loop a function using the cmp and jmp instruction to repeat a specific sequence. 2 | ; in this case we loop until EAX is less than 0xf 3 | 4 | section .text 5 | 6 | 7 | global main 8 | 9 | main: 10 | mov ebp, esp; for correct debugging 11 | mov eax, 0x1 12 | jmp func 13 | 14 | 15 | func: 16 | add eax, eax 17 | cmp eax, 0xf 18 | jl func 19 | mov eax, 0x1 20 | mov ebx, 0x0 21 | int 0x80 22 | 23 | -------------------------------------------------------------------------------- /C/13 - Header files/include/header.h: -------------------------------------------------------------------------------- 1 | #ifndef C86F6563_6541_4697_87CE_61977F80DAC9 2 | #define C86F6563_6541_4697_87CE_61977F80DAC9 3 | 4 | //needed only if we write functions standard C instructions 5 | #include 6 | 7 | void function(); //declaration only, will be linked to header.c 8 | 9 | static inline void func() { //declaration and definition, will be linked where it's used. 10 | printf("do something\n"); 11 | } 12 | 13 | #endif /* C86F6563_6541_4697_87CE_61977F80DAC9 */ 14 | -------------------------------------------------------------------------------- /C/99extras/08 - Atoi()/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.c 3 | * @author Fabxx 4 | * @brief Atoi converts string numbers into actual numbers. 5 | NOTE: For doubles use "atof". 6 | * @version 0.1 7 | * @date 2023-01-31 8 | * 9 | * @copyright Copyright (c) 2023 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | char *string = "1024"; 19 | int num = atoi(string); 20 | 21 | printf("number: %d\n", num); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/main.dir/src/class.cpp.o" 3 | "CMakeFiles/main.dir/src/class.cpp.o.d" 4 | "CMakeFiles/main.dir/src/main.cpp.o" 5 | "CMakeFiles/main.dir/src/main.cpp.o.d" 6 | "main" 7 | "main.pdb" 8 | ) 9 | 10 | # Per-language clean rules from dependency scanning. 11 | foreach(lang CXX) 12 | include(CMakeFiles/main.dir/cmake_clean_${lang}.cmake OPTIONAL) 13 | endforeach() 14 | -------------------------------------------------------------------------------- /C++/21 - Template example/Basic example 2/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | template 6 | 7 | class text { 8 | public: 9 | type array[value]; 10 | }; 11 | 12 | 13 | int main() { 14 | 15 | text nameoftemplate; 16 | for (size_t i = 0; i < 5; i++){ 17 | cin >> nameoftemplate.array[i]; 18 | } 19 | for (size_t i = 0; i < 5; i++){ 20 | cout << " " << nameoftemplate.array[i]; 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C/HEADER FILE NOTES.txt: -------------------------------------------------------------------------------- 1 | In order for the compiler to recognize all the declarations, the header files must be put in the same order when those are referenced. 2 | 3 | Also note to put always the standard libraries before any custom library made by you. 4 | 5 | example: 6 | 7 | main(){ 8 | setup4(); 9 | setup3(setup2); 10 | 11 | order: 12 | 13 | #include 14 | 15 | void setup4(); 16 | 17 | #include 18 | void setup3(); 19 | 20 | #include 21 | void setup2(); 22 | 23 | 24 | -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = '2 - Saving values into variables and printing' 11 | include('app') 12 | -------------------------------------------------------------------------------- /C/README.md: -------------------------------------------------------------------------------- 1 | # C-Programming 2 | 3 | # Giving support/help 4 | ======= 5 | These projects very clearly explain you some of the basics of C programming and briefly covers all major topics for the beginners. These projects are made to help the understanding of the code for beginners that are practicing. If you want to contribute with this little "hobbie project", simply do a issue report about the syntax if there a mistake, or do a pull request about new functions. 6 | 7 | Thank you!! 8 | 9 | Happy coding!! 10 | 11 | ![](c.png) 12 | -------------------------------------------------------------------------------- /Python/15 - function - fizzbuzz continue statement/main.py: -------------------------------------------------------------------------------- 1 | """Continue statement skips over a condition and continues with the iteration """ 2 | 3 | 4 | def fizzbuzz(): 5 | for x in range(1,25): 6 | if x % 3 == 0 and x % 5 == 0: 7 | print("fizzbuzz") 8 | #Once it reaches 15 the loop will continue 9 | continue 10 | elif x % 3 == 0: 11 | print("fizz") 12 | continue 13 | elif x % 5 == 0: 14 | print("buzz") 15 | continue 16 | else: 17 | print(x) 18 | print("The loop has ended") 19 | 20 | fizzbuzz() 21 | -------------------------------------------------------------------------------- /Golang/17 - Switch/main.go: -------------------------------------------------------------------------------- 1 | /* Switch cases are useful for menu behaviors, or to let the code run specific instructions when a case that we expect happen 2 | 3 | default falls back to the standard case where all cases don't happen. 4 | */ 5 | 6 | package main 7 | 8 | import ( 9 | "fmt" 10 | ) 11 | 12 | func main() { 13 | 14 | var number int 15 | fmt.Scanf("%d", &number) 16 | 17 | switch number { 18 | case 1: 19 | fmt.Println("1") 20 | case 2: 21 | fmt.Println("2") 22 | default: 23 | fmt.Println("10") 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Python/23 - data manipulation - tuples/main.py: -------------------------------------------------------------------------------- 1 | """ Tuples are a data type that contains more than one item. Once a tuple has been created the contents cannot be changed """ 2 | 3 | 4 | 5 | tuple = (1,2,3,"four") 6 | 7 | print(tuple) 8 | 9 | 10 | #Indexing 11 | #Indexing allows the programmer to select an item in the tuple 12 | #Picking the first item in the tuple 13 | print(tuple[0]) 14 | 15 | #Selecting the last item in the tuple 16 | print(tuple[-1]) 17 | 18 | #Selecting more than one item in the tuple 19 | print(tuple[1:3]) 20 | -------------------------------------------------------------------------------- /C++/README.md: -------------------------------------------------------------------------------- 1 | 2 | # C++-Programming 3 | 4 | # Giving support/help 5 | 6 | These projects very clearly explain you some of the basics of c++ programming and briefly covers all major topics for the beginners. These projects are made to help the understanding of the code for beginners that are practicing. If you want to contribute with this little "hobbie project", simply do a issue report about the syntax if there a mistake, or do a pull request about new functions. 7 | 8 | Thank you!! 9 | 10 | Happy coding!! 11 | 12 | ![](c++.png) 13 | 14 | -------------------------------------------------------------------------------- /Python/README.md: -------------------------------------------------------------------------------- 1 | # Python-Programming 2 | 3 | # Giving support/help 4 | 5 | These projects very clearly explain you some of the basics of python programming and briefly covers all major topics for the beginners. These projects are made to help the understanding of the code for beginners that are practicing. If you want to contribute with this little "hobbie project", simply do a issue report about the syntax if there a mistake, or do a pull request about new functions. 6 | 7 | Thank you!! 8 | 9 | Happy coding!! 10 | 11 | ![](python.png) 12 | 13 | -------------------------------------------------------------------------------- /R/README.md: -------------------------------------------------------------------------------- 1 | # R-Programming 2 | 3 | # Giving support/help 4 | 5 | These projects very clearly explain you some of the basics of R programming and briefly covers all major topics for the beginners. These projects are made to help the understanding of the code for beginners that are practicing. If you want to contribute with this little "hobbie project", simply do an issue report about the syntax if there is a mistake, or do a pull request about the new functions. 6 | 7 | Thank you!! 8 | 9 | Happy coding!! 10 | 11 | ![image](index.jpeg) 12 | 13 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/3.22.3/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Linux-5.15.28-1-MANJARO") 2 | set(CMAKE_HOST_SYSTEM_NAME "Linux") 3 | set(CMAKE_HOST_SYSTEM_VERSION "5.15.28-1-MANJARO") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Linux-5.15.28-1-MANJARO") 9 | set(CMAKE_SYSTEM_NAME "Linux") 10 | set(CMAKE_SYSTEM_VERSION "5.15.28-1-MANJARO") 11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /Arduino/README.md: -------------------------------------------------------------------------------- 1 | # Arduino-Programming 2 | 3 | # Giving support/help 4 | 5 | These projects very clearly explain you some of the basics of Arduino hardware programming and briefly covers all major topics for the beginners. These projects are made to help the understanding of the code for beginners that are practicing. If you want to contribute with this little "hobbie project", simply do a issue report about the syntax if there a mistake, or do a pull request about new functions. 6 | 7 | Thank you!! 8 | 9 | Happy coding!! 10 | 11 | ![](arduino.png) 12 | -------------------------------------------------------------------------------- /Python/16 - function - fizzbuzz pass statement/main.py: -------------------------------------------------------------------------------- 1 | """Pass statement is a placeholder that does nothing and continues with the loop. """ 2 | 3 | 4 | def fizzbuzz(): 5 | for x in range(1,25): 6 | if x % 3 == 0 and x % 5 == 0: 7 | pass 8 | print("This is 15") 9 | elif x % 3 == 0: 10 | print("fizz") 11 | elif x % 5 == 0: 12 | print("buzz") 13 | else: 14 | print(x) 15 | print("The loop has ended") 16 | 17 | 18 | fizzbuzz() 19 | 20 | -------------------------------------------------------------------------------- /C++/06 - Break and continue/For loop/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // prints the numbers 0-6. 8 | // notice how numbers 7-10 aren't printed 9 | for (int i = 0; i < 10; i++){ 10 | cout << i << " "; 11 | 12 | if (i == 3){ 13 | cout << "continue " << endl; 14 | continue; 15 | } 16 | 17 | if (i == 6) { 18 | cout << "break! " << endl; 19 | break; 20 | } 21 | 22 | cout << "*" << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /C++/23 - List, stack, tail/2 - Stack example/swap function/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | 5 | int main() { 6 | 7 | stack stack1, stack2; 8 | 9 | for (size_t i = 0; i < 5; i++){ 10 | stack1.push(i+1); 11 | stack2.push(i+5); 12 | } 13 | //exchanges the stack1 values with stack2 values. 14 | stack1.swap(stack2); 15 | 16 | while (!stack1.empty()){ 17 | cout << "Elemet: " << stack1.top() << endl; 18 | stack1.pop(); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include "class.h" 4 | 5 | int main(){ 6 | 7 | /*here we redeclare the objects as pointers and use them as parameters again. This time for the other class it 8 | is necessary another object based on B, because we need to access a funciton in B. 9 | DO not use the objects as pointers or else you'll get a segfault.*/ 10 | 11 | A grab; 12 | B grab2; 13 | grab.in(); 14 | grab2.out(grab); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/src/class.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | #include "class.h" 3 | 4 | /*When gathering data between classes, we can use objects to store the data in those variables, but to not lose those data 5 | we have to use them as parameters and working in memory of those. We use the object for the same class in this case since the 6 | data we need is only in A. 7 | 8 | */ 9 | 10 | void A::in() { 11 | 12 | cin >> A::b; 13 | } 14 | 15 | void B::out(A grab) { 16 | 17 | cout << "" << grab.b << endl; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #project name 2 | project(main) 3 | 4 | #checking for min version of cmake 5 | cmake_minimum_required(VERSION 3.10) 6 | 7 | #including library directories, from extra packages too. 8 | include_directories(include) 9 | 10 | #adding source .cpp files directory 11 | aux_source_directory(src SOURCE) 12 | aux_source_directory(include INCLUDE) 13 | 14 | #creating executable with sources 15 | add_executable(main ${SOURCE}) 16 | 17 | #linking external libraries to executable 18 | target_link_libraries(main ${INCLUDE}) 19 | -------------------------------------------------------------------------------- /C++/16 - Vectors/4 - Input, sort, remove duplicate, output/include/class.h: -------------------------------------------------------------------------------- 1 | #ifndef DE1E89B1_35CE_4801_8185_1F1526798462 2 | #define DE1E89B1_35CE_4801_8185_1F1526798462 3 | #include 4 | using namespace std; 5 | #include 6 | 7 | using vett = vector; 8 | 9 | class vectors { 10 | 11 | private: 12 | static vett vector1; 13 | public: 14 | static void input(); 15 | static void sort(); 16 | static void remove_duplicated(); 17 | static void output(); 18 | }; 19 | 20 | 21 | #endif /* DE1E89B1_35CE_4801_8185_1F1526798462 */ 22 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/classes in .h and .cpp/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Showing how we implement class member declarations from .h 5 | * and .cpp file, the variables must be followed by an implementation as well. 6 | * @version 0.1 7 | * @date 2021-10-23 8 | * 9 | * @copyright Copyright (c) 2021 10 | * 11 | */ 12 | 13 | #include 14 | 15 | int main() { 16 | //calling out declarated members. 17 | mainclass::inputa(); 18 | mainclass::inputb(); 19 | mainclass::output(); 20 | system("pause"); 21 | return 0; 22 | 23 | } -------------------------------------------------------------------------------- /Python/24 - data manipulation - list/main.py: -------------------------------------------------------------------------------- 1 | """ Lists are a data type that contains more than one item. Unlike the tuple, a list can be manipulated""" 2 | 3 | #Indexing 4 | a = [1,2,3,4,5,6,7] 5 | 6 | #Printing the first item 7 | print(a[0]) 8 | 9 | #Printing the last item 10 | print(a[-1]) 11 | 12 | #Printing every other item 13 | print(a[0:6:2]) 14 | 15 | #Printing the length of the list 16 | print(len(a)) 17 | 18 | #Printing the minimum value in the list 19 | print(min(a)) 20 | 21 | ##Printing the maximum value in the list 22 | print(max(a)) 23 | 24 | #Changing the value of an item in the list 25 | a[3] = 10 26 | 27 | -------------------------------------------------------------------------------- /Python/29 - Object oriented programming - Making a class/main.py: -------------------------------------------------------------------------------- 1 | #Object oriented programming in python is a great way to reuse code 2 | 3 | #Class is the data structure for object oriented programming 4 | class Car: 5 | def __init__(self,make,model,year): 6 | self.make = make 7 | self.model = model 8 | self.year = year 9 | 10 | 11 | #__init__ initiates the class. 12 | # Car is the class attributes that defines the class 13 | #make, model, and year are instance attributes that assign a value once the class has been called 14 | 15 | #To print the make of the car 16 | a = Car("Honda", "Civic", 1975) 17 | print(a.make) 18 | -------------------------------------------------------------------------------- /C++/42 - std::jthread/42.5 - std::thread::hardware_concurrency()/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief this allows us to obtain the max number of threads avaialble on the system. 5 | * @version 0.1 6 | * @date 2023-03-23 7 | * 8 | * @copyright Copyright (c) 2023 9 | * 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | void get_thread_num() 16 | { 17 | std::cout << "threads available: " << std::jthread::hardware_concurrency() << std::endl; 18 | } 19 | 20 | int main(void) 21 | { 22 | std::jthread thread1(get_thread_num); 23 | thread1.join(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Python/14 - function - fizzbuzz break statement/main.py: -------------------------------------------------------------------------------- 1 | """Break statements will end a loop once a condition has been met. """ 2 | 3 | 4 | def fizzbuzz(): 5 | for x in range(1,25): 6 | if x % 3 == 0 and x % 5 == 0: 7 | print("fizzbuzz") 8 | #Once it reaches 15 the loop will end prematurely 9 | break 10 | elif x % 3 == 0: 11 | print("fizz") 12 | elif x % 5 == 0: 13 | print("buzz") 14 | else: 15 | print(x) 16 | print("The loop has ended") 17 | 18 | 19 | fizzbuzz() 20 | -------------------------------------------------------------------------------- /C++/C++ use of deleted function error.txt: -------------------------------------------------------------------------------- 1 | error: use of deleted function 2 | 3 | cause: passing a parameter without & in main. 4 | 5 | error: 6 | 7 | class 1 8 | { 9 | public: 10 | void func(string1); //string 1 is not *string1. 11 | } 12 | 13 | int main(void) 14 | { 15 | string string1; 16 | 17 | function(string1) //& missing on string1 18 | } 19 | 20 | this causes a use of deleted function because the constructor of the string deletes the previous string memory sector, and the values 21 | are not saved anywhere else. like a normal parameter if passed as argument in main, it needs the address operator to copy the memory. 22 | -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/NOT (~) bitwise operand/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The ~ operator performs a inversion operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 = 1 7 | * 1 = 0 8 | * 9 | * it's basically a ! negation. 10 | * 11 | * @version 0.1 12 | * @date 2023-03-22 13 | * 14 | * @copyright Copyright (c) 2023 15 | * 16 | */ 17 | 18 | #include 19 | 20 | int main(void) 21 | { 22 | //a = 00000111 23 | int a = 7; 24 | 25 | printf("NOT Result: %d\n", (~a)); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C++/19 - tytpedef and alias/Example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Alias method it's a new standard to define new types of data in C++, with the usage of using keyword. 5 | * in C we used typedef. 6 | * @version 0.1 7 | * @date 2021-10-20 8 | * 9 | * @copyright Copyright (c) 2021 10 | * 11 | */ 12 | #include 13 | using namespace std; 14 | using Newtype = int; //typedef equivalent in C++ 15 | typedef double NewtypeC; //standard typedef. 16 | using vett = vector 17 | 18 | int main() { 19 | Newtype a = 0; 20 | cout << "Hello world! Type number: " << a << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C++/06 - Break and continue/While loop/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int i = 0; 8 | // prints the numbers 0-6. 9 | // notice how numbers 7-10 aren't printed 10 | while (i != 10){ 11 | cout << i << " "; 12 | 13 | if (i == 3){ 14 | cout << "continue " << endl; 15 | i += 1; 16 | // skips the rest of the loop 17 | continue; 18 | } 19 | 20 | if(i == 6) { 21 | cout << "break! " << endl; 22 | break; 23 | } 24 | 25 | i += 1; 26 | cout << "*" << endl; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /C++/44 - Smart Pointers/44.0 - Introduction/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief Smart pointers are a wrapper for pointers. 5 | * 6 | * FEATURES: 7 | * -it can deallocate and free destroyed object memory automatically. 8 | * -the destructor is automatically called when an object goes out of scope, 9 | * the dynamically allocated memory will automatically be deleted (or the reference count can be decremented). 10 | * -additional features of memory management. 11 | * @version 0.1 12 | * @date 2023-03-24 13 | * 14 | * @copyright Copyright (c) 2023 15 | * 16 | */ -------------------------------------------------------------------------------- /C++/42 - std::jthread/42.2 - std::this_thread/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief std::this_thread is a namespace member that referres to the current thread where the function belongs to, 5 | * shares the same methods as std::jthread. 6 | * @version 0.1 7 | * @date 2023-03-23 8 | * 9 | * @copyright Copyright (c) 2023 10 | * 11 | */ 12 | 13 | void func() 14 | { 15 | //referres to thread1 16 | std::this_thread::get_id(); 17 | } 18 | 19 | int main(void) 20 | { 21 | //referres to main() thread. 22 | std::this_thread::get_id(); 23 | 24 | std::jthread thread1(func); 25 | 26 | thread1.join(); 27 | 28 | } -------------------------------------------------------------------------------- /Golang/10 - Maps/main.go: -------------------------------------------------------------------------------- 1 | /* Similar to dictionary, we can have maps of different types in go. In the square brackets we have to reference the value with the 2 | first type. When assignin a value we need to give a matching type of the second type*/ 3 | 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | 10 | var menu = map[int]string{ 11 | 1: "name", 12 | 2: "surname", 13 | } 14 | 15 | fmt.Println(menu[1]) 16 | 17 | var menu2 = map[string]int{ 18 | "Fabxx": 14, 19 | "SSUPII": 20, 20 | } 21 | 22 | fmt.Println(menu2["Fabxx"]) 23 | 24 | for index, value := range menu { 25 | fmt.Println(index, value) 26 | } 27 | 28 | menu[1] = "Fab" 29 | } 30 | -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/NOT (~) bitwise operand/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The ~ operator performs a inversion operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 = 1 7 | * 1 = 0 8 | * 9 | * it's similar to a ! negation. 10 | * 11 | * @version 0.1 12 | * @date 2023-03-22 13 | * 14 | * @copyright Copyright (c) 2023 15 | * 16 | */ 17 | 18 | #include 19 | 20 | int main(void) 21 | { 22 | //a = 00000111 23 | int a = 7; 24 | 25 | //will output in this case. 26 | std::cout << "NOT result: " << (~a) << std::endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/40 - "continue" keyword/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The continue keyword allows in a iteration (for, while, do-while) to skip the next instructions 5 | * and directly increase the counter until a specific condition is met. In this case we simply skip the 6 | * cout until i reaches 5. 7 | * @version 0.1 8 | * @date 2023-03-22 9 | * 10 | * @copyright Copyright (c) 2023 11 | * 12 | */ 13 | 14 | #include 15 | 16 | int main(void) 17 | { 18 | for (size_t i = 0; i < 10; i++) { 19 | if (i < 5) { 20 | continue; 21 | } 22 | std::cout << "not skipping this block!" << std::endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C/13 - Header files/src/main.c: -------------------------------------------------------------------------------- 1 | /*Header files can help in reducing the size of a source file in terms of lines. 2 | 3 | To include a local library: 4 | 5 | #include "libname.h" 6 | 7 | to include a system library: 8 | 9 | #include 10 | 11 | We can declare functions in header files, and then define their instructions in the related source code 12 | 13 | or 14 | 15 | we can define and declare the functions in the header files directly, without adding extra source files, 16 | with the use of static inline keywords. 17 | */ 18 | 19 | #include 20 | #include "header.h" 21 | 22 | int main(void) 23 | { 24 | func(); 25 | function(); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C++/25 - std::map/Hash table with hex values/include/randomizer.h: -------------------------------------------------------------------------------- 1 | #ifndef B0103129_13A4_4999_A7D4_7E795DB938D1 2 | #define B0103129_13A4_4999_A7D4_7E795DB938D1 3 | #include 4 | using namespace std; 5 | #include 6 | 7 | template 8 | class randomizer { 9 | public: 10 | random_device nameofseed; 11 | datatype number; //saving generated number. 12 | 13 | randomizer() { 14 | mt19937 mt(nameofseed()); 15 | uniform_int_distribution dist(INT_MIN, INT_MAX); 16 | number = dist(mt); 17 | } 18 | }; 19 | 20 | #endif /* B0103129_13A4_4999_A7D4_7E795DB938D1 */ 21 | -------------------------------------------------------------------------------- /C++/09 - Function Parameters/Simple Int Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | double totalAmt(double price, double tip) 6 | { 7 | return price + tip; 8 | } 9 | 10 | double tipAmt(double price) 11 | { 12 | return price * 0.18; 13 | } 14 | 15 | int main() 16 | { 17 | double price; 18 | double tip; 19 | double total; 20 | cout << "How much was your dinner bill?" << endl; 21 | cin >> price; 22 | 23 | // you can call a function to retrieve a value 24 | tip = tipAmt(price); 25 | cout << "Then you should tip at least $" << tip << endl; 26 | 27 | total = totalAmt(price, tip); 28 | cout << "This will be a grand total of $" << total << endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++/01 - Usage Of Variables and printf/simple print statements/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // NOTE: To run these programs, open terminal, go into the correct directory 6 | // ex: C++/1 - Usage of Variables and printf/complex print statements with variables 7 | // Run "g++ -o main main.cpp" and then "./main" 8 | 9 | int main() 10 | { 11 | // prints "My dad's name is Bob. He is 50 years old. 12 | // His first name starts with the letter B. For lunch, 13 | // he had a hamburger for $12.5." 14 | cout << "My dad's name is Bob. He is 50 years old. " 15 | "His first name starts with the letter B. " 16 | "For lunch, he had a hamburger for $12.50." << endl; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Golang/06 - Loops/main.go: -------------------------------------------------------------------------------- 1 | /* in GO there's mainly the for loop */ 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | ) 8 | 9 | func main() { 10 | 11 | for x := 0; x < 5; x++ { 12 | fmt.Println("Value of x:", x) 13 | } 14 | 15 | var y = 0 16 | 17 | for y < 5 { 18 | fmt.Println("Value of y:", y) 19 | y++ 20 | } 21 | 22 | var names = []string{"Fabxx", "SSUPII", "Hashkell"} 23 | 24 | for i := 0; i < len(names)-1; i++ { 25 | fmt.Println(names[i]) 26 | } 27 | 28 | /* We can use range keyword with two indexes, i takes the position, j is the string 29 | NOTE: if you don't want to use the index value, replace index with _ (underscore)*/ 30 | for index, strings := range names { 31 | fmt.Println(index, strings) 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /C++/20 - Pointers C++/Dynamic Matrix allocation/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Dynamic allocation of a matrix. 5 | * @version 0.1 6 | * @date 2021-10-28 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | 18 | int rows = 3; 19 | int cols = 5; 20 | 21 | // dynamic allocation: 22 | int *matrix = new int[rows*cols]; 23 | 24 | // iteration & printing: 25 | for (int i=0; i 17 | #include 18 | 19 | using namespace std; 20 | 21 | 22 | int main() { 23 | 24 | int x = 0; 25 | cin >> x; 26 | if (x == 1){ 27 | PlaySound("doggo1.wav", NULL, SND_SYNC); 28 | } else { 29 | PlaySound("gemma.wav", NULL, SND_SYNC); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Golang/07 - Boolean and Conditionals/main.go: -------------------------------------------------------------------------------- 1 | /* Boolean Algebra usage. Continue keyword basically skips the current loop cicle and goes to the next one. 2 | Useful if you need to skip further instructions.*/ 3 | 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | 10 | age := 20 11 | 12 | fmt.Println(age < 25, age > 21) 13 | 14 | if age < 18 { 15 | fmt.Println("Age is lower than 18") 16 | } else if age > 18 { 17 | fmt.Println("Age is bigger than 18") 18 | } else { 19 | fmt.Println("Age matches 18") 20 | } 21 | 22 | names := []string{"Fabxx", "SSUPII", "Hashkell"} 23 | 24 | for index, strings := range names { 25 | if index < 2 && strings != names[2] { 26 | fmt.Println("Skipping...") 27 | continue 28 | } 29 | fmt.Println("String is:", names[index]) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Virtual class extension/Operation override/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class a 5 | { 6 | public: 7 | virtual void operation() 8 | { 9 | int a = 10, b = 10; 10 | cout << "Operation is: " << a+b << endl; 11 | } 12 | }; 13 | 14 | class b : public a 15 | { 16 | public: 17 | void operation() 18 | { 19 | int a = 10, b = 10; 20 | cout << "Operation is: " << a-b << endl; 21 | } 22 | }; 23 | 24 | int main(void) 25 | { 26 | a obj1, *obj2 = new a(); 27 | 28 | obj1.operation(); //will give 20 29 | 30 | //before the override will give 20 31 | obj2->operation(); 32 | //after the override will give 0. 33 | obj2 = new b(); 34 | obj2->operation(); 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C/99extras/02 - snprintf usage/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char const *argv[]) 3 | { 4 | char buffer[256]; //buffer to be used 5 | 6 | //variables to be printed must be const char *, they don't have to be edited in memory and we need to access the memory via pointer. 7 | const char *name = "Revix"; 8 | 9 | 10 | //printing the strings in the memory buffer provided and stored in here. snprintf handles automatically how many bytes have to be stored. 11 | //Don't use sprintf, it doesn't handle the memory and might cause a stack corruption 12 | snprintf(buffer, sizeof(buffer), 13 | "My name is: %s\n", name); 14 | 15 | printf("The string printed in the buffer is: %s\n\n", buffer); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.22 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/fab/Scrivania/Objects as parameters") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/fab/Scrivania/Objects as parameters") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /C/14 - ? and : conditional operators/src/main.c: -------------------------------------------------------------------------------- 1 | /*These are called ternary operators. It is a more compact way of writing conditions. 2 | 3 | the syntax is explained as follows: 4 | 5 | is a = to 0? if no give to it the value of 10, if yes give it 20. 6 | 7 | equivalent of: 8 | 9 | if (a == 0) { 10 | a = 20; 11 | } else { 12 | a = 10 13 | } 14 | 15 | as you can see it is way more compact to write it like so. but an if-else becomes mandatory when we need 16 | nested conditions with else ifs and so on. If it's only a single condition to verify then the syntax above can be more clean. 17 | 18 | */ 19 | 20 | #include 21 | 22 | int main(void) 23 | { 24 | int a = 0, b = 0; 25 | 26 | a = 0 ? 10 : 20; 27 | 28 | printf("value of a: %d\n", a); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C++/36 - this pointer/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief "this" is an implicit pointer that can be used inside a class/class function, to access a class member. Can't be used inside static functions. 5 | * @version 0.1 6 | * @date 2023-01-31 7 | * 8 | * @copyright Copyright (c) 2023 9 | * 10 | */ 11 | 12 | #include 13 | 14 | class A 15 | { 16 | public: 17 | int x; 18 | void change_x(int x); 19 | }; 20 | 21 | //this referres to A::x. 22 | void A::change_x(int x) 23 | { 24 | this->x = x; 25 | } 26 | 27 | int main(void) 28 | { 29 | A obj; 30 | int myx = 10; 31 | obj.x = 20; 32 | 33 | std::cout << "x member before change: " << obj.x << std::endl; 34 | obj.change_x(myx); 35 | std::cout << "x member after change: " << obj.x << std::endl; 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++/04 - For loops/complex examples/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // backwards iteration 8 | // prints the numbers 10-1 (i.e. 10 numbers) 9 | cout << "Rocket Launch:" << endl; 10 | for (int i = 10; i > 0; i--){ 11 | cout << i << endl; 12 | } 13 | cout << "Blast off!\n" << endl; 14 | 15 | // every other number 16 | // prints every other number 0-10(i.e. 5 numbers) 17 | cout << "Even numbers:" << endl; 18 | for (int i = 0; i < 10; i+=2){ 19 | cout << i << endl; 20 | } 21 | cout << "\n"; 22 | 23 | // every other number backwards 24 | // prints every other number 10-0(i.e. 5 numbers) 25 | cout << "Even numbers:" << endl; 26 | for (int i = 10; i > 0; i-=2){ 27 | cout << i << endl; 28 | } 29 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Basic OOP with object/src/class.cpp: -------------------------------------------------------------------------------- 1 | #include "class.h" 2 | using namespace std; 3 | 4 | /* 5 | NOTE: members AND variables of the same class don't need an object to be called. those can be called directly when defining. 6 | when calling inside ANY other function (class function or normal function), an object is required, like it happens in 7 | test2 class function, we are calling "test" functions, which is another class. 8 | */ 9 | 10 | void test::print1() { 11 | cout << "Printing" << endl; 12 | } 13 | 14 | void test::print2() { 15 | cout << "Printing again" << endl; 16 | } 17 | 18 | 19 | void test2::add() { 20 | //objects must be local to the function where we need to use it, or else we get a multiple declaration error. 21 | test obj; 22 | obj.print1(); 23 | obj.print2(); 24 | } 25 | -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/OR (|) bitwise operand/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The | operator performs a comparison operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 1 7 | * 0 0 = 0 8 | * 1 0 = 1 9 | * 1 1 = 1 //always returns 1 if at least one of the two bits is 1. 10 | * 11 | * In this example we take two numbers and perform the OR op. on their bits. 12 | * 13 | * @version 0.1 14 | * @date 2023-03-22 15 | * 16 | * @copyright Copyright (c) 2023 17 | * 18 | */ 19 | 20 | #include 21 | 22 | int main(void) 23 | { 24 | //a = 00000111, b = 00001001 25 | int a = 7, b = 9; 26 | 27 | //will output 15 in this case. 28 | printf("OR Result: %d\n", ( a | b)); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/XOR (^) bitwise operand/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The ^ operator performs a exclusive comparison operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 1 7 | * 0 0 = 0 8 | * 1 0 = 1 9 | * 1 1 = 0 //always returns 1 if the two bits are different. 10 | * 11 | * In this example we take two numbers and perform the OR op. on their bits. 12 | * 13 | * @version 0.1 14 | * @date 2023-03-22 15 | * 16 | * @copyright Copyright (c) 2023 17 | * 18 | */ 19 | 20 | #include 21 | 22 | int main(void) 23 | { 24 | //a = 00000111, b = 00001001 25 | int a = 7, b = 9; 26 | 27 | //will output 14 in this case. 28 | printf("XOR Result: %d\n", (a ^ b)); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/OR (|) bitwise operand/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The | operator performs a comparison operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 1 7 | * 0 0 = 0 8 | * 1 0 = 1 9 | * 1 1 = 1 //always returns 1 if at least one of the two bits is 1. 10 | * 11 | * In this example we take two numbers and perform the OR op. on their bits. 12 | * 13 | * @version 0.1 14 | * @date 2023-03-22 15 | * 16 | * @copyright Copyright (c) 2023 17 | * 18 | */ 19 | 20 | #include 21 | 22 | int main(void) 23 | { 24 | //a = 00000111, b = 00001001 25 | int a = 7, b = 9; 26 | 27 | //will output 15 in this case. 28 | std::cout << "OR result: " << (a | b) << std::endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/XOR (^) bitwise operand/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The ^ operator performs a exclusive comparison operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 1 7 | * 0 0 = 0 8 | * 1 0 = 1 9 | * 1 1 = 0 //always returns 0 if the two bits are equal. 10 | * 11 | * In this example we take two numbers and perform the OR op. on their bits. 12 | * 13 | * @version 0.1 14 | * @date 2023-03-22 15 | * 16 | * @copyright Copyright (c) 2023 17 | * 18 | */ 19 | 20 | #include 21 | 22 | int main(void) 23 | { 24 | //a = 00000111, b = 00001001 25 | int a = 7, b = 9; 26 | 27 | //will output 14 in this case. 28 | std::cout << "XOR result: " << (a ^ b) << std::endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C++/11 - String C++/finding substring and specific characters in a string/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | 5 | int main() { 6 | 7 | string string1; 8 | string string2; 9 | size_t pos; 10 | string string3; 11 | 12 | getline(cin, string1); 13 | 14 | //giving to string2 the characters from string1 from beginning until it's lenght it's reached. 15 | string2 = string1.substr(0, string1.length()); 16 | cout << "String2 content found in string1: " << string2 << endl; 17 | 18 | //giving exact characters to find with a size_t variable type, and stored with a sort of iterator 19 | pos = string1.find("Hello"); 20 | //Findind substring with given stored pos. 21 | string3 = string1.substr(pos); 22 | 23 | cout << "Word found and applied on string3: " << string3 << endl; 24 | 25 | return 0; 26 | 27 | } -------------------------------------------------------------------------------- /C/08 - Preprocessor Directives/src/main.c: -------------------------------------------------------------------------------- 1 | /*Can be used to do different operations at compile time, such as: 2 | 3 | -defining variables 4 | -compiling specific functions based on macro (example, using a function only if under linux/windows). 5 | 6 | For macro list, see here: 7 | 8 | https://github.com/cpredef/predef 9 | */ 10 | 11 | #include 12 | 13 | 14 | #ifdef __linux__ 15 | 16 | void Function() { 17 | printf("printing in linux!\n"); 18 | } 19 | 20 | #elif defined _WIN32 21 | 22 | void Function() { 23 | printf("printing in windows!\n"); 24 | } 25 | 26 | #endif 27 | 28 | #ifndef variable 29 | 30 | #define variable 31 | 32 | #endif 33 | 34 | int main(void) 35 | { 36 | Function(); 37 | 38 | #ifdef variable 39 | printf("Variable has been defined at compile time\n"); 40 | #endif 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Python/25 - data manipulation - dictionaries/main.py: -------------------------------------------------------------------------------- 1 | """ Dictionaries are a data type that stores a key and a value """ 2 | 3 | 4 | #An example of what a dictionary looks like 5 | #First value is the key and the second value is the value 6 | a = {"make": "toyota", "model":"rav4"} 7 | 8 | print(a) 9 | 10 | #printing the keys in the dictionary 11 | print(a.keys()) 12 | 13 | #printing the values in the dictionary 14 | print(a.values()) 15 | 16 | #adding a item in a dictionary 17 | a["year"] = 2005 18 | print(a) 19 | 20 | 21 | #Changing a value in dictionary 22 | a["year"] = 2009 23 | 24 | #printing the items in the dictionary 25 | print(a.items()) 26 | 27 | 28 | #removing an item in a dictionary 29 | #popitem() removes the last item in the dictionary 30 | a.popitem() 31 | print(a) 32 | 33 | #Clearing the dictionary 34 | a.clear() 35 | print(a) 36 | 37 | 38 | -------------------------------------------------------------------------------- /C++/05- While loops/complex examples/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int i = 10; 8 | // prints the numbers 10-1 (i.e. 10 numbers) 9 | cout << "Backwards iteration:" << endl; 10 | while (i != 0){ 11 | cout << i << endl; 12 | i -= 1; 13 | // print. 14 | } 15 | cout << "\n"; 16 | 17 | i = 10; 18 | int num1 = 1; 19 | int num2 = 1; 20 | int total = 0; 21 | // prints the fibonacci sequence 22 | // ex: 1, 1, 2, 3, 5, 8, 12, etc. 23 | cout << "Fibonacci Sequence:" << endl; 24 | cout << num1 << " "; 25 | cout << num2 << " "; 26 | while (i != 0){ 27 | total = num1 + num2; 28 | cout << total << " "; 29 | 30 | num1 = num2; 31 | num2 = total; 32 | i -= 1; 33 | } 34 | cout << "\n"; 35 | } 36 | -------------------------------------------------------------------------------- /C++/14 - Casting/Reinterpret cast/uint8_t to unsigned char */main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | /** 4 | * @brief Reinterpet cast makes the compiler change the variable type to another, so that the compiler 5 | * can interpret that variable to a completely different type. The bits are seen with a different 6 | * layout, it can be used only with pointers or memory areas. 7 | * 8 | * @return int 9 | */ 10 | int main() 11 | { 12 | //-----UINT8_T to unsigned char * 13 | /*Here we print the pointer memory of a. in this case we're converting a uint8_t to unsigned char *. 14 | WHy uint8_t? a char is a equivalent of 8 bit, so we need the same data lenght for the integer, or we'll 15 | lose precision*/ 16 | uint8_t a = 90; 17 | std::cout << reinterpret_cast(&a) << endl; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/app/src/main/java/example3/app/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This Java source file was generated by the Gradle 'init' task. 3 | */ 4 | package example3.app; 5 | 6 | public class App { 7 | public static void main(String[] args) { 8 | int number = 10; 9 | double result; 10 | 11 | result = number + 6; //Addition 12 | System.out.println(number+"+6="+result); 13 | 14 | result = number - 8; //Subtraction 15 | System.out.println(number+"-8="+result); 16 | 17 | result = number * 4; //Multiplication 18 | System.out.println(number+"*4="+result); 19 | 20 | result = number / 5; //Division 21 | System.out.println(number+"/5="+result); 22 | 23 | result = number % 3; //Rest of the division, module 24 | System.out.println(number+"%3="+result); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/main.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Consider dependencies only in project. 3 | set(CMAKE_DEPENDS_IN_PROJECT_ONLY OFF) 4 | 5 | # The set of languages for which implicit dependencies are needed: 6 | set(CMAKE_DEPENDS_LANGUAGES 7 | ) 8 | 9 | # The set of dependency files which are needed: 10 | set(CMAKE_DEPENDS_DEPENDENCY_FILES 11 | "/home/fab/Scrivania/Objects as parameters/src/class.cpp" "CMakeFiles/main.dir/src/class.cpp.o" "gcc" "CMakeFiles/main.dir/src/class.cpp.o.d" 12 | "/home/fab/Scrivania/Objects as parameters/src/main.cpp" "CMakeFiles/main.dir/src/main.cpp.o" "gcc" "CMakeFiles/main.dir/src/main.cpp.o.d" 13 | ) 14 | 15 | # Targets to which this target links. 16 | set(CMAKE_TARGET_LINKED_INFO_FILES 17 | ) 18 | 19 | # Fortran module output directory. 20 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 21 | -------------------------------------------------------------------------------- /C++/25 - std::map/Hash table with hex values/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief A template can be used as a recipe to make new functions/classes/types of data 5 | * templates gives a way to create our function scheme to adopt for 6 | * new functions that we create. 7 | * NOTE: templates can be structured in header files only. 8 | * Basically this means: we can create our own functions with our scheme as a template. 9 | * @version 0.1 10 | * @date 2021-12-13 11 | * 12 | * @copyright Copyright (c) 2021 13 | * 14 | */ 15 | 16 | #include 17 | using namespace std; 18 | #include 19 | 20 | int main() { 21 | //constructor call with template. 22 | //this can be used to call constructor only with (). 23 | hashtable(); 24 | system("pause"); 25 | return 0; 26 | 27 | } -------------------------------------------------------------------------------- /C++/31 - std::array type/Basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | std::array arr; //equivalent of int arr[4]. 7 | std::array names; //can put multiple chars for each position, equivalent of char *names[]. 8 | std::arraychars; //can put single chars only for each position. 9 | 10 | for (size_t i = 0; i < 4; ++i) 11 | { 12 | //not using arr.push_back() like vector type. 13 | std::cin >> arr[i]; 14 | std::cout << "" << arr[i] << std::endl; 15 | } 16 | 17 | for (size_t i = 0; i < 2; ++i) 18 | { 19 | std::cin >> names[i]; 20 | std::cout << "Name put in the array of string type: " << names[i] << std::endl; 21 | } 22 | 23 | 24 | if (arr.size() == 4) 25 | { 26 | std::cout << "THe size of the first vector is: " << arr.size() << std::endl; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++/02 - Arithmetic/without variables/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // NOTE: To run these programs, open terminal, go into the correct directory 6 | // ex: C++/1 - Usage of Variables and printf/complex print statements with variables 7 | // Run "g++ -o main main.cpp" and then "./main" 8 | 9 | int main() 10 | { 11 | // Addition 12 | cout << "Addition: "; 13 | cout << 4 + 2 << endl; 14 | 15 | // Subtraction 16 | cout << "Subtraction: "; 17 | cout << 4 - 2 << endl; 18 | 19 | // Division 20 | cout << "Division: "; 21 | cout << 4 / 2 << endl; 22 | 23 | // Multiplication 24 | cout << "Multiplication: "; 25 | cout << 4 * 2 << endl; 26 | 27 | // Modulo (remainder) 28 | cout << "Modulo: "; 29 | // 14 / 3 = 4 remainder 2, so the modulo is 2 30 | cout << 14 % 3 << endl; 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C/15 - argc and argv/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | argc: argument counter, counts the arguments written in the terminal. 3 | 1 is the name of the program, 2 is the first argument, and so on. 4 | 5 | argv: argument vector, the strings used to represent the arguments, to trigget their behavior. 6 | 7 | in this case we can run the program as ./main --help 8 | 9 | argc must be bigger than 0, or else you will try to compare a unallocated string position, which causes 10 | a segfault because the vector is empty. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc > 1) { 19 | if (strcmp(argv[1], "--help") == 0) { 20 | printf("Displaying help:\n" 21 | "1) test\n" 22 | "2) something"); 23 | } 24 | 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C++/35 - std::pair/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief Equivalend of std::map, can also be compared, copied/moved. Unlike std::map though, it doesn't have a iterator for 5 | * multiple pair positions, so you can make only one pair, useful if multiple pairs are not needed. In that case, see the 6 | * chapter 26 - std::map. 7 | * @version 0.1 8 | * @date 2023-01-31 9 | * 10 | * @copyright Copyright (c) 2023 11 | * 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | int main() 18 | { 19 | std::pair string_pair; 20 | 21 | string_pair.first = 1; 22 | string_pair.second = "string"; 23 | 24 | std::cout << "First: " << string_pair.first << "\nSecond: " << string_pair.second << std::endl; 25 | 26 | //can also create a pair with this function: 27 | string_pair = std::make_pair(1, "string2"); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/11 - String C++/std::String to const char */CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #project name 2 | project(main) 3 | 4 | #checking for min version of cmake 5 | cmake_minimum_required(VERSION 3.10) 6 | 7 | #checking GTK packages, this is used for any external libraries. 8 | FIND_PACKAGE(PkgConfig REQUIRED) 9 | PKG_CHECK_MODULES(GTK REQUIRED gtk+-3.0) #replace gtk+-3.0 with the actual package name if there are external libraries to include. 10 | 11 | #including library directories, from extra packages too. 12 | include_directories(include) 13 | include_directories(${GTK_INCLUDE_DIRS}) 14 | link_directories(${GTK_LIBRARY_DIRS}) 15 | 16 | #adding source .cpp files directory 17 | aux_source_directory(src SOURCE) 18 | aux_source_directory(include INCLUDE) 19 | 20 | #creating executable with sources 21 | add_executable(main ${SOURCE}) 22 | 23 | #linking external libraries to executable 24 | target_link_libraries(main ${INCLUDE} ${GTK_LIBRARIES}) 25 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Basic OOP with object/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief SHowing basic OOP, when using an object to call class members, we create a copy of those members 5 | * in memory into a new buffer, so the static keyword won't be needed to reference member classes 6 | * and OOP won't be lost. 7 | 8 | NOTE: just like structs we can make array of objects if we initialize them like this: 9 | test2 *obj = new test2[5]; 10 | and each object will have a copy of its class in the heap. 11 | * @version 0.1 12 | * @date 2022-03-01 13 | * 14 | * @copyright Copyright (c) 2022 15 | * 16 | */ 17 | #include 18 | using namespace std; 19 | #include "class.h" 20 | 21 | int main() { 22 | test2 obj2; //calling here the object for test2 class to reach it's members. 23 | obj2.add(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/AND (&) bitwise operand/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The & operator performs a multiplication operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 0 7 | * 0 0 = 0 8 | * 1 0 = 0 9 | * 1 1 = 1 //only if both bits are 1 the multiplication returns 1 on the bits. 10 | * 11 | * In this example we take two numbers and perform the AND op. on their bits, they will return a 12 | * result equal to the other equivalent binary number 13 | * 14 | * @version 0.1 15 | * @date 2023-03-22 16 | * 17 | * @copyright Copyright (c) 2023 18 | * 19 | */ 20 | 21 | #include 22 | 23 | int main(void) 24 | { 25 | //a = 00000111, b = 00001001 26 | int a = 7, b = 9; 27 | 28 | //will output 1 in this case. 29 | printf("AND Result: %d\n", (a & b)); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/AND (&) bitwise operand/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief The & operator performs a multiplication operation on the bits of a variable. here's a table of results: 5 | * 6 | * 0 1 = 0 7 | * 0 0 = 0 8 | * 1 0 = 0 9 | * 1 1 = 1 //only if both bits are 1 the multiplication returns 1 on the bits. 10 | * 11 | * In this example we take two numbers and perform the AND op. on their bits, they will return a 12 | * result equal to the other equivalent binary number 13 | * 14 | * @version 0.1 15 | * @date 2023-03-22 16 | * 17 | * @copyright Copyright (c) 2023 18 | * 19 | */ 20 | 21 | #include 22 | 23 | int main(void) 24 | { 25 | //a = 00000111, b = 00001001 26 | int a = 7, b = 9; 27 | 28 | //will output 1 in this case. 29 | std::cout << "AND result: " << (a & b) << std::endl; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++/10 - Scope/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Global variable can be used in any function 5 | // Per good coding practices, variable names are all capitalized. 6 | int X = 10; 7 | 8 | void add15() { 9 | int y = 15; 10 | X = X + y; 11 | } 12 | 13 | void sub3() { 14 | int y = 3; 15 | X = X - 3; 16 | } 17 | 18 | int main() { 19 | cout << "Value of X, from main: " << X << endl; 20 | 21 | add15(); 22 | // should be 25 23 | cout << "Value of X, after add15: " << X << endl; 24 | 25 | sub3(); 26 | // should be 22 27 | cout << "Value of X, after sub3: " << X << endl; 28 | 29 | return 0; 30 | } 31 | 32 | // SUMMARY: 33 | // X is a global variable so it can be used anywhere 34 | // y is a local variable, so it can only be used in the function it is declared. 35 | // This is why y is declared both on 9 and 14. Without declaring y on one of these lines, 36 | // there would be an access error. -------------------------------------------------------------------------------- /C++/16 - Vectors/3 - [IMPORTANT] Operating with vector elements - Wrong and good ways/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_Y 4 | * @brief Sometimes we need to do operations on contiguous data, that becomes a problem when 5 | * the data is stored in different positions, it can result in redundant calculation 6 | * of members already used in a specific position. 7 | * we MUST have the data in the precise i/j/whatever index position. To do so, we 8 | * handle logically the elements with two or plus vectors. Here are different ways: 9 | * @version 0.1 10 | * @date 2021-10-26 11 | * 12 | * @copyright Copyright (c) 2021 13 | * 14 | */ 15 | #include 16 | #include 17 | #include 18 | using namespace std; 19 | 20 | int main() { 21 | 22 | //methods::two_vectors(); 23 | //methods::single_vector(); 24 | methods::single_vector_solution(); 25 | 26 | system("pause"); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Avoiding circular depency.cpp: -------------------------------------------------------------------------------- 1 | Something common that happens with objects and classes is a circular depency, basically explained like this: 2 | 3 | // file: A.h 4 | class A { 5 | B _b; 6 | }; 7 | 8 | // file: B.h 9 | class B { 10 | A _a; 11 | }; 12 | 13 | // file main.cc 14 | #include "A.h" 15 | #include "B.h" 16 | int main(...) { 17 | A a; 18 | } 19 | 20 | /*What happens is that the compiler looks for B in A.h, and in the meantime B.h is looking for A. Since there's a problem in terms of order 21 | it would be necessary to adjust it by using a third header or use another class above all the others which approaches both classes*/ 22 | 23 | // file: A.h 24 | class A { 25 | }; 26 | 27 | // file: B.h 28 | class B { 29 | }; 30 | 31 | //file C.h uses the already declared classes, this avoids circular depency and follows the compiler order and fixes the undeclared error. 32 | 33 | class C { 34 | A _a; 35 | B _b; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /C++/15 - mutable identifier/mutable string/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief Example with char string. 5 | * @version 0.1 6 | * @date 2021-10-11 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | 15 | class myclass { 16 | public: 17 | char string1 = 'A'; 18 | mutable char string2 = 'B'; 19 | 20 | myclass() { //class constructor, required by the constant to operate. 21 | string1 = 'F'; 22 | string2 = 'T'; 23 | } 24 | }; 25 | int main() { 26 | const myclass access; 27 | cout << "Chars before access:\n"; 28 | cout << access.string1 << " \n" << access.string2 << " \n"; 29 | //access.string1 = 'S'; //gives error, lvalue not editable. 30 | access.string2 = 'G'; 31 | cout << "Chars after access:\n"; 32 | cout << access.string1 << " \n" << access.string2 << " \n"; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++/C++ RAII definition.txt: -------------------------------------------------------------------------------- 1 | RAII (Resource acquisition is initialization) is a technique used in multi-threaded programs 2 | 3 | 4 | often used for controlling mutex locks in multi-threaded applications. 5 | In that use, the object releases the lock when destroyed. 6 | Without RAII in this scenario the potential for deadlock would be 7 | high and the logic to lock the mutex would be far from the logic to unlock it. 8 | With RAII, the code that locks the mutex essentially includes the logic that the lock 9 | will be released when execution leaves the scope of the RAII object. 10 | 11 | TL-DR: RAII Involves the use and handling of mutexes for multi threading to avoid deadlocks on them, 12 | and the use of heap-allocated objects shared with smart pointers. 13 | 14 | RAII depends on heap-based objects to be implicitly or explicitly deleted along all possible execution paths, 15 | in order to trigger its resource-releasing destructor (or equivalent). 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Python/15 - function - fizzbuzz continue statement/main.py.save: -------------------------------------------------------------------------------- 1 | """Pass statements """ 2 | 3 | 4 | def fizzbuzz(): 5 | for x in range(1,25): 6 | print(x) 7 | if x % 15 == 0: 8 | print("fizzbuzz") 9 | #Once it reaches 15 the loop will continue 10 | pass 11 | elif x % 3 == 0: 12 | print("fizz") 13 | elif x % 5 == 0: 14 | print("buzz") 15 | print("The loop has ended") 16 | 17 | 18 | fizzbuzz() 19 | 20 | """Continue statements """ 21 | 22 | 23 | def fizzbuzz(): 24 | for x in range(25): 25 | if x % 3 == 0: 26 | print("fizz") 27 | elif x % 5 == 0: 28 | print("buzz") 29 | elif x % 3 == 0 and x % 5 == 0: 30 | print("fizzbuzz") 31 | #Once it reaches 15 fizzbuzz wont be printed and the loop will continue 32 | continue 33 | print("The loop has ended") 34 | 35 | 36 | fizzbuzz() 37 | -------------------------------------------------------------------------------- /C++/07 - Switch Statements/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main () { 5 | char grade; 6 | // local variable declaration: 7 | cout << "What grade in Calculus did you get? " << endl; 8 | cout << "Only enter the letters A, B, C, D, or F: " << endl; 9 | cin >> grade; 10 | // switching the cases with single chars, in this case we used the char grade as a varaible. 11 | switch(grade) { 12 | case 'A' : 13 | cout << "Excellent!" << endl; 14 | break; 15 | case 'B' : 16 | cout << "Good job" << endl; 17 | break; 18 | case 'C' : 19 | cout << "Ok" << endl; 20 | break; 21 | case 'D' : 22 | cout << "Darn. So close to passing." << endl; 23 | break; 24 | case 'F' : 25 | cout << "C'mon!" << endl; 26 | break; 27 | default : 28 | cout << "Invalid grade" << endl; 29 | } 30 | cout << "Good bye." << endl; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++/16 - Vectors/3 - [IMPORTANT] Operating with vector elements - Wrong and good ways/include/methods.h: -------------------------------------------------------------------------------- 1 | #ifndef A7E2EB86_C503_439C_815B_36BCD3D14393 2 | #define A7E2EB86_C503_439C_815B_36BCD3D14393 3 | #include 4 | using namespace std; 5 | #include 6 | #include 7 | 8 | class methods { 9 | 10 | private: 11 | static int Xcoords; 12 | static int Ycoords; 13 | using vett = vector; 14 | 15 | public: 16 | 17 | static vett XYcoords; //single vector. 18 | static vett coords1; 19 | static vett coords2; 20 | static int totsum; 21 | static int tot_sum_single_vector; 22 | static int X, Y, XY; 23 | static int counter; 24 | static void two_vectors(); 25 | static void single_vector(); 26 | static void single_vector_solution(); 27 | }; 28 | #endif /* A7E2EB86_C503_439C_815B_36BCD3D14393 */ 29 | -------------------------------------------------------------------------------- /Golang/14 - Receiver Functions/main.go: -------------------------------------------------------------------------------- 1 | /* Associate functions to struct objects. THese functions can only be called by the used struct object. 2 | 3 | As showed below, i associated the function "values" to "mystruct", and in main i can call that function 4 | only through mystruct object. 5 | 6 | NOTE: you don't need to create another object based on my struct like the previous example. 7 | */ 8 | 9 | package main 10 | 11 | import "fmt" 12 | 13 | type mystruct struct { 14 | a int 15 | } 16 | 17 | func (structure mystruct) values() { 18 | structure.a = 10 19 | fmt.Println(structure.a) 20 | } 21 | 22 | func main() { 23 | mystruct.values(mystruct{}) 24 | 25 | /* alternatively can init struct object and call through object, the code above makes a mystruct{} init in place 26 | i'd recommend the second way since you don't istantiate another struct copy for every method. 27 | We will see this in the next chapter of pointer structs too.*/ 28 | 29 | structure := mystruct{} 30 | 31 | structure.values() 32 | } 33 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Friend Class/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * @brief A friend class can be used to access private/protected members of another class. 5 | * 6 | * @param argc 7 | * @param argv 8 | * @return int 9 | */ 10 | 11 | /*Note: We can declare friend class or function anywhere in the base class body whether its private, protected or public block. 12 | It works all the same.*/ 13 | class A 14 | { 15 | private: 16 | int a; 17 | 18 | protected: 19 | int b; 20 | 21 | public: 22 | friend class B; 23 | //init vars. 24 | A() 25 | { 26 | a = 10; 27 | b = 20; 28 | }; 29 | }; 30 | 31 | class B 32 | { 33 | public: 34 | void access(A vars); 35 | }; 36 | 37 | //accessing private and protected members via A object from B class, which is declared friend inside A. 38 | void B::access(A vars) 39 | { 40 | std::cout << vars.a << "\n" << vars.b << std::endl; 41 | } 42 | 43 | int main() 44 | { 45 | A vars; B obj; 46 | obj.access(vars); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C++/09 - Function Parameters/Complex Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void passByVal(int x) { 5 | x = 33; 6 | cout << "Value of x from passByVal: " << x << endl; 7 | } 8 | 9 | // adding the ampersand in front of the variable makes it pass by reference 10 | // pass by reference essentially means passing the actual variable rather 11 | // than just the VALUE of the variable. 12 | void passByRef(int &x) { 13 | x = 33; 14 | cout << "Value of x from passByRef: " << x << endl; 15 | } 16 | 17 | int main() { 18 | int x = 10; 19 | cout << "Value of x from main: " << x << endl; 20 | 21 | passByVal(x); 22 | // will still be 10 23 | cout << "Value of x, after passByVal " << x << endl; 24 | 25 | passByRef(x); 26 | // will now be 33 27 | cout << "Value of x, after passByRef " << x << endl; 28 | 29 | return 0; 30 | } 31 | 32 | // SUMMARY: 33 | // when you pass by ref, you can modify the original value. 34 | // when you pass by value, you only can read the original value. -------------------------------------------------------------------------------- /Java/02 - Saving values into variables and printing/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Java application project to get you started. 5 | * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle 6 | * User Manual available at https://docs.gradle.org/7.4.2/userguide/building_java_projects.html 7 | */ 8 | 9 | plugins { 10 | // Apply the application plugin to add support for building a CLI application in Java. 11 | id 'application' 12 | } 13 | 14 | repositories { 15 | // Use Maven Central for resolving dependencies. 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | // Use JUnit test framework. 21 | testImplementation 'junit:junit:4.13.2' 22 | 23 | // This dependency is used by the application. 24 | implementation 'com.google.guava:guava:30.1.1-jre' 25 | } 26 | 27 | application { 28 | // Define the main class for the application. 29 | mainClass = 'example2.app.App' 30 | } 31 | -------------------------------------------------------------------------------- /C++/27 - Goto/Basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief The goto usage it's useful to do a clear skip inside linked iterations, without overchecking 5 | * variables or using extra variables, tho it doesn't have to be abused, because it can create confusing 6 | * code in certain istances. in cases where the for needs multiple checks, this can be more clean 7 | * to skip a for. 8 | * @version 0.1 9 | * @date 2022-01-06 10 | * 11 | * @copyright Copyright (c) 2022 12 | * 13 | */ 14 | 15 | #include 16 | using namespace std; 17 | 18 | int main() { 19 | int x = 0; 20 | for (size_t i = 0; i < 20; i++) { 21 | for (size_t j = 0; j < 20; j++) { 22 | x++; 23 | if (x == 5){ 24 | cout << "X reached 5, skipping for to use related function." << endl; 25 | goto function; //declaration of goto with name of function, we spare doing i = 20. 26 | } 27 | } 28 | } 29 | //function creation. 30 | function: { 31 | cout << "skipped for!" << endl; 32 | } 33 | } -------------------------------------------------------------------------------- /Golang/13 - Structs and custom types/main.go: -------------------------------------------------------------------------------- 1 | /* definition of structures and custom types. To access struct members this is the syntax: 2 | 3 | variable := structname{ 4 | //init vars here with comma 5 | } 6 | 7 | unlike C, we can't directly access members of a struct by just typing structname.var, they have to be accessed by its object. 8 | 9 | So in this case i can't do mystruct.a but i have to do initStruct.a. The struct object is initialized as a copy of the struct 10 | we can also return that object if we need it, or pass it as a pointer. If it is not returned or passed by reference, the struct copy 11 | will be discarded after the function exits. 12 | */ 13 | 14 | package main 15 | 16 | import "fmt" 17 | 18 | type mystruct struct { 19 | a int 20 | b string 21 | c float32 22 | } 23 | 24 | func values() { 25 | initStruct := mystruct{ 26 | a: 10, 27 | b: "name", 28 | c: 1.0, 29 | } 30 | 31 | fmt.Println(initStruct.a) 32 | fmt.Println(initStruct.b) 33 | fmt.Println(initStruct.c) 34 | } 35 | 36 | func main() { 37 | values() 38 | } 39 | -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/casting types.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief Showing functions of static_cast<>(), const_cast, and more. 3 | * 4 | * static_cast` is used for cases where you basically want to reverse an implicit conversion, 5 | * with a few restrictions and additions. `static_cast` performs no runtime checks. 6 | * This should be used if you know that you refer to an object of a specific type, 7 | * and thus a check would be unnecessary. NOTE: casting to char takes ASCII table as reference. 8 | * 9 | dynamic_cast only works for pointers or references to polymorphic class types; 10 | const_cast can't change types, only const or volatile qualifiers; 11 | reinterpret_cast is for special circumstances, converting between pointers or references and completely unrelated types. 12 | Specifically, it won't do numeric conversions. 13 | C-style and function-style casts do whatever combination of static_cast, const_cast and reinterpret_cast is needed to get the job done. 14 | * @version 0.1 15 | * @date 2021-10-06 16 | * 17 | */ 18 | -------------------------------------------------------------------------------- /Python/31 - Object oriented programming - Inheritance/.main.py.swp: -------------------------------------------------------------------------------- 1 | b0nano 5.4Fkalikalimain.pyU -------------------------------------------------------------------------------- /C++/28 - New keyword/Basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief New keyword it's used to create a new variable in the currently available area in the heap (literal memory jump) 5 | * from the main stack in memory. It can be useful to address new free memory to a variable in the same stack 6 | * which is handled in LIFO and can cause a slowdown in specific cases. This memory area can be created through a pointer 7 | * where we can access this area in the stack, which is generated at runtime. 8 | * @version 0.1 9 | * @date 2022-02-11 10 | * 11 | * @copyright Copyright (c) 2022 12 | * 13 | */ 14 | #include 15 | using namespace std; 16 | 17 | int main() { 18 | 19 | int *a = new int(); //empty init with (). 20 | int b; 21 | 22 | cin >> *a >> b; 23 | cout << "Data saved in memory area: " << *a << endl 24 | << "Memory address: " << &a << endl 25 | << "Memory address of new area: " << &a << endl 26 | << "Memory address of old area in b: " << &b << endl; 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/42 - std::jthread/42.4 - std::ref/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author std::ref it's basically pass by reference, but instead of making variables as pointers explicitly 4 | * we can use the function defined in the namespace "std" 5 | * @brief 6 | * @version 0.1 7 | * @date 2023-03-23 8 | * 9 | * @copyright Copyright (c) 2023 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | /*making the string "s" a temporary pointer to reference the value. DO NOT make it an actual pointer 17 | because std::ref does not take pointers as arguments, but only normal variables that will be already 18 | converted by it */ 19 | void func(std::string &s) 20 | { 21 | s = "my string that will be referenced"; 22 | } 23 | 24 | int main(void) 25 | { 26 | std::string s = "a string"; 27 | 28 | std::cout << "String before edit by thread: " << s << std::endl; 29 | std::jthread thread1(func, std::ref(s)); 30 | thread1.join(); 31 | 32 | std::cout << "String after edit by thread: " << s << std::endl; 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Java/README.md: -------------------------------------------------------------------------------- 1 | A series of concese examples of the basics on the Java language. 2 | 3 | # How to run the examples 4 | 5 | Make sure Java is installed on your machine. 6 | All examples are built and tested using Java 11 on Debian Bookworm. You can grab it for your operative system from the link or command below. 7 | Windows: https://adoptium.net/temurin/releases/?version=11 8 | Linux: 9 | Debian/Ubuntu/Kali: `sudo apt install openjdk-11-jdk` 10 | Arch/Manjaro: `sudo pacman -S jdk11-openjdk` 11 | Fedora/RedHat: `sudo dnf install java-11-openjdk-devel.x86_64` 12 | 13 | To run the example, open your command prompt or terminal emulator: 14 | On Windows, press Shift + RightClick and select "Open Command Prompt here" (Windows Vista to 8.1), "Open Powershell here" (Windows 10) or "Open Windows Terminal here" (Windows 11). 15 | On all Linux distros it will change based on your enviroment. In the case of Ubuntu Gnome, right click the folder and select "Open in Terminal". 16 | 17 | With your command interpreter open, type `./gradle.bat run` for Windows and `./gradle run` for Linux. 18 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Friend Class/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Debug", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "cwd": "${workspaceFolder}", 11 | "environment": [], 12 | "externalConsole": false, 13 | "linux": { 14 | "MIMode": "gdb", 15 | "miDebuggerPath": "gdb", 16 | "program": "${workspaceFolder}/output/main" 17 | }, 18 | "osx": { 19 | "MIMode": "lldb", 20 | "miDebuggerPath": "lldb-mi", 21 | "program": "${workspaceFolder}/output/main" 22 | }, 23 | "windows": { 24 | "MIMode": "gdb", 25 | "miDebuggerPath": "gdb.exe", 26 | "program": "${workspaceFolder}/output/main.exe" 27 | }, 28 | "preLaunchTask": "build" 29 | } 30 | ] 31 | } -------------------------------------------------------------------------------- /Python/24 - data manipulation - list/example.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is the game plan. Have a switch statement where each statement uses 3 | a built-in function and then explain it 4 | 5 | Here are a list of built-in functions for list 6 | 7 | 8 | .extend() 9 | .index() 10 | .remove() 11 | .pop() 12 | .insert() 13 | .count() 14 | .reverse() 15 | .sort() 16 | .append() 17 | .copy() 18 | .clear() 19 | 20 | len() 21 | min() 22 | max() 23 | 24 | 25 | """ 26 | """ 27 | Explain what a list is 28 | """ 29 | 30 | a = [1,2,3,4,5] 31 | b = ["one","two","three","four","five"] 32 | 33 | def listFunction(x): 34 | 35 | #input a number between 1-11 36 | x = input("Enter a number between 1-11": ) 37 | if x = 1: 38 | 39 | print("This is") 40 | elif x = 2: 41 | print("") 42 | elif x = 3: 43 | print("") 44 | elif x = 4: 45 | print("") 46 | elif x = 5: 47 | print("") 48 | elif x = 6: 49 | print("") 50 | elif x = 7: 51 | print("") 52 | elif x = 8: 53 | print("") 54 | elif x = 9: 55 | print("") 56 | elif x = 10: 57 | print("") 58 | elif x = 11: 59 | print("") 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /C++/02 - Arithmetic/with variables/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // NOTE: To run these programs, open terminal, go into the correct directory 6 | // ex: C++/1 - Usage of Variables and printf/complex print statements with variables 7 | // Run "g++ -o main main.cpp" and then "./main" 8 | 9 | int main() 10 | { 11 | int four = 4; 12 | int two = 2; 13 | 14 | // Addition 15 | cout << "Addition: "; 16 | int addAns = four + two; 17 | cout << addAns << endl; 18 | 19 | // Subtraction 20 | cout << "Subtraction: "; 21 | int subAns = four - two; 22 | cout << subAns << endl; 23 | 24 | // Division 25 | cout << "Division: "; 26 | int divAns = four / two; 27 | cout << divAns << endl; 28 | 29 | // Multiplication 30 | cout << "Multiplication: "; 31 | int multAns = four * two; 32 | cout << multAns << endl; 33 | 34 | // Modulo (remainder) 35 | cout << "Modulo: "; 36 | int modAns = 14 % 3; 37 | // 14 / 3 = 4 remainder 2, so the modulo is 2 38 | cout << modAns << endl; 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Assembly/x86/3 - jmp and cmp/main.asm: -------------------------------------------------------------------------------- 1 | ; here we compare eax value with ebx, and we tell the code to jump if eax is less than ebx 2 | ; cmp instruction modifies the EFLAGS, specifically the Zero Flag ZF, since boolean 3 | ; operations return 1 or 0. 4 | 5 | ; Once the flag is edited by cmp, the jump instruction checks for that flag to perform or not 6 | ; the jump to the memory address. 7 | 8 | ; in this case we are using jl, jump if less than. 9 | 10 | ; Other jump instructions that can be used with different conditions: 11 | 12 | ; JE => Jump if equal 13 | 14 | ; JNE => Jump if not equal 15 | 16 | ; JG => Jump if greater 17 | 18 | ; JGE => Jummp if greater or equal 19 | 20 | ; JL => Jump if less 21 | 22 | ; JLE => jump if less or equal 23 | 24 | section .text 25 | 26 | 27 | global main 28 | 29 | main: 30 | mov ebp, esp; for correct debugging 31 | mov eax, 0xa 32 | mov ebx, 0xb 33 | cmp eax, ebx ; 10 < 11 so jl will jump 34 | jl func ; zero flag is now 0 which means true, 1 is false 35 | 36 | 37 | func: 38 | mov eax, 1 39 | mov ebx, 0 40 | int 0x80 41 | 42 | -------------------------------------------------------------------------------- /C++/08 - Function Return Values/Complex String Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string bobbyShoes() 6 | { 7 | return "Converse"; 8 | } 9 | 10 | string sallyShoes() 11 | { 12 | return "Nike"; 13 | } 14 | 15 | int main() 16 | { 17 | string name; 18 | string favPairOfShoes; 19 | bool correctInput = false; 20 | 21 | while(correctInput == false){ 22 | cout << "Are you Bobby or Sally? (enter either)" << endl; 23 | cin >> name; 24 | 25 | if(name == "Bobby"){ 26 | favPairOfShoes = bobbyShoes(); 27 | correctInput = true; 28 | } 29 | 30 | else if(name == "Sally"){ 31 | favPairOfShoes = sallyShoes(); 32 | correctInput = true; 33 | } 34 | else 35 | cout << "Enter a correct name." << endl; 36 | } 37 | 38 | // Prints "Bobby's favorite shoe brand is Converse." 39 | // OR "Sally's favorite shoe brand is Nike.'" 40 | cout << name << "\'s favorite shoe brand is " << favPairOfShoes << "." << endl; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /C/19 - Union keyword/struct union example/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | A union is a special data type available in C that allows to store different data types in the same 5 | memory location. You can define a union with many members, but only one member can contain a value at any given time. 6 | Unions provide an efficient way of using the same memory location for multiple-purpose */ 7 | 8 | typedef struct str 9 | { 10 | int a; 11 | int b; 12 | //instead of making another struct we can store extra data in the same struct via union.This makes easier to divide data category. 13 | union Data 14 | { 15 | int c; 16 | int d; 17 | } Data; 18 | 19 | } str; 20 | 21 | int main() 22 | { 23 | str struct1; 24 | //direct union access 25 | union Data dat; 26 | dat.c; 27 | 28 | scanf("%d", &struct1.a); 29 | scanf("%d", &struct1.Data.c); 30 | scanf("%d", &struct1.Data.d); 31 | 32 | /*if i insert the value of C, both C and D will have the same value. 33 | when inserting D next, both will have D value*/ 34 | printf("A:%d\nC:%d\nD:%d\n", struct1.a, struct1.Data.c, struct1.Data.d); 35 | return (0); 36 | } -------------------------------------------------------------------------------- /C++/16 - Vectors/IMPORTANT NOTES.txt: -------------------------------------------------------------------------------- 1 | std::vector it's not only for integers, but it's a type that accepts other types as well: 2 | 3 | std::vector a; means that for each char pushed back in the vector there will be automatically a position for it, behaving like 4 | std::string or char[] or char *. 5 | 6 | std::vector will act like char *strings[]; where for each position you can receive a undefined number of chars. 7 | 8 | this behavior is similar to std::array. 9 | 10 | Also can be replicated with integers/doubles ecc: 11 | 12 | std::vector integers; 13 | 14 | 15 | When doing a comparison with indexes and sizes, the size of the vector is returned as a normal integer, 16 | let' say "6", but in fact, those elements are indexed from 0 to 5. 17 | 18 | so if vector.size() = 6: 19 | 20 | for (size_t x = 0; x < vector.size(); ++x) { 21 | 22 | if (x == vector.size()-1) { 23 | std::cout << "x reached end of vector" << std::endl; 24 | } 25 | 26 | we do size-1 because the actual end of the vector is 5 and not 6, because the elements start from 27 | 0 and 5 is the actual sixth element. 28 | -------------------------------------------------------------------------------- /C++/38 - auto and decltype keyword/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief With the auto keyword, the compiler understands what type the variable is judging from its initializer. 5 | * this keyword becomes useful to not write multiple times explicit types that the compiler already knows 6 | * from their values. 7 | * 8 | * The decltype keyword instead lets us retreive the data type from a initialized variable, and can also be used as 9 | * a type assignator to the variables. 10 | * @version 0.1 11 | * @date 2023-02-01 12 | * 13 | * @copyright Copyright (c) 2023 14 | * 15 | */ 16 | #include 17 | 18 | int main(void) 19 | { 20 | //Assignation of a integer will make this var as "int" 21 | auto var = 1; 22 | 23 | //getting var type and giving it to another_var 24 | decltype(var) another_var; 25 | 26 | //typeid returns the type of the auto variable. 27 | std::cout << "Type of data: " << typeid(var).name() << std::endl; 28 | 29 | //The use of auto can be mostly useful for iterators as well: 30 | for (auto i = 0; i < 2; i++) { 31 | /* code */ 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /C++/03 - If else statements/important detail/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // chained if statements vs. if-else block 8 | int num = 16; 9 | 10 | // Chained if statements 11 | // The first 3 will print 12 | cout << "Chained if statements results" << endl; 13 | if(num > 5) 14 | cout << "Greater than 5." << endl; 15 | if (num > 10) 16 | cout << "Greater than 10." << endl; 17 | if (num > 15) 18 | cout << "Greater than 15." << endl; 19 | if (num > 20) 20 | cout << "Greater than 20." << endl; 21 | 22 | // if-else statement block 23 | // Only the first will print 24 | // Once a statement is satisfied within an if-else block, the code leaves the block 25 | cout << "If-else block results" << endl; 26 | if(num > 5) 27 | cout << "Greater than 5." << endl; 28 | else if (num > 10) 29 | cout << "Greater than 10." << endl; 30 | else if (num > 15) 31 | cout << "Greater than 15." << endl; 32 | else if (num > 20) 33 | cout << "Greater than 20." << endl; 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C++/03 - If else statements/simple with user input/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int num = 0; 8 | 9 | cout << "Type a number (any integer) and then press enter: "; 10 | cin >> num; 11 | cout << "You typed the number: " << num << endl; 12 | 13 | // check if negative 14 | if (num < 0) { 15 | cout << "Your number is negative." << endl; 16 | if (num < -100) 17 | cout << "Your number is less than -100." << endl; 18 | else 19 | cout << "Your number is greater than -100." << endl; 20 | 21 | } 22 | // else we know it's positive 23 | else{ 24 | cout << "Your number is positive." << endl; 25 | if (num > 100) 26 | cout << "Your number is greater than 100." << endl; 27 | else 28 | cout << "Your number is less than 100." << endl; 29 | } 30 | 31 | // check if it's even (% is modulo aka remainder) 32 | if (num % 2 == 0) 33 | cout << "Your number is even." << endl; 34 | else 35 | cout << "Your number is odd." << endl; 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/The Diamond Problem/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /*The diamond problem is when two superclasses share the same base class, and the compiler 4 | doesn't understand which class is referring to the base class when using it 5 | in this example Class3 is the derived class and has two bases.*/ 6 | 7 | class class1 8 | { 9 | public: 10 | void print_class1(); 11 | }; 12 | 13 | class class2 : public class1 14 | { 15 | public: 16 | void access_class1(); 17 | }; 18 | 19 | class class3 : public class2, class1 //diamond problem 20 | { 21 | public: 22 | void access_ambiguated(); 23 | }; 24 | 25 | void class1::print_class1() 26 | { 27 | std::cout << "hello class1" << std::endl; 28 | } 29 | 30 | void class2::access_class1() 31 | { 32 | print_class1(); 33 | } 34 | 35 | void class3::access_ambiguated() 36 | { 37 | class1 obj; //in this way the ambiguation it's fixed, but it's better to now extend a class into two classes 38 | //to avoid this problem in the design. 39 | obj.print_class1(); 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | std::cout << "Hello world!" << std::endl; 45 | } -------------------------------------------------------------------------------- /C++/13 - Getline Function/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Showing usage of getline function, similar to a fgets in C, getline obtains 5 | * from input a sequence of characters on a string variable. Plus, we show how to return 6 | * a string from an object. String it's an alternative too an array of char. If the 7 | * element that we have to return in a function it's string type, then the funciton must be 8 | * the same type, neither char, nor other types. 9 | * @version 0.1 10 | * @date 2021-09-28 11 | * 12 | * @copyright Copyright (c) 2021 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | class example { 22 | public: 23 | 24 | void setname(string name) { 25 | getline(cin, name); 26 | cout << name << endl; 27 | } 28 | //function that returns the input as string type. 29 | string getName(string name) { 30 | return name; 31 | } 32 | }; 33 | 34 | 35 | int main() { 36 | 37 | string nameparameter; 38 | 39 | example usage; 40 | usage.getName(nameparameter); 41 | usage.setname(nameparameter); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Java/03 - Mathematical operations/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Java application project to get you started. 5 | * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle 6 | * User Manual available at https://docs.gradle.org/7.4.2/userguide/building_java_projects.html 7 | */ 8 | 9 | plugins { 10 | // Apply the application plugin to add support for building a CLI application in Java. 11 | id 'application' 12 | } 13 | 14 | repositories { 15 | // Use Maven Central for resolving dependencies. 16 | mavenCentral() 17 | } 18 | 19 | dependencies { 20 | // Use JUnit Jupiter for testing. 21 | testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' 22 | 23 | // This dependency is used by the application. 24 | implementation 'com.google.guava:guava:30.1.1-jre' 25 | } 26 | 27 | application { 28 | // Define the main class for the application. 29 | mainClass = 'example3.app.App' 30 | } 31 | 32 | tasks.named('test') { 33 | // Use JUnit Platform for unit tests. 34 | useJUnitPlatform() 35 | } 36 | -------------------------------------------------------------------------------- /C++/17 - Exceptions/Exception Handler with classes/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Another exception example. 5 | * @version 0.1 6 | * @date 2021-10-17 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | class test { 18 | private: 19 | int x; 20 | int y; 21 | bool flag = false; 22 | 23 | public: 24 | 25 | void input() { 26 | cin >> x; 27 | } 28 | 29 | bool exception() { 30 | if (x == 10) { 31 | try { 32 | throw x; 33 | this->flag = true; 34 | } 35 | catch(int catchering) { //NOTE: exception catcher MUST be declared here. 36 | cout << "Exception Occurred on Value " << catchering << endl; 37 | } 38 | 39 | } 40 | return flag; 41 | } 42 | 43 | void print() { 44 | cout << "Exception returned true!" << endl; 45 | } 46 | 47 | }; 48 | 49 | 50 | int main() { 51 | 52 | test tester; 53 | 54 | tester.input(); 55 | tester.exception(); 56 | //if the flag is true, print the exception. 57 | if(tester.flag) { 58 | tester.print(); 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Assembly/x86/2 - EIP Instruction Pointer and jmp instruction/main.asm: -------------------------------------------------------------------------------- 1 | ; EIP in x86 is the Instruction Pointer, which points to the next instruction in memory to 2 | ; be executed. normally in GDB when you hit a breakpoint, you can see the instruction 3 | ; pointed by the EIP with a -> or => near the memory address. 4 | 5 | ; when jmp is used, the ESP register which contains the pointer of the base stack address 6 | ; to reach, gets updated with the new address of the stack frame of "func" 7 | ; the FP frame pointer saves the previous address of ESP so that the register knows 8 | ; where the program jumped from in case it needs to go back. 9 | 10 | section .text 11 | 12 | 13 | global main 14 | 15 | main: 16 | mov ebp, esp; for correct debugging 17 | mov ebx, 42 ; exit status 42 will be returned if jmp works 18 | mov eax, 1 19 | jmp func ; jump to func function, alters the EIP 20 | mov ebx, 13 ; if not successfull status will be 13 21 | 22 | func: 23 | 24 | int 0x80 25 | 26 | 27 | ; NOTES: we can analyze the EIP when we reach the jmp instruction and we can see 28 | ; that it points to the address of int 0x80 inside func. 29 | -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/<< and >> shift operands/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief -Left shift operand "<<" applies an operation of power on the used variable, alongside a multiplication. 5 | * a << b is equivalent of a * 2^b, where 2 is the base applied on b, and it's elevated by 6 | * b itself, moving the binary digits of the numbers. 7 | * 8 | * -Right shift operand ">>", same operation as above, but instead it uses a division. 9 | * 10 | * Limit cases: 11 | * 12 | * -Negative numbers lead to a undefined behavior 13 | * -Shift that goes above the type limit leads to a undefined behavior: 14 | * example int16_t is 65535 max, if the shift is above the number it will not 15 | * display the correct values. 16 | * 17 | * 18 | * @version 0.1 19 | * @date 2023-03-21 20 | * 21 | * @copyright Copyright (c) 2023 22 | * 23 | */ 24 | 25 | #include 26 | 27 | int main(void) 28 | { 29 | int a = 5, b = 5; 30 | 31 | printf("Left shift result: %d\nRight Shift Result: %d\n", (a << b), (a >> b)); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C++/29 - Class constructor/basic example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /*A constructor it's a integrated function class. Can also have a type if you want to return something with it. It gets initialized and executed 5 | before every other instruction unless it's made static. Useful to initialize data before working on it with other functions.*/ 6 | 7 | class first { 8 | private: 9 | int a, b; 10 | public: 11 | 12 | first() { 13 | 14 | a = 5, b = 7; 15 | 16 | cout << "Printing with constructor\n"; 17 | cout << "Operation result is: \n" << a+b; 18 | } 19 | ~first(); /*destructor, in this case it does nothing, but if we want we can NULL the values of a and b. A destructor frees the data captured 20 | **we select from the constructor*/ 21 | }; 22 | 23 | //Alternative constructor initialization, implicitly void. It's always better to write it separately from the class unlike above, to make the code more 24 | //readable. 25 | 26 | first::first() 27 | { 28 | //code 29 | } 30 | 31 | 32 | int main() { 33 | 34 | first(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /C++/16 - Vectors/4 - Input, sort, remove duplicate, output/src/class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | 5 | vett vectors::vector1; 6 | 7 | void vectors::input() { 8 | 9 | int a = 0; 10 | //i < size+1 always true so we can stop him manually. 11 | for (size_t i = 0; i < vector1.size()+1; i++){ 12 | //if a != 33 insert a inside the vector, or else exit from the cicle. 13 | if (a != 33) { 14 | cin >> a; 15 | vector1.push_back(a); 16 | } else { 17 | i = vector1.size()+1; 18 | } 19 | } 20 | } 21 | 22 | void vectors::sort() { 23 | 24 | int temp; 25 | 26 | for (size_t i = 0; i < vector1.size(); i++){ 27 | for (size_t j = i+1; j < vector1.size(); j++) { 28 | if (vector1[i] > vector1[j]){ 29 | temp = vector1[i]; 30 | vector1[i] = vector1[j]; 31 | vector1[j] = temp; 32 | } 33 | } 34 | } 35 | } 36 | void vectors::remove_duplicated() { 37 | 38 | for (size_t i = 0; i < vector1.size(); i++){ 39 | if (vector1[i] == vector1[i+1]) { 40 | vector1.erase(vector1.begin() + i); 41 | } 42 | } 43 | } 44 | 45 | void vectors::output() { 46 | for (size_t i = 0; i < vector1.size(); i++){ 47 | cout << " " << vector1[i]; 48 | } 49 | } -------------------------------------------------------------------------------- /Golang/16 - User Input/main.go: -------------------------------------------------------------------------------- 1 | /* Initialize a buffer that reads the input, then call that reader buffer to get what you need. Similar to Java. 2 | THe buffer can be initialized in specific buffers where to listen for data. IN this case is stdin. 3 | 4 | NOTE: this is needed only for strings, for numbers you can just do: 5 | 6 | var num int/float64/float32 7 | 8 | fmt.Scan(num). 9 | 10 | if argument is already pointer no need to put & 11 | 12 | if a pointer is empty you must initialize with the * symbol, like showed below with str. 13 | 14 | Docs: https://pkg.go.dev/fmt#hdr-Printing 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "bufio" 21 | "fmt" 22 | "os" 23 | "strings" 24 | ) 25 | 26 | func getInput(number *int) { 27 | fmt.Scan(number) 28 | } 29 | 30 | func getString(str *string) { 31 | reader := bufio.NewReader(os.Stdin) 32 | //first var is the string, second var is the returned error by function 33 | *str, _ = reader.ReadString('\n') 34 | } 35 | 36 | func main() { 37 | 38 | var num int 39 | mystring := "" 40 | fmt.Println("insert number") 41 | getInput(&num) 42 | fmt.Println(num) 43 | 44 | getString(&mystring) 45 | fmt.Println(strings.TrimSpace(mystring)) 46 | } 47 | -------------------------------------------------------------------------------- /C++/30 - Extern keyword/Hybrid C-C++ linkage and scoping effect/include/header.hh: -------------------------------------------------------------------------------- 1 | #ifndef F1E01628_B975_412F_AB52_65E96CBA321E 2 | #define F1E01628_B975_412F_AB52_65E96CBA321E 3 | 4 | /* 5 | **extern makes scope of this function global to all the files that include the header where it's declared and tells the compiler this 6 | function is declared somewhere. 7 | 8 | In short words: 9 | 10 | -declare a function as extern in a header. 11 | -define the extern function in a source, without the extern keyword already, and including the header. 12 | -That definition now becomes available for all the source files that include the header. 13 | */ 14 | extern void print(); 15 | 16 | /*A macro that allows us to create functions that will be compiled with C symbols in .c files 17 | (or functions in .c files that will be called in .cpp files, NOT viceversa. for that you need another macro.), to allow hybrid code by 18 | enabling the linkage between .c and .cpp files. 19 | 20 | here is an example of __cplusplus macro usage, this function goes in file.c and will be called in main.cpp*/ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | void function(); 25 | } 26 | #endif 27 | #endif /* F1E01628_B975_412F_AB52_65E96CBA321E */ 28 | -------------------------------------------------------------------------------- /Java/01 - Hello world/app/src/main/java/app/App.java: -------------------------------------------------------------------------------- 1 | package app; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.io.BufferedReader; 5 | 6 | /* 7 | * This Java source file was generated by the Gradle 'init' task. 8 | 9 | /*class name must have file name. Java functions must be putted under a class. for each function we have to specify if it's public or private 10 | static because members that need to access other class members require static type, like C++ (tho that's limited from class to class, not in 11 | the same class).*/ 12 | public class App { 13 | 14 | String scanfString (String msg) throws IOException { 15 | String strInput; 16 | 17 | InputStreamReader in = new InputStreamReader(System.in); 18 | BufferedReader inputTastiera = new BufferedReader(in); 19 | strInput = inputTastiera.readLine(); 20 | System.out.println(msg); 21 | return strInput; 22 | } 23 | 24 | public static void main(String[] args) { 25 | string strinput; 26 | App object = new App(); 27 | try { 28 | object.scanfString(strinput); 29 | } catch (Exception e) { 30 | 31 | } 32 | } 33 | } 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Assembly/x86/5 - editing strings/main.asm: -------------------------------------------------------------------------------- 1 | ; we can edit a string by using mov instruction. 2 | ; we call string with [] which means call it as a pointer 3 | ; then we define on the same line a byte "H" which is the char to put inside. 4 | ; if we type [string] only we point to index 0 of the string 5 | ; if we type [string+0x1] we edit the second char, and so on 6 | 7 | ; Remember: the index starts from 0. my string is 4 chars so 0-3 is the memory range. 8 | ; each byte of char is represented by 2 hex characters, 4 bits each. 9 | 10 | ; so Fabx in memory: 0x46 64 62 78 11 | ; F A B X 12 | 13 | ; [string+0x3] points to x 78, and we replace it with H 48 14 | 15 | ; NOTE: on gdb if you debug the mov instruction where [string+0x3] is 16 | ; you will get only the value pointed at 0x3, not the entire string 17 | 18 | ; you can obtain the full string once it's inside the register ECX 19 | 20 | section .data 21 | string db "Fabx" 22 | lenght equ $ - string 23 | 24 | 25 | section .text 26 | 27 | global main 28 | 29 | main: 30 | mov ebp, esp; for correct debugging 31 | mov [string+0x3], byte 'H' 32 | mov eax, 4 33 | mov ebx, 1 34 | mov ecx, string 35 | mov edx, lenght 36 | int 0x80 -------------------------------------------------------------------------------- /Golang/11 - Pass By Value/main.go: -------------------------------------------------------------------------------- 1 | /* Pass by value makes copies of variables and stores them into other variables, unlike pointers where you reference the same memory address instead 2 | of copying. If we want to update the referenced variable, we have to return with the function that we are using, then assign the returned value. 3 | 4 | NOTE: it is better to use pointers to reference values unless we stricly need copies of values. */ 5 | 6 | package main 7 | 8 | import "fmt" 9 | 10 | func changeString(x string) string { 11 | x = "mystring" 12 | return x 13 | } 14 | 15 | /* 16 | in cases of maps, slices and functions we add values in this way, adding memory blocks. 17 | 18 | in all other cases (arrays, structs, vars ecc) it makes a copy, leaving the defined one in main unchanged 19 | */ 20 | func changeMap(y map[int]string) { 21 | y[1] = "Another" 22 | } 23 | 24 | func main() { 25 | 26 | var strings = "second" 27 | // we are updating x, not "strings", making a copy in x 28 | changeString(strings) 29 | fmt.Println(strings) 30 | 31 | strings = changeString(strings) 32 | fmt.Println(strings) 33 | 34 | mymap := map[int]string{ 35 | 0: "first", 36 | } 37 | 38 | changeMap(mymap) 39 | 40 | fmt.Println(mymap) 41 | } 42 | -------------------------------------------------------------------------------- /C++/39 - Bitwise operands/<< and >> shift operands/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief -Left shift operand "<<" applies an operation of power on the used variable, alongside a multiplication. 5 | * in the example below, a << b is equivalent of 5 * 2^5, where 2 is the base applied on b, and it's elevated by 6 | * b itself, moving the binary digits of the numbers. 7 | * 8 | * -Right shift operand ">>", same operation as above, but instead it's divided. 9 | * 10 | * Limit cases: 11 | * 12 | * -Negative numbers lead to a undefined behavior 13 | * -Shift that goes above the type limit leads to a undefined behavior: 14 | * example int16_t is 65535 max, if the shift is above the number it will not 15 | * display the correct values. 16 | * 17 | * 18 | * @version 0.1 19 | * @date 2023-03-21 20 | * 21 | * @copyright Copyright (c) 2023 22 | * 23 | */ 24 | 25 | #include 26 | 27 | int main(void) 28 | { 29 | int a = 5, b = 5; 30 | 31 | std::cout << "Left Shifted result: " << (a << b) << std::endl; 32 | std::cout << "Right Shifted result: " << (a >> b) << std::endl; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++/17 - Exceptions/Basic exception throw/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief Exceptions provide a way to react to exceptional circumstances (like runtime errors) 5 | * in programs by transferring control to special functions called handlers. 6 | 7 | To catch exceptions, a portion of code is placed under exception inspection. 8 | This is done by enclosing that portion of code in a try-block. When an exceptional circumstance arises within that block, an exception is thrown that transfers the control to the exception handler. If no exception is thrown, the code continues normally and all handlers are ignored. 9 | An exception is thrown by using the throw keyword from inside the try block. 10 | Exception handlers are declared with the keyword catch, which must be placed immediately after 11 | the try block: 12 | * @version 0.1 13 | * @date 2021-10-15 14 | * 15 | * @copyright Copyright (c) 2021 16 | * 17 | */ 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | int main () { 24 | try 25 | { 26 | throw 20; 27 | throw "Error"; 28 | } 29 | catch (int e) { 30 | cout << "An exception occurred. Exception Nr. " << e << '\n'; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /C/09 - Enums/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Enums act as integers, but instead of using explicit numbers, we can give names to those numbers. 3 | This can make things more clear in the code to understand the logic of a specific number that is 4 | expected, instead of trying to figure out why a condition has to be less than X. 5 | 6 | Enums start from 0, we can also assign custom values to a enum. 7 | 8 | A common practice is to write enums in uppercase, to indicate that those are actually enums being used and not some other 9 | variable. 10 | 11 | */ 12 | 13 | enum { 14 | ZERO, 15 | ONE, 16 | TWO, 17 | MYNUMBER = 24 18 | }; 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | int main(void) 25 | { 26 | char a[10]; 27 | int num; 28 | 29 | fgets(a, sizeof(a), stdin); 30 | a[strcspn(a, "\n")] = 0; 31 | num = atoi(a); 32 | 33 | if (num == ZERO) { 34 | printf("num has value: %d\n", num); 35 | } else if (num == ONE) { 36 | printf("num has value: %d\n", num); 37 | } else if (num == TWO) { 38 | printf("num has value: %d\n", num); 39 | } else { 40 | printf("num has value: %d\n", num); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Accessing private member/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief This program shows how can we access private members in a class. 5 | 6 | NOTE: for private functions use the constructor (or other public functions) 7 | to access them once defined. 8 | * @version 0.1 9 | * @date 2021-10-11 10 | * 11 | * @copyright Copyright (c) 2021 12 | * 13 | */ 14 | 15 | #include 16 | using namespace std; 17 | 18 | class myclass { 19 | private: 20 | int a = 0, b = 0; //private members, we cannot access them directly 21 | 22 | public: 23 | 24 | void print() { 25 | cout << a << " \n" << b << " \n"; 26 | } 27 | void function() { //our public object, which can access private members. 28 | a = 15, b = 16; 29 | 30 | cout << " \n" << a << " \n" << b; 31 | } 32 | 33 | 34 | 35 | }; 36 | int main() { 37 | 38 | myclass access; 39 | cout << "before: \n"; 40 | access.print(); 41 | //access.a = 15; Uncomment and you'll see you can't access to it. Only a class member can access private objects. 42 | cout << "After: \n"; 43 | access.function(); 44 | return 0; 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /C++/16 - Vectors/Built-in Delete function/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_Y 4 | * @brief Showing how to empty a vector with clear function. 5 | * @version 0.1 6 | * @date 2021-10-26 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | vector v; 19 | 20 | int a; 21 | for ( size_t i = 0; i < 4; i++ ){ 22 | cin >> a; 23 | v.push_back(a); 24 | } 25 | 26 | cout << "Numbers before: "; 27 | for ( int e : v ) { //scanning vector with e integer. 28 | cout << e << ' '; 29 | } 30 | 31 | v.clear(); //clears ALL the vector. 32 | v.erase(v.begin() + position); //pos 0 + pos given to delete a specific element. 33 | // erase the first 3 elements, start from 0 finish to 3: 34 | v.erase (v.begin(), v.begin()+3); 35 | 36 | 37 | 38 | cout << "... Numbers After: "; 39 | for ( int e : v ) { 40 | cout << e << ' '; 41 | } 42 | 43 | //alternative reading, on the terminal nothing won't appear because the vector size is 0. 44 | for (size_t i = 0; i < v.size(); i++){ 45 | cout << "Numbers after with v.size() " << v[i] << endl; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /C++/24 - random.h - randomizer for C++/basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief Showing usage of random library to generate random numbers 5 | * with c++11 random library instead of rand(); The mersenne twister algorithm uses 6 | * positive integers prime numbers as a power for the numbers given, for more information see: 7 | * https://en.wikipedia.org/wiki/Mersenne_Twister 8 | * @version 0.1 9 | * @date 2021-12-12 10 | * 11 | * @copyright Copyright (c) 2021 12 | * 13 | */ 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | int main() { 19 | //seed init to randomize 20 | random_device nameofseed; 21 | //mersenne twister algorithm init, name of algorithm + twister function with parameter seed. 22 | mt19937 mt(nameofseed()); 23 | /*Calling class template to specify data type to operate with and the range of numbers 24 | NOTE: dbl_min and dbl_max can be changed with explicit numbers too. They just indicate the range.*/ 25 | uniform_real_distribution dist(__DBL_MIN__, __DBL_MAX__); 26 | for (size_t i = 0; i < 10; i++){ 27 | //printing mersenn twister output with the distance we gave. 28 | cout << "" << dist(mt) << endl; 29 | } 30 | return 0; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Golang/08 - Functions/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func print(a int) { 8 | fmt.Println("Hello from function with number:", a) 9 | } 10 | 11 | func printarg(mystring string, names []string) { 12 | fmt.Println("Printing string content:", mystring) 13 | fmt.Println("Printing filled names:", names) 14 | 15 | } 16 | 17 | /* reference function from another function. f is a function that takes int as an argument. 18 | for every number in the array, we call the function that we pass in main 19 | So this will pass to a our array of ints*/ 20 | 21 | func reference(numbers []int, f func(int)) { 22 | for _, value := range numbers { 23 | f(value) 24 | } 25 | } 26 | 27 | // function returning a type must have the type written outside the argument section 28 | func returningfunc(a int) int { 29 | return a 30 | } 31 | 32 | // multiple value return 33 | func doubleret() (string, int) { 34 | 35 | return "hello", 1 36 | } 37 | 38 | func main() { 39 | 40 | newstring := "Fabxx" 41 | mynames := []string{"Fabxx", "SSUPII", "Haskell"} 42 | 43 | print(4) 44 | printarg(newstring, mynames) 45 | reference([]int{1, 2, 3}, print) 46 | fmt.Println(returningfunc(5)) 47 | 48 | value := returningfunc(5) 49 | fmt.Println(value) 50 | fmt.Println(doubleret()) 51 | } 52 | -------------------------------------------------------------------------------- /C++/21 - Template example/template on vector example/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //just a function to clear terminal, ignore this. 6 | #if defined (__linux__) 7 | inline void clear_terminal(void) 8 | { 9 | system("clear"); 10 | } 11 | #endif 12 | #if defined (_WIN32) 13 | inline void clear_terminal(void) 14 | { 15 | system("cls"); 16 | } 17 | #endif 18 | 19 | 20 | template 21 | 22 | class A 23 | { 24 | public: 25 | std::vector vec; 26 | std::string mystring; 27 | }; 28 | 29 | int main(void) 30 | { 31 | A obj; 32 | 33 | for (size_t i = 0; i < 4; ++i) { 34 | getline(std::cin, obj.mystring); 35 | obj.vec.push_back(obj.mystring); 36 | } 37 | 38 | clear_terminal(); 39 | 40 | //print the strings of vector 41 | for (size_t i = 0; i < obj.vec.size(); ++i){ 42 | std::cout << obj.vec[i] << std::endl; 43 | } 44 | 45 | //we can also change the type of the vector data in the code after that 46 | obj.vec.erase(obj.vec.begin(), obj.vec.end()); 47 | A obj2; 48 | 49 | for (size_t i = 0; i < 2; ++i) { 50 | obj2.vec.push_back(i); 51 | } 52 | 53 | clear_terminal(); 54 | 55 | for (size_t i = 0; i < obj2.vec.size(); ++i) { 56 | std::cout << obj2.vec[i] << std::endl; 57 | } 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /C/18 - Bitwise Operands/README.md: -------------------------------------------------------------------------------- 1 | # Use cases 2 | 3 | -`&` it's used to test and clear bits 4 | 5 | -`|` it's used to set bits. 6 | 7 | -Clearing bits means setting them to `0` 8 | 9 | In embedded programming these operators are useful to switch pin states 10 | 11 | # Parity check 12 | 13 | -Use a bitmak of 1 (odd) or 0 (even) 14 | 15 | If you want to switch/test specific bit positions then you first need to know which binary sequence you need 16 | 17 | that will produce the result you want. Then use the corresponding number in hex/dec 18 | 19 | can be 1 (to check if it's odd) or 0 (to check if it's even). 20 | 21 | example: 22 | 23 | if ((num & 1) == 1) { 24 | 25 | print("odd"); 26 | 27 | } 28 | 29 | This checks the least significant bit `LSB` of a given binary sequence, and tests the bit with the mask to determine 30 | the parity of the number. 31 | 32 | # Alternative for parity check 33 | Using the module operation with `n%2==0` comparison. 34 | 35 | 36 | # Bit setting and clearing (method 1) 37 | 38 | I want to clear the 6th bit of 8 and set the 7th bit. 39 | 40 | binary sequence: `00001000` 41 | 42 | bit mask: `000001000` 43 | 44 | operation: 45 | 46 | 00001000 & 47 | 48 | 00000100 = 49 | 50 | 00000000 | the 6th bit has been cleared. 51 | 52 | 00000100 = 53 | 54 | 00000100 the 7th bit has been set. 55 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Virtual class extension/Basic Example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /*Virtual tells the compiler to create a jump table so that it can 5 | call subclass functions through superclass pointers at runtime. 6 | THis keyword can be useful if you have too many classes and don't want to create 7 | a new object for each of them. You can use one superclass with dummy functions 8 | and override them via subclasses from one object.*/ 9 | 10 | class Car // Base class (Superclass) 11 | { 12 | public: 13 | virtual void Create() // virtual function, if you remove virtual key, the print will not change. 14 | { 15 | cout << "Parent class: Car\n"; 16 | } 17 | }; 18 | 19 | class Sedan: public Car { //derived class (subclass) where we override Create of Car with Create of Sedan 20 | public: 21 | void Create() { 22 | cout << "Derived class: Sedan - Overridden C++ virtual function"; 23 | } 24 | }; 25 | 26 | int main() { 27 | 28 | Car x, *y; 29 | x.Create(); 30 | //overriding the Superclass function with the Subclass function 31 | y = new Sedan(); 32 | y->Create(); 33 | 34 | //virtual with the same class object is the equivalent of this: 35 | /* 36 | Sedan *y = new Sedan(); //pointer object must be init with a Class memory. 37 | y->Create(); 38 | */ 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++/25 - std::map/Search, Delete hash/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief Showing how to search and delete an element in dictionary. 5 | * @version 0.1 6 | * @date 2021-12-16 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | map hash_table; 18 | map::iterator index; 19 | 20 | for (size_t i = 0; i < 5; i++){ 21 | hash_table.insert(pair(i+1, i)); 22 | } 23 | 24 | for (index = hash_table.begin(); index != hash_table.end(); index++){ 25 | cout << " " << index->first //first int pointer 26 | << " " << index->second << endl; //second int pointer. 27 | } 28 | 29 | //direct deletition 30 | //hash_table.erase(2) 31 | 32 | for (index = hash_table.begin(); index != hash_table.end();){ 33 | if (index->first == 2){ 34 | cout << "Key 2 found, removing..." << endl; 35 | index = hash_table.erase(index); //map::erase() returns the next iterator, so assign that to your index variable. 36 | } else { 37 | index++; 38 | } 39 | } 40 | cout << "New table" << endl; 41 | for (index = hash_table.begin(); index != hash_table.end(); index++){ 42 | cout << " " << index->first 43 | << " " << index->second << endl; 44 | } 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /C++/32 - Namespace /Basic Example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabx 4 | * @brief A namespace it's useful to distinguish functions that might have the same name, and avoids conflicts. 5 | NOTE: a namespace it's useful to create API functions and helper functions that do not belong 6 | to a class. 7 | * @version 0.1 8 | * @date 2022-07-23 9 | * 10 | * @copyright Copyright (c) 2022 11 | * 12 | */ 13 | 14 | #include 15 | 16 | // NOTE: you can also put in variables, structures, classes ecc 17 | namespace Fabx 18 | { 19 | void fabcalc(); 20 | 21 | // Can also Wrap C structures into C++ namespace. note that to wrap Structure functions you need to write or implement an existing wrapper. 22 | 23 | struct a 24 | { 25 | int a; 26 | }; 27 | } 28 | 29 | void Fabx::fabcalc() 30 | { 31 | std::cout << 1+1 << std::endl; 32 | } 33 | 34 | //then if we don't want to write the namespace every single time, we use the "using" keyword. 35 | 36 | using namespace Fabx; 37 | 38 | //we can also make namespaces inside other mainspaces, call other made functions inside, and so on. 39 | 40 | namespace 1 41 | { 42 | void a(); 43 | namespace 2 44 | { 45 | void b(); 46 | }; 47 | }; 48 | 49 | int main() 50 | { 51 | Fabx::fabcalc(); 52 | /*call without namespace 53 | fabcalc(); 54 | */ 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Golang/15 - Receiver Functions with Pointers/main.go: -------------------------------------------------------------------------------- 1 | /* Pointers are useful to not make excessive copies of objects in memory, in Go the pointer is automatically 2 | dereferenced for us, so we don't have to write something like (*structure).a = something or similar. 3 | 4 | Then to call a function that is associated with a struct pointer, you need the following syntax: 5 | 6 | (&struct{}).function() 7 | 8 | This is needed because we have to remove ambiguity for the compiler to make what we are calling addressable, by default 9 | directly calling a receiver function that has a pointer is not addressable for the compiler. 10 | 11 | However, this still doesn't pass the struct values to the main function and makes a copy, so when we call it in this way, 12 | a will be 0. We need to make a variable that is initialized to the struct pointer, and then call the functions so we can 13 | reference the address of the structure and will not make copies. 14 | 15 | */ 16 | 17 | package main 18 | 19 | import "fmt" 20 | 21 | type mystruct struct { 22 | a int 23 | } 24 | 25 | func (structure *mystruct) values() { 26 | structure.a = 10 27 | } 28 | 29 | func (structure *mystruct) returned() int { 30 | return structure.a 31 | } 32 | 33 | func main() { 34 | test := &mystruct{} 35 | test.values() 36 | fmt.Println(test.returned()) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /C++/42 - std::jthread/42.3 - std::move/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author std::move is a function that allows you to move the data of a parameter inside the child thread 4 | * process, without sharing memory between the threads. 5 | * 6 | * In this case "mystring" is the argument that will pass the data to "string" in main(), but then 7 | * that data is moved outside the main thread and goes inside func() which is handled by "mythread" 8 | * 9 | * 10 | * we CANNOT assign a thread to the other, but we can move the ownership of it. 11 | * @brief 12 | * @version 0.1 13 | * @date 2023-03-23 14 | * 15 | * @copyright Copyright (c) 2023 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | void func(std::string mystring) 23 | { 24 | mystring = "a"; 25 | std::cout << mystring << std::endl; 26 | } 27 | 28 | void nullfunc() 29 | { 30 | 31 | } 32 | 33 | int main(void) 34 | { 35 | std::string string; 36 | std::jthread mythread(func, std::move(string)); 37 | 38 | mythread.join(); 39 | 40 | //will be empty since data is moved inside the thread. 41 | std::cout << string << std::endl; 42 | 43 | //moving thread ownership, where thread2 takes the function of thread1: 44 | std::jthread thread1(nullfunc); 45 | std::jthread thread2 = std::move(thread1); 46 | } -------------------------------------------------------------------------------- /Golang/12 - Pointers/main.go: -------------------------------------------------------------------------------- 1 | /* Pointers point to a memory address, which then contains a value. THese can be used to pass arguments as references to update vars and so on, without 2 | making a copy in memory. We can change the memory address of a var so that it will contain the value we want from an argument. 3 | 4 | If a var is declared as a pointer, you don't need the & symbol, because you are already calling it's memory address, 5 | and if you need to see its value you just call it with the * symbol. 6 | 7 | If a var is declared normally wihtout being a pointer, you need to add the & symbol to view the memory address, if you give nothing, 8 | you will already seek the actual value of the variable. 9 | */ 10 | 11 | package main 12 | 13 | import "fmt" 14 | 15 | func variable(x *int) { 16 | *x = 10 17 | } 18 | 19 | func main() { 20 | x := 5 21 | //stores the address of x, where 10 is stored. a is implicitly a *int 22 | a := &x 23 | fmt.Println("Memory address of x: ", &x) 24 | fmt.Println("Address of a: ", a) 25 | 26 | /*dereferencing pointer to access actual value stored in a. 27 | to print a pointer with its value you have to use the * symbol */ 28 | fmt.Println("Value of a: ", *a) 29 | 30 | // updating memory address of x by reference 31 | fmt.Println("value of x: ", x) 32 | variable(&x) 33 | fmt.Println("Value of x after update:", x) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /C/03 - Loops/src/main.c: -------------------------------------------------------------------------------- 1 | /*Three types of loops: 2 | 3 | for 4 | while 5 | do-while 6 | 7 | THey all repeat instructions based on specific conditions. 8 | 9 | We can use two keywords in loops: 10 | 11 | continue: skips the current loop and goes into the next one until condition is met. 12 | 13 | break: breaks the loop when a specific condition is reached 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | int main(void) 21 | { 22 | int val = 0, val2 = 0; 23 | 24 | for (size_t i = 0; i < 5; i++) { 25 | if (i < 4) { 26 | continue; 27 | } 28 | printf("Printing Directly number: %ld\n", i); 29 | } 30 | 31 | 32 | while (val < 5) { 33 | if (val == 4) { 34 | break; 35 | } 36 | printf("Printing value: %d\n", val); 37 | val++; 38 | } 39 | 40 | do { 41 | printf("0x%d\n", val2); 42 | val2++; 43 | } while (val2 < 10); 44 | 45 | 46 | // Input loop, can store 1 number in each position. 47 | 48 | int numbers[4][1] = {}; 49 | 50 | // i < 3 because memory starts from 0. So we have 0, 1, 2 positions for numbers. So index must be SIZE OF ARRAY-1 51 | 52 | for (size_t i = 0; i < 3; i++){ 53 | scanf("%d", &numbers[i][i]); 54 | printf("%d\n", numbers[i][i]); 55 | } 56 | 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /C++/33 - Delete keyword/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief This keyword it's used to delete a pointer, specifically, it deletes values inside the heap created with new keyword. 5 | * can also be used to delete arrays and any types of pointers. Does not destroy pointer to object, but value or memory block 6 | * pointed by the pointer is destroyed. 7 | * @version 0.1 8 | * @date 2023-01-31 9 | * 10 | * @copyright Copyright (c) 2023 11 | * 12 | */ 13 | 14 | #include 15 | 16 | static void func(int *ptr) 17 | { 18 | delete(ptr); 19 | }; 20 | 21 | int main() 22 | { 23 | 24 | int *ptr = new int(20); 25 | int *arr = new int[10]; 26 | 27 | std::cout << "Pointer before delete: " << *ptr << std::endl; 28 | delete ptr; 29 | //gives random garbage value due to deletion. 30 | std::cout << "Pointer deleted: " << *ptr << std::endl; 31 | 32 | for (size_t i = 0; i < 10; i++) { 33 | std::cin >> arr[i]; 34 | std::cout << arr[i] << std::endl; 35 | } 36 | 37 | delete[] arr; 38 | 39 | #if defined (__linux__) 40 | system("clear"); 41 | #elif defined (_WIN32) 42 | system("cls"); 43 | #endif 44 | 45 | //same for array. 46 | std::cout << "Array after deletion:" << std::endl; 47 | for (size_t i = 0; i < 10; ++i){ 48 | std::cout << arr[i] << std::endl; 49 | } 50 | 51 | //deleting argument pointer 52 | int *ptr2 = new int(25); 53 | func(ptr2); 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/stati cast - char to int/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief Showing functions of static_cast<>(), const_cast, and more. 5 | * 6 | * static_cast` is used for cases where you basically want to reverse an implicit conversion, 7 | * with a few restrictions and additions. `static_cast` performs no runtime checks. 8 | * This should be used if you know that you refer to an object of a specific type, 9 | * and thus a check would be unnecessary. NOTE: casting to char takes ASCII table as reference. 10 | * 11 | dynamic_cast only works for pointers or references to polymorphic class types; 12 | const_cast can't change types, only const or volatile qualifiers; 13 | reinterpret_cast is for special circumstances, converting between pointers or references and completely unrelated types. 14 | Specifically, it won't do numeric conversions. 15 | C-style and function-style casts do whatever combination of static_cast, const_cast and reinterpret_cast is needed to get the job done. 16 | 17 | * @version 0.1 18 | * @date 2021-10-06 19 | * 20 | * @copyright Copyright (c) 2021 21 | * 22 | */ 23 | 24 | #include 25 | using namespace std; 26 | 27 | int main() { 28 | 29 | char x; 30 | cout << "Insert a string" << endl; 31 | cin >> x; 32 | cout << "Correspondent numbers: " << static_cast(x) << endl; 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Simple calss with and without pointer/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_y 4 | * @brief A simple program that shows Object oriented programming. 5 | * a class it's a function container defined as a object. An 6 | * object is something that we use in a certain situation as 7 | * a component to complete our task, this is the logic of the 8 | * classes in C++. It helps us to divide the functions as separate 9 | * objects that we can use anytime for a specific situation, 10 | * which don't need to follow a structured programming method. 11 | * 12 | * @version 0.1 13 | * @date 2021-09-27 14 | * 15 | * @copyright Copyright (c) 2021 16 | * 17 | */ 18 | 19 | #include 20 | 21 | using namespace std; 22 | 23 | class printer { //Object name for the class 24 | 25 | public: //indicates that the functions listed belowe are accessible to every other function. 26 | void printin_class() { //function contained in a class 27 | 28 | cout << "Hello class" << endl; 29 | } 30 | 31 | void printin_class_ptr() { 32 | cout << "Hello pointer calss" << endl; 33 | } 34 | }; //end of class. 35 | 36 | int main() { 37 | 38 | printer myprinter; //pointer to our class, similar to a typedef struct. 39 | myprinter.printin_class(); 40 | 41 | printer *myprinterptr = NULL; //example with pointer. 42 | myprinterptr->printin_class_ptr(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/static cast - int to char/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief Showing functions of static_cast<>(), const_cast, and more. 5 | * 6 | * static_cast` is used for cases where you basically want to reverse an implicit conversion, 7 | * with a few restrictions and additions. `static_cast` performs no runtime checks. 8 | * This should be used if you know that you refer to an object of a specific type, 9 | * and thus a check would be unnecessary. NOTE: casting to char takes ASCII table as reference. 10 | * 11 | dynamic_cast only works for pointers or references to polymorphic class types; 12 | const_cast can't change types, only const or volatile qualifiers; 13 | reinterpret_cast is for special circumstances, converting between pointers or references and completely unrelated types. 14 | Specifically, it won't do numeric conversions. 15 | C-style and function-style casts do whatever combination of static_cast, const_cast and reinterpret_cast is needed to get the job done. 16 | 17 | * @version 0.1 18 | * @date 2021-10-06 19 | * 20 | * @copyright Copyright (c) 2021 21 | * 22 | */ 23 | 24 | #include 25 | using namespace std; 26 | 27 | int main() { 28 | 29 | int x = 0; 30 | cout << "Insert a number" << endl; 31 | cin >> x; 32 | cout << "Correspondent character: " << static_cast(x) << endl; 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/static cast - float to int/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief Showing functions of static_cast<>(), const_cast, and more. 5 | * 6 | * static_cast` is used for cases where you basically want to reverse an implicit conversion, 7 | * with a few restrictions and additions. `static_cast` performs no runtime checks. 8 | * This should be used if you know that you refer to an object of a specific type, 9 | * and thus a check would be unnecessary. NOTE: casting to char takes ASCII table as reference. 10 | * 11 | dynamic_cast only works for pointers or references to polymorphic class types; 12 | const_cast can't change types, only const or volatile qualifiers; 13 | reinterpret_cast is for special circumstances, converting between pointers or references and completely unrelated types. 14 | Specifically, it won't do numeric conversions. 15 | C-style and function-style casts do whatever combination of static_cast, const_cast and reinterpret_cast is needed to get the job done. 16 | 17 | * @version 0.1 18 | * @date 2021-10-06 19 | * 20 | * @copyright Copyright (c) 2021 21 | * 22 | */ 23 | 24 | #include 25 | using namespace std; 26 | 27 | int main() { 28 | 29 | float x; 30 | cout << "Insert a floating point number" << endl; 31 | cin >> x; 32 | cout << "Correspondent integer number: " << static_cast(x) << endl; 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /C++/21 - Template example/Basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author SSUPI and Prox_y for documentation translation 4 | * @brief Showing simple usage of template with typename keyword, which express a generic undefined type. 5 | For a more complex usage see: 6 | https://github.com/Prox-y/Programming_Languages/tree/master/C%2B%2B/26%20-%20Dictionary/Hash%20table%20with%20hex%20values 7 | * @version 0.1 8 | * @date 2021-11-24 9 | * 10 | * @copyright Copyright (c) 2021 11 | * 12 | */ 13 | #include 14 | using namespace std; 15 | 16 | /*typename indicates generic type, writing class T is equivalent to typename T. the template can accept constant types. 17 | Each function writed below the template, is linked to the template itself until you close the last bracket of that function 18 | In this case, the template it's valid until the class finishes.*/ 19 | template //Z, parameter type. 20 | 21 | class test{ 22 | public: 23 | //array of integers which will become int. 24 | Z value[N]; 25 | }; 26 | 27 | int main() { 28 | //Calling class object, with template arguments specified. 29 | test templateExample; 30 | //constructor call syntax: test(); 31 | 32 | for(int i = 0; i < 3; i++){ 33 | templateExample.value[i] = i+5; 34 | printf("%d ", templateExample.value[i]); //Output: 5 6 7 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /C/07 - Functions/src/main.c: -------------------------------------------------------------------------------- 1 | /*What happens under the hood is this: 2 | 3 | -The instruction pointer calls the "main" stack frame, and starts from the first memory address of it 4 | -When the instruction pointer reaches "func", the system gets a copy of the last reached address in main 5 | then, the instruction pointer gets updates to the new stack frame in memory of "func" to be executed 6 | -Once the stack frame of func is done, the program jumps back to main stack frame and ends its execution. 7 | 8 | With functions we can exploit the pass by reference showcased in chapter 05 9 | 10 | WIth functions we can also return values corresponding to the types we need. 11 | */ 12 | 13 | #include 14 | 15 | 16 | 17 | typedef struct { 18 | int a, b; 19 | } mydata; 20 | 21 | void func() { 22 | printf("Printing from function\n"); 23 | } 24 | 25 | void structPass(mydata *data) { 26 | data->a = 10; 27 | data->b = 20; 28 | } 29 | 30 | void printStruct(mydata *data) { 31 | printf("%d\n%d\n", data->a, data->b); 32 | } 33 | 34 | int returnNumber(void) { 35 | return 10; 36 | } 37 | 38 | char *newString(void) { 39 | return "new string!"; 40 | } 41 | 42 | int main(void) 43 | { 44 | mydata newData; 45 | int x = 0; 46 | char *string = NULL; 47 | structPass(&newData); 48 | printStruct(&newData); 49 | 50 | x = returnNumber(); 51 | string = newString(); 52 | 53 | printf("%d\t%s\n", x, string); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /C/12 - extern Keyword/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Extern keyword allows to increase the scope of a function/variable for external linkage in the compiler. 3 | 4 | in a C++ context, it is used for hybrid programming to allow compilation of .c files with C symbols, along with .cpp files with 5 | C++ symbols with the following snippet: 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | 10 | } 11 | 12 | #endif 13 | 14 | then you can call C functions in .c files. 15 | 16 | For variables it doesn't instantiate the variable itself, i.e. doesn't allocate any memory. This needs to be done somewhere else. 17 | Thus it's important if you want to import the variable from somewhere else. 18 | 19 | For functions, this only tells the compiler that linkage is extern. As this is the default you don't need to explicitly do it. 20 | 21 | in this example, int myvar is declared in the header, and defined in file.c, by including the header, we can then call the same 22 | definition from file.c, without redefining myvar. 23 | 24 | Basically the compiler finds the declaration, finds our definition to allocate memory and then allows further references without 25 | redefining the same variable. 26 | 27 | It is useful if we need to access the same var in different files. 28 | */ 29 | 30 | #include 31 | #include "header.h" 32 | 33 | int main(void) 34 | { 35 | printf("%d\n", myvar); 36 | 37 | printf("extern strings: %s\t%s\t%s\n", strings[0], strings[1], strings[2]); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /C++/29 - Class constructor/Basic Example 2/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class constructor 4 | { 5 | 6 | private: 7 | int16_t a; 8 | public: 9 | void input(); 10 | void output(); 11 | static void funcBeforeObj(); 12 | 13 | constructor(); 14 | ~constructor(); 15 | }; 16 | 17 | void constructor::funcBeforeObj() 18 | { 19 | std::cout << "Printing message before object call: " << std::endl; 20 | } 21 | 22 | void constructor::input() 23 | { 24 | std::cin >> a; 25 | } 26 | 27 | void constructor::output() 28 | { 29 | std::cout << "Value of a after destruction: " << a << std::endl; 30 | } 31 | 32 | 33 | /*In constructors it's possible to call the functions of the class. 34 | If in main we want to call other functions before the constructor, we need them as static methods 35 | NOTE: Function declarations and definitiond are not influenced by this rule.*/ 36 | constructor::constructor() 37 | { 38 | input(); 39 | 40 | if (a > 10) 41 | { 42 | std::cout << "Check by constructor" << std::endl; 43 | } 44 | } 45 | 46 | 47 | //The destructor is called automatically if declared, if you don't want to destroy data, simply don't do this function. 48 | constructor::~constructor() 49 | { 50 | a = 0; 51 | output(); 52 | } 53 | 54 | int main() 55 | { 56 | //static function before constructor initialization. 57 | constructor::funcBeforeObj(); 58 | 59 | /*without the object call constructor.*/ 60 | constructor(); 61 | 62 | /*Alternative way to call constructor and destructor with object.*/ 63 | //constructor obj; 64 | return 0; 65 | } -------------------------------------------------------------------------------- /C++/43 - std::chrono examples/43.2 - std::chrono available time members/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief std::chrono provides also time variables that can be used to interpret values as different 5 | * time measurements: 6 | * 7 | * /* 8 | /// nanoseconds 9 | using nanoseconds = duration<_GLIBCXX_CHRONO_INT64_T, nano>; 10 | 11 | /// microseconds 12 | using microseconds = duration<_GLIBCXX_CHRONO_INT64_T, micro>; 13 | 14 | /// milliseconds 15 | using milliseconds = duration<_GLIBCXX_CHRONO_INT64_T, milli>; 16 | 17 | /// seconds 18 | using seconds = duration<_GLIBCXX_CHRONO_INT64_T>; 19 | 20 | /// minutes 21 | using minutes = duration<_GLIBCXX_CHRONO_INT64_T, ratio< 60>>; 22 | 23 | /// hours 24 | using hours = duration<_GLIBCXX_CHRONO_INT64_T, ratio<3600>>; 25 | 26 | #if __cplusplus > 201703L 27 | /// days 28 | using days = duration<_GLIBCXX_CHRONO_INT64_T, ratio<86400>>; 29 | 30 | /// weeks 31 | using weeks = duration<_GLIBCXX_CHRONO_INT64_T, ratio<604800>>; 32 | 33 | /// years 34 | using years = duration<_GLIBCXX_CHRONO_INT64_T, ratio<31556952>>; 35 | 36 | /// months 37 | using months = duration<_GLIBCXX_CHRONO_INT64_T, ratio<2629746>>; 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | int main(void) 45 | { 46 | for (size_t i = 0; i < 2; ++i) { 47 | std::cout << "waiting 2 seconds..." << std::endl; 48 | std::this_thread::sleep_for(std::chrono::seconds(2)); 49 | } 50 | return 0; 51 | } -------------------------------------------------------------------------------- /C++/09 - Function Parameters/Simple Int Example/importantNote.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | /* 6 | The following is main.cpp rearranged so that it follows bad coding practices. 7 | If you haven't looked at main.cpp, do that first and then return. 8 | 9 | Why this code is bad: 10 | 1. For starters, typically you never want "chained" functions, 11 | i.e. a function that calls a function which calls another function 12 | When in doubt, all function calls should be made in MAIN. 13 | 14 | 2. Line 44 is bad because the function name indicates that it returns a tip, but 15 | its return value is set to total. This is very confusing for a reader. A reader might 16 | worry that function tipAmt is named wrong, or that the variable total is used wrong. 17 | 18 | NOTE: Even if the code works how it's supposed to work, if it is written/structured 19 | incorrectly or in a confusing way then it is BAD CODE. 20 | */ 21 | double totalAmt(double price, double tip) 22 | { 23 | return price + tip; 24 | } 25 | 26 | double tipAmt(double price) 27 | { 28 | double tip = price * 0.18; 29 | cout << "Then you should tip at least $" << tip << endl; 30 | 31 | // THIS IS BAD PRACTICE! 32 | double total = totalAmt(price, tip); 33 | return total; 34 | } 35 | 36 | int main() 37 | { 38 | double price; 39 | double total; 40 | cout << "How much was your dinner bill?" << endl; 41 | cin >> price; 42 | 43 | // THIS IS BAD PRACTICE! 44 | total = tipAmt(price); 45 | 46 | cout << "This will be a grand total of $" << total << endl; 47 | return 0; 48 | } -------------------------------------------------------------------------------- /C++/14 - Casting/static cast/static cast - double to float/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief Showing functions of static_cast<>(), const_cast, and more. 5 | * 6 | * static_cast` is used for cases where you basically want to reverse an implicit conversion, 7 | * with a few restrictions and additions. `static_cast` performs no runtime checks. 8 | * This should be used if you know that you refer to an object of a specific type, 9 | * and thus a check would be unnecessary. NOTE: casting to char takes ASCII table as reference. 10 | * 11 | dynamic_cast only works for pointers or references to polymorphic class types; 12 | const_cast can't change types, only const or volatile qualifiers; 13 | reinterpret_cast is for special circumstances, converting between pointers or references and completely unrelated types. 14 | Specifically, it won't do numeric conversions. 15 | C-style and function-style casts do whatever combination of static_cast, const_cast and reinterpret_cast is needed to get the job done. 16 | 17 | * @version 0.1 18 | * @date 2021-10-06 19 | * 20 | * @copyright Copyright (c) 2021 21 | * 22 | */ 23 | 24 | #include 25 | using namespace std; 26 | 27 | int main() { 28 | 29 | double x; 30 | cout << "Insert a number" << endl; 31 | cin >> x; 32 | cout << "Correspondent floating point number: " << static_cast(x) << endl; 33 | return 0; 34 | 35 | /*34.2654646468746464646465555555555555555555555555555555555555555555555555555555 36 | Correspondent floating point number: 34.2655*/ 37 | } 38 | 39 | -------------------------------------------------------------------------------- /C/11 - Inline Keyword/src/main.c: -------------------------------------------------------------------------------- 1 | /*Inline can be used for optimization purposes. Normally what would happen is this: 2 | 3 | void func() {// instructions...} 4 | 5 | int main(){ function() } 6 | 7 | we execute the main stack frame, when main reaches func, it has to make a jump to the other function stack frame, execute it and then 8 | jump back to the main stack frame. In big functions this is not a problem, but in really short functions there can be a oberhead in 9 | the CPU registers, because it takes more time to jump in and back rather than executing the instructions. 10 | 11 | So, applying inline removes this need to jump, and puts the assembly code of the function inside the main stack frame. 12 | 13 | Now this is a very simple code, so performance won't be affected that much, but in larger programs this can optimize 14 | the code a lot if using more small functions. 15 | 16 | Using static to avoid linking error of undefined reference, forces the linker to include the function symbol in the symbol table. 17 | Extern keyword can work as well to allow the code generation of the function, but in C context static is more appropriate 18 | (unless you really need that function to be extern.) 19 | 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | void func() { 26 | printf("somthing\n"); 27 | } 28 | 29 | static inline void printfunc() { 30 | printf("Something\n"); 31 | } 32 | 33 | int main(void) 34 | { 35 | for (size_t i = 0; i < 10; i++) { 36 | //func(); 37 | printfunc(); 38 | } 39 | 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Assembly/x86/1 - Hello World/main.asm: -------------------------------------------------------------------------------- 1 | ; text = var name 2 | ; db = define byte, since each char is a byte. 3 | ; the actual string 4 | ; 10 (aka 0xa) = \n 5 | 6 | ; data section it's used to initialize variables that are declared 7 | 8 | section .data 9 | 10 | text db "hello world!", 0xa 11 | len equ $ - text ; obtain string lenght 12 | 13 | 14 | ; text section, used to declare functions and write code for those functions 15 | section .text 16 | global main ;can also write it as _start for some assemblers 17 | 18 | main: 19 | mov ebp, esp ; for debugging 20 | mov eax, 4 ; call sys_write to perform a write operation in the regs 21 | mov ebx, 1 ; specify stdout for the file specifier 22 | mov ecx, text ; put your string in the register 23 | mov edx, len ; number of bytes to write 24 | int 0x80 ; this opcode executes the currently sys operation set up in the regs. 25 | 26 | 27 | ; our return 0 setup, EDX must be 1 and EDX, the returned value 0 respectively in these registers. 28 | 29 | ; NOTE: they don't have to be setup always in this way, what matters is that EAX is 1 and then EDX to the status number 30 | ; you want to display. 0 is EXIT_SUCCESS 31 | 32 | exit: 33 | mov eax, 1 34 | mov edx, 0 35 | int 0x80 36 | 37 | 38 | ; quick recap: 39 | 40 | ; EAX 4 represents a write operation to a buffer 41 | 42 | ; EBX 1 represents the buffer ID, in our case, stdout 43 | 44 | ; ECX contains our text 45 | 46 | ; EDX contains the lenght of the string to write 47 | 48 | ; 0x80 executes the write operation (4) into stdout (1). Specifically this opcode executes any sys operation defined in EAX 49 | -------------------------------------------------------------------------------- /C++/01 - Usage Of Variables and printf/complex print statements/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | // NOTE: To run these programs, open terminal, go into the correct directory 7 | // ex: C++/1 - Usage of Variables and printf/complex print statements with variables 8 | // Run "g++ -o main main.cpp" and then "./main" 9 | 10 | int main() 11 | { 12 | string wordToPrint = "Bob"; 13 | int intToPrint = 50; 14 | char charToPrint = 'B'; 15 | double doubleToPrint = 12.50; 16 | 17 | // prints "My dad's name is Bob. He is 50 years old. 18 | // His first name starts with the letter B. For lunch, 19 | // he had a hamburger for $12.5." 20 | cout << "No decimal formatting:" << endl; 21 | cout << "My dad's name is " << wordToPrint << ". He is " 22 | << intToPrint << " years old. His first name starts with the letter " 23 | << charToPrint << ". For lunch, he had a hamburger for $" 24 | << doubleToPrint << "." << endl << endl; 25 | 26 | // prints "My dad's name is Bob. he is 50 years old. 27 | // His first name starts with the letter B. For lunch, 28 | // he had a hamburger for $12.50." 29 | // NOTE: fixed << setprecision(2) allows you to print a decimal with a specific amount of decimal points 30 | cout << "With decimal formatting:" << endl; 31 | cout << "My dad's name is " << wordToPrint << ". He is " 32 | << intToPrint << " years old. His first name starts with the letter " 33 | << charToPrint << ". For lunch, he had a hamburger for $" 34 | << fixed << setprecision(2) << doubleToPrint << "." << endl; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C++/25 - std::map/Basic example/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief Showing a basic dictionary creation in C++, useful 5 | * to create a personal has table too. In this examples i used the mersenne twister algorithm 6 | * to generate the hashes. 7 | * Some basic functions associated with Map: 8 | begin() – Returns an iterator to the first element in the map 9 | end() – Returns an iterator to the theoretical element that follows last element in the map 10 | size() – Returns the number of elements in the map 11 | max_size() – Returns the maximum number of elements that the map can hold 12 | empty() – Returns whether the map is empty 13 | insert(pair(number, number2) – Adds a new element to the map 14 | erase(iterator position) – Removes the element at the position pointed by the iterator 15 | erase(const g)– Removes the key value ‘g’ from the map 16 | clear() – Removes all the elements from the map 17 | * @version 0.1 18 | * @date 2021-12-13 19 | * 20 | * @copyright Copyright (c) 2021 21 | * 22 | */ 23 | #include 24 | #include 25 | using namespace std; 26 | 27 | int main() { 28 | //first int is KEY, second int is VALUE associated to key. 29 | map hash_table; 30 | //Iterator to scan is required, like lists. 31 | map::iterator index; 32 | for (int16_t i = 0; i < 10; i++){ 33 | hash_table.insert(pair(i+1, i)); 34 | } 35 | 36 | for (index = hash_table.begin(); index != hash_table.end(); index++) { 37 | cout << "\tKEY: " << index->first 38 | << "\tHASH: " << index->second << endl; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C++/41 - volatile keyword/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Fabxx 4 | * @brief Volatile it's used to avoid unwanted optimizations on the code while compiling 5 | * that may cause unwanted results where: 6 | * 7 | * -Code may not work as expected when optimization is turned on. 8 | -Code may not work as expected when interrupts are enabled and used. 9 | 10 | Objects declared as volatile are omitted from optimization because their values can 11 | be changed by code outside the scope of current code at any time. Some examples are: 12 | 13 | -Global variables modified by an interrupt service routine outside the scope 14 | -Global variables within a multi-threaded application 15 | 16 | where changes are affected by the optimized code. 17 | 18 | 19 | In this code example, if we apply volatile to local, the re-initialization of ptr will 20 | be able to modify the memory area of "local" instead of himself, so that ptr is linked 21 | to the memory of "local". 22 | 23 | NOTE: this is affected if "local" is const. Also these effects are compiler specific, so you 24 | might have different behaviors. this was tested on GCC/G++. 25 | * @version 0.1 26 | * @date 2023-03-22 27 | * 28 | * @copyright Copyright (c) 2023 29 | * 30 | */ 31 | 32 | #include 33 | 34 | int main(void) 35 | { 36 | const volatile int local = 10; 37 | int *ptr = (int*)&local; 38 | 39 | std::cout << "First value: " << local << std::endl; 40 | 41 | *ptr = 100; 42 | 43 | std::cout << "Modified value: " << local << std::endl; 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /C++/22 - Swap function - integrated and manual implementation/swap - manual implementation/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.c 3 | * @author x86_Avx 4 | * @brief Bubble sorting with a array or integers, works if you initialize the array too. 5 | * @version 0.1 6 | * @date 2021-08-16 7 | * 8 | * @copyright Copyright (c) 2021 9 | * 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | #include 15 | 16 | 17 | void swap(int *x, int *y); 18 | void Bubblesort(int array[]); 19 | void print(int array[]); 20 | void randomizer(int array[]); 21 | 22 | int main() { 23 | 24 | int array[5]; 25 | 26 | randomizer(array); 27 | Bubblesort(array); 28 | print(array); 29 | } 30 | 31 | void randomizer(int array[]) { 32 | 33 | int seed = time(NULL); 34 | srand(seed); 35 | 36 | int i; 37 | for (i = 0; i < 5; i++) { 38 | cout << "Randomizing the " << i+1 << " number" << endl; 39 | array[i] = rand() % (100 + 18 - 1) + 18; //randomizing between 18 and 100. 40 | cout << i+1 << " Element: " << array[i] << endl; 41 | } 42 | } 43 | 44 | //Manual swap function. 45 | void swap(int *x, int *y) { 46 | int temp = 0; 47 | temp = *x; 48 | *x = *y; 49 | *y = temp; 50 | } 51 | 52 | void Bubblesort(int array[]) { 53 | int tmp, i, j; 54 | /*We repeat this sequence of code untilthe array is finished.*/ 55 | 56 | for (i = 0; i < 5; i++){ 57 | for (j = i+1; j < 5; j++) { 58 | if (array[i] > array[j]) { 59 | swap(&array[i], &array[j]); //in C++ you can just write like this, no need of the above funciton. 60 | } 61 | } 62 | } 63 | } 64 | 65 | void print(int array[]) { 66 | 67 | int i; 68 | for (i = 0; i < 5; i++) { 69 | cout << " " << array[i]; 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /C++/15 - mutable identifier/mutbale int/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author your name (you@domain.com) 4 | * @brief This program shows how we can operate on class variable with a constant function. 5 | * a constant function shouldn't be able to edit a variable because, like the name 6 | * suggests, a value operated by a constant function can't be changed. To be 7 | * able to do so, we create a mutable variable to pass to the constant function, so the 8 | * constant function used to access the class can still edit it's objects. We're trying 9 | * to edit an integer with a constant access to the class. Note that this requires a constructor, 10 | which means that the class itself must operate on the class values, then we use the constructor 11 | as a constant. 12 | * @version 0.1 13 | * @date 2021-10-11 14 | * 15 | * @copyright Copyright (c) 2021 16 | * 17 | */ 18 | 19 | #include 20 | using namespace std; 21 | 22 | class myclass { 23 | public: 24 | int a; 25 | mutable int b; 26 | 27 | myclass(int x, int y) { //class constructor, required by the constant to operate. 28 | x = 3, y = 15; 29 | a = x; 30 | b = y; 31 | } 32 | }; 33 | int main() { 34 | const myclass access(3, 7); //the two integers in the constructor parameters. 35 | 36 | cout << "First access:\n"; 37 | cout< 25 | #include 26 | 27 | class A 28 | { 29 | public: 30 | void something(); 31 | }; 32 | 33 | void A::something() 34 | { 35 | std::cout << "something shared" << std::endl; 36 | } 37 | 38 | int main(void) 39 | { 40 | std::shared_ptr pointer1 = std::make_shared(); 41 | //pointer 2 being initialized with A resource of pointer1. 42 | std::shared_ptr pointer2(pointer1); 43 | 44 | pointer1->something(); 45 | pointer2->something(); 46 | 47 | std::cout << pointer2.use_count() << std::endl; 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Golang/02 - variables and formatting/main.go: -------------------------------------------------------------------------------- 1 | /* Example of variable declaration and usage. 2 | for a list of types check this source: https://go.dev/tour/basics/11 3 | 4 | Main difference between print and prinf: 5 | 6 | print allows to print a variable in the middle of a string without using % and the char to indicate the type, but you have to write var in the middle of the strings. 7 | 8 | printf allows to do C style formatting, you have to write % and the char corresponding to the var type, but you can write all vars at the end. 9 | 10 | sprint, sprintf, sprintln allows us to save a string into a variable just like C function. 11 | 12 | Same thing between scan and scanf 13 | */ 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | 21 | //declaration types 22 | var name = "Fabx" 23 | var name1 string = "Fabxx" 24 | 25 | /*Declaration with implicit type, similar to "auto" in C++ but there is no type written. 26 | it determines the type from the data assigned. NOTE: once created if you need to reassign the variable 27 | you just need to type name3 = "something", the := syntax is used only for initialization*/ 28 | name3 := "string" 29 | 30 | // creating uninitialized var. This is the only syntax that allows it, with both var and typename 31 | var name2 string 32 | 33 | /*you can use Println which prints the next strings on a new line each variable, but for each var a new Println instruction is 34 | required. instead inside print you can use \n directly.*/ 35 | fmt.Print("Printing my name:", name, "\n", name1, "\n", name2, "\n", name3, "\n") 36 | 37 | //using printf like C formatting, a "\n" can also be put as an argument and needs a %v 38 | fmt.Printf("My name is: %v \n", name) 39 | 40 | name2 = fmt.Sprint("returned string\n") 41 | fmt.Print(name2) 42 | } 43 | -------------------------------------------------------------------------------- /Golang/03 - Arrays and Slices/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | How to declare and use an array: 3 | 4 | var name [size]type = [size]type{elements} 5 | or 6 | var name = [size]type{elements} 7 | 8 | len is an instruction that returns the size of an array. you don't have to use it to print array contents, it just indicates the size of the array 9 | 10 | Arrays use a fixed size, slices don't. to make a slice declare an array and leave the size brackets empty 11 | */ 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | ) 18 | 19 | func main() { 20 | 21 | //var array [3]int = [3]int{1, 2, 3} 22 | var array = [3]int{4, 5, 6} 23 | var array2 = [2]string{"Fabxx", "Fab"} 24 | 25 | fmt.Print("Array elements:", array, "\n", "Array size: ", len(array), "\n", 26 | "Array elements:", array2, "\n", "Array size:", len(array2), "\n\n") 27 | 28 | //accessing array element 29 | 30 | array2[0] = "Fab1" 31 | fmt.Print("Name changed: ", array2[0], "\n", 32 | "Array content: ", array2, "\n") 33 | 34 | //slice 35 | var myslice = []int{1, 5, 7} 36 | var myslice2 = []int{9, 12, 13} 37 | 38 | // append data to slice, we can add data since size is not fixed. Returns a new slice. We can also merge slices. 39 | 40 | myslice = append(myslice, 40) 41 | 42 | fmt.Print("Edited slice: ", myslice, "\n") 43 | 44 | myslice = append(myslice, myslice2...) 45 | 46 | fmt.Print("Merged slice: ", myslice, "\n") 47 | 48 | // get elements from array range. NOTE: includes from 0:4-1 elements. gets from 0:3 then stops at 4 49 | var myrange = myslice[0:4] 50 | 51 | // get everything from the array starting from a number, and viceversa 52 | var myrange2 = myslice[3:] 53 | var myrange3 = myslice[:5] 54 | 55 | fmt.Print(myrange, "\n", myrange2, "\n", myrange3, "\n") 56 | 57 | // can also append to a range 58 | 59 | myrange = append(myrange, 1) 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Golang/19 - Files/main.go: -------------------------------------------------------------------------------- 1 | /* Shows how to write structs or single vars into a file. 2 | 3 | 4 | os.OpenFile takes: 5 | 6 | -The file name in the same or different folder 7 | -System flag for permissions on the file, in this case is READ ONLY 8 | -file mode inside the filesystem 9 | 10 | 11 | in this basic example i just create a file without checking if it exists already. 12 | 13 | NOTE: encoding/binary package can only write fixed-size variables inside a struct. the size must be precise in the type 14 | (cannot write int, only int8, int16 and so on. Cannot write strings) 15 | 16 | here i use encoding/json. 17 | 18 | NOTE 2: To write struct data, the variables of the struct must begin with a uppercase letter, or else they won't be exported. 19 | also using uppercase letter makes the vars visible on other packages, increasing the scope. 20 | 21 | 22 | NOTE 3: to write single variables, just use file.Method() to the corresponding value you're trying to write. 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "encoding/json" 29 | "fmt" 30 | "io/fs" 31 | "os" 32 | ) 33 | 34 | type data struct { 35 | Value float32 36 | } 37 | 38 | func fileOps() { 39 | 40 | structure := data{ 41 | Value: 2.0, 42 | } 43 | 44 | file, fileError := os.Create("file.txt") 45 | 46 | if fileError != nil { 47 | fmt.Println(fileError) 48 | } else { 49 | os.OpenFile(file.Name(), os.O_RDWR, fs.FileMode(os.O_RDWR)) 50 | //Marhal Indent gives automatic indentation in json style inside the files. 51 | dataEnc, err := json.MarshalIndent(structure, "", " ") 52 | 53 | if err != nil { 54 | fmt.Println(err) 55 | } else { 56 | err := os.WriteFile(file.Name(), dataEnc, fs.FileMode(os.O_RDWR)) 57 | 58 | if err != nil { 59 | fmt.Println("Error: ", err) 60 | } else { 61 | file.Close() 62 | } 63 | 64 | } 65 | 66 | } 67 | 68 | } 69 | 70 | func main() { 71 | 72 | fileOps() 73 | 74 | } 75 | -------------------------------------------------------------------------------- /C++/23 - List, stack, tail/2 - Stack example/Introduction, input, removing element, printing/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author -_< 4 | * @brief Showing basic example usage of a stack. Input is done from above and 5 | * scrolls down. Removal remoes items from the bottom. Values accepted are numbers. 6 | * The functions associated with stack are: 7 | empty() – Returns whether the stack is empty in boolean format. – Time Complexity : O(1) 8 | size() – Returns the size of the stack – Time Complexity : O(1) 9 | top(LIFO based, bottom element it's considered the top) – Returns a reference to the top most element of the stack – Time Complexity : O(1) 10 | push(g)/emplace(g) – Adds the element ‘g’ at the top of the stack – Time Complexity : O(1) 11 | pop() – Deletes the top most element of the stack – Time Complexity : O(1) 12 | * @version 0.1 13 | * @date 2021-12-13 14 | * 15 | * @copyright Copyright (c) 2021 16 | * 17 | */ 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | int main() { 23 | stack stack1; 24 | stack1.push(10.70); 25 | stack1.push(20); 26 | 27 | while (!stack1.empty()) { 28 | cout << "Printing with while: " << stack1.top() << endl; 29 | //if we don't empty the stack, the pointer to it will always detect the last element, resulting in a loop. 30 | stack1.pop(); 31 | } 32 | 33 | stack1.push(40); 34 | stack1.push(60); //current top in LIFO logic. 35 | /*The for here is a little tricky, to avoid segmentation fault we cannot compare any kind of 36 | iterator here since it's a boolean value that stops the function. we can leave empty spaces and use the 37 | condition directly with for*/ 38 | for (; !stack1.empty();){ 39 | cout << "Printing with for: " << stack1.top() << endl; 40 | if (stack1.top() == 40){ 41 | cout << "Found 40 on list!" << endl; 42 | } 43 | stack1.pop(); 44 | } 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /home/fab/Scrivania/Objects as parameters 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "/usr/local") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Install shared libraries without execute permission? 31 | if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) 32 | set(CMAKE_INSTALL_SO_NO_EXE "0") 33 | endif() 34 | 35 | # Is this installation the result of a crosscompile? 36 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 37 | set(CMAKE_CROSSCOMPILING "FALSE") 38 | endif() 39 | 40 | # Set default install directory permissions. 41 | if(NOT DEFINED CMAKE_OBJDUMP) 42 | set(CMAKE_OBJDUMP "/usr/bin/objdump") 43 | endif() 44 | 45 | if(CMAKE_INSTALL_COMPONENT) 46 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 47 | else() 48 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 49 | endif() 50 | 51 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT 52 | "${CMAKE_INSTALL_MANIFEST_FILES}") 53 | file(WRITE "/home/fab/Scrivania/Objects as parameters/${CMAKE_INSTALL_MANIFEST}" 54 | "${CMAKE_INSTALL_MANIFEST_CONTENT}") 55 | -------------------------------------------------------------------------------- /C++/25 - std::map/Hash table with hex values/include/hash_table.h: -------------------------------------------------------------------------------- 1 | #ifndef D31029FC_34F7_4015_872A_54FD04EC5B40 2 | #define D31029FC_34F7_4015_872A_54FD04EC5B40 3 | #include 4 | using namespace std; 5 | #include 6 | #include 7 | #include 8 | 9 | //class T = typename T. 10 | //first scheme attached to the class. 11 | template 12 | class hashtable { 13 | private: 14 | map hash_table; 15 | //typename needed to call embedded class iterator under template. 16 | typename map::iterator index; 17 | stringstream decin; 18 | string output; 19 | public: 20 | //inserting values in the hash table, calling randomizer member with it's template. 21 | /*calling constructor from another constructor. When directly calling another constructor 22 | you must recall the template and specify the data types. in this case datatype becomes int*/ 23 | functiontype hashtablerandomizer() { 24 | for (size_t i = 0; i < 5; i++){ 25 | randomizer(); 26 | hash_table.insert(pair(i+1, randomizer().number)); 27 | } 28 | } 29 | //converting hash values to hexadecimal. 30 | functiontype dec2hex() { 31 | decin << hex << index->second; 32 | string out(decin.str()); 33 | output = out; 34 | } 35 | 36 | hashtable() { 37 | hashtablerandomizer(); 38 | for (index = hash_table.begin(); index != hash_table.end(); index++){ 39 | dec2hex(); 40 | cout << "\tKEY: " << index->first; 41 | cout << "\tHASH: " << output << endl; 42 | } 43 | } 44 | }; 45 | 46 | #endif /* D31029FC_34F7_4015_872A_54FD04EC5B40 */ 47 | 48 | -------------------------------------------------------------------------------- /C++/12 - Object Oriented Programming/Objects as parameters/CMakeFiles/Makefile.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.22 3 | 4 | # The generator used is: 5 | set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") 6 | 7 | # The top level Makefile was generated from the following files: 8 | set(CMAKE_MAKEFILE_DEPENDS 9 | "CMakeCache.txt" 10 | "CMakeFiles/3.22.3/CMakeCCompiler.cmake" 11 | "CMakeFiles/3.22.3/CMakeCXXCompiler.cmake" 12 | "CMakeFiles/3.22.3/CMakeSystem.cmake" 13 | "CMakeLists.txt" 14 | "/usr/share/cmake/Modules/CMakeCInformation.cmake" 15 | "/usr/share/cmake/Modules/CMakeCXXInformation.cmake" 16 | "/usr/share/cmake/Modules/CMakeCommonLanguageInclude.cmake" 17 | "/usr/share/cmake/Modules/CMakeGenericSystem.cmake" 18 | "/usr/share/cmake/Modules/CMakeInitializeConfigs.cmake" 19 | "/usr/share/cmake/Modules/CMakeLanguageInformation.cmake" 20 | "/usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake" 21 | "/usr/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake" 22 | "/usr/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake" 23 | "/usr/share/cmake/Modules/Compiler/GNU-C.cmake" 24 | "/usr/share/cmake/Modules/Compiler/GNU-CXX.cmake" 25 | "/usr/share/cmake/Modules/Compiler/GNU.cmake" 26 | "/usr/share/cmake/Modules/Platform/Linux-GNU-C.cmake" 27 | "/usr/share/cmake/Modules/Platform/Linux-GNU-CXX.cmake" 28 | "/usr/share/cmake/Modules/Platform/Linux-GNU.cmake" 29 | "/usr/share/cmake/Modules/Platform/Linux.cmake" 30 | "/usr/share/cmake/Modules/Platform/UnixPaths.cmake" 31 | ) 32 | 33 | # The corresponding makefile is: 34 | set(CMAKE_MAKEFILE_OUTPUTS 35 | "Makefile" 36 | "CMakeFiles/cmake.check_cache" 37 | ) 38 | 39 | # Byproducts of CMake generate step: 40 | set(CMAKE_MAKEFILE_PRODUCTS 41 | "CMakeFiles/CMakeDirectoryInformation.cmake" 42 | ) 43 | 44 | # Dependency information for all targets: 45 | set(CMAKE_DEPEND_INFO_FILES 46 | "CMakeFiles/main.dir/DependInfo.cmake" 47 | ) 48 | -------------------------------------------------------------------------------- /C++/12.1 classes not OOP with static/from class to class access with static members/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main.cpp 3 | * @author Prox_Y 4 | * @brief A class can access to another class only if his members are static. NOTE: static it's required only if you're using multiple classes that needs to access 5 | each other members. If you use a single class, static it's not needed. 6 | * @version 0.1 7 | * @date 2021-10-19 8 | * 9 | * @copyright Copyright (c) 2021 10 | * 11 | */ 12 | 13 | #include 14 | 15 | using namespace std; 16 | 17 | class class1 { 18 | private: 19 | static int a; 20 | public: 21 | static void member() { 22 | cout << "Hello" << endl; 23 | } 24 | void nonStaticMember() { 25 | cout << "No hello" << endl; 26 | 27 | //cin >> a; error, function not static, can't access static variable. 28 | } 29 | }; 30 | 31 | class class2 { 32 | public: 33 | static void member1() { 34 | class1::member(); 35 | //class1::nonStaticMember(); gives error. 36 | } 37 | }; 38 | 39 | //private members must be static too: 40 | 41 | class class3 { 42 | private: 43 | static int a; 44 | public: static void input(){ 45 | cin >> a; 46 | cout << "Static variable: " << a << endl; 47 | }; 48 | 49 | /*If in a class there are private variables, the functions/members that have to operate on them 50 | MUST be all in the same class, or else we won't have access to the results we need. 51 | 52 | 53 | If we need a value of a variable from a class to another, like doing a switch in another class with a 54 | value from another class. we can make that variable in the class public, out of all the members: 55 | */ 56 | class input { 57 | public: 58 | static int choice; //public variable, ACCESSIBLE FORM OTHER CLASSES. 59 | 60 | static void inputinit() { 61 | cin >> choice; 62 | } 63 | 64 | }; 65 | 66 | class switcher { 67 | 68 | public: 69 | static void switchoption() { 70 | switch (input::choice) { //switching choice value from another class member. 71 | case 1: 72 | 73 | }; 74 | --------------------------------------------------------------------------------