Skip to content

Instantly share code, notes, and snippets.

View illescasDaniel's full-sized avatar
💻
Learning something new

Daniel Illescas Romero illescasDaniel

💻
Learning something new
View GitHub Profile
@illescasDaniel
illescasDaniel / varReflection.cpp
Last active October 23, 2016 19:43
Variables reflection [C++]
#include <iostream>
using namespace std;
#define varName(_name_) #_name_
#define varValue(_variable_) _variable_
int main() {
int test = 10;
@illescasDaniel
illescasDaniel / random.cpp
Last active October 23, 2016 18:58
Generate random numbers and sort it [C++]
#include <iostream>
#include <chrono>
#include <vector>
#include <random>
using namespace std;
using namespace chrono;
int main() {
@illescasDaniel
illescasDaniel / smartPointers.cpp
Last active October 23, 2016 19:42
Smart pointers (unique_ptr) [C++]
#include <iostream>
#include <memory>
#include <algorithm>
using namespace std;
struct Human {
int age = 0;
Human(const int& newAge) { age = newAge; }
};
@illescasDaniel
illescasDaniel / dice.cpp
Last active October 23, 2016 19:42
Throw dice [C++]
#include <iostream>
#include <random>
using namespace std;
int main() {
random_device rd;
mt19937 rng(rd());
uniform_int_distribution<> dice(1, 6);
@illescasDaniel
illescasDaniel / forLoops.cpp
Last active November 26, 2016 18:54
For loops [C++]
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void print(const int& i) {
cout << i << ' ';
}
@illescasDaniel
illescasDaniel / placeholders.cpp
Created October 23, 2016 21:33
Change parameter order in functions [C++]
#include <functional>
#include <iostream>
using namespace std;
using namespace std::placeholders;
void show(const string& a, const string& b, const string& c) {
cout << a << "; " << b << "; " << c << endl;
}
@illescasDaniel
illescasDaniel / makefile
Last active October 23, 2016 21:51
Makefile for modern C++
## FLAGS ##
Libraries = -L lib
Headers = -I include
Sources = main.cpp $(Headers) $(Libraries)
CompilerFlags = -O3 -Wall
OutputName = test
## TARGETS ##
all:
@g++ -std=c++1z $(CompilerFlags) $(Sources) -o $(OutputName)
@illescasDaniel
illescasDaniel / checkNull.cpp
Last active November 26, 2016 19:09
Check null pointer with an assertion [C++]
#include <iostream>
#include <cstddef>
#include <cassert>
using namespace std;
int main(int argc, char *argv[]) {
int * numbers = nullptr; // = new int[3]{1,2,3};
@illescasDaniel
illescasDaniel / threadVectors.cpp
Created October 24, 2016 11:26
Concurrent programming (sort vectors) [C++]
#include <iostream>
#include <thread>
#include <chrono>
#include <ctime>
#include <cstddef>
using namespace std;
using namespace chrono;
void sortVector() {
@illescasDaniel
illescasDaniel / map.cpp
Created October 24, 2016 11:32
Map / Dictionary [C++]
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(int argc, char *argv[]) {
map<string,int> dic;