Skip to content

Instantly share code, notes, and snippets.

View plusangel's full-sized avatar
😁
happy coding!

angelos plastropoulos plusangel

😁
happy coding!
View GitHub Profile
@plusangel
plusangel / CMakeLists.txt
Created June 6, 2020 17:37
Simple factory pattern example
cmake_minimum_required(VERSION 3.16)
project(factory_methods)
set(CMAKE_CXX_STANDARD 17)
add_library(shape_factory shape_factory.cpp)
add_executable(factory_method main.cpp)
target_link_libraries(factory_method shape_factory)
@plusangel
plusangel / CMakeLists.txt
Last active June 5, 2020 18:54
Monostate idiom example in C++
cmake_minimum_required(VERSION 3.16)
project(monostate_idiom)
set(CMAKE_CXX_STANDARD 17)
add_library(monostate monostate.cpp)
add_executable(monostate_idiom main.cpp)
target_link_libraries(monostate_idiom monostate)
@plusangel
plusangel / CMakeLists.txt
Last active June 5, 2020 18:54
Singleton idiom example in C++
cmake_minimum_required(VERSION 3.16)
project(singleton_idiom)
set(CMAKE_CXX_STANDARD 17)
add_library(singleton singleton.cpp)
add_executable(singleton_idiom main.cpp)
target_link_libraries(singleton_idiom singleton)
@plusangel
plusangel / CMakeLists.txt
Created June 2, 2020 18:45
This is an example of the pimpl idiom using smart pointers.
cmake_minimum_required(VERSION 3.16)
project(pimpl_idiom)
set(CMAKE_CXX_STANDARD 17)
add_library(timer timer.cpp)
add_executable(pimpl_idiom main.cpp)
target_link_libraries(pimpl_idiom timer)
//
// Tell me about your birthday!
// Created by angelos on 03/05/2020.
//
#include <ctime>
#include <iostream>
#include <string_view>
int validate_input(int lower_limit, int upper_limit, std::string_view prompt);
void year(tm &birthday);
@plusangel
plusangel / simple_calc.cpp
Created March 1, 2020 10:13
String handling using Boost's tokenizer
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <boost/tokenizer.hpp>
#include <iostream>
using namespace std::literals::string_literals;
int basic_calc(const std::string &input) {
boost::char_separator<char> operators{"+-*/"};
@plusangel
plusangel / CMakeLists.txt
Last active February 23, 2020 11:06
A program that accepts any number of command line arguments and prints them in alphanumerically sorted order, using a std::set<const char*> to store the elements, then iterate over the set to obtain the sorted result (custom comparator that compares two C-style strings)
cmake_minimum_required(VERSION 3.15)
project(sets)
set(CMAKE_CXX_STANDARD 17)
add_executable(sets sets.cpp)
@plusangel
plusangel / CMakeLists.txt
Last active January 17, 2020 12:26
Poco echo TCPServer
cmake_minimum_required(VERSION 3.0.0)
project(tcp_server VERSION 0.1
DESCRIPTION "Poco echo TCPServer")
set(CMAKE_CXX_STANDARD 17)
find_package(Poco REQUIRED Foundation Net)
# check if Poco library was found
@plusangel
plusangel / tf_ros.py
Created December 3, 2019 14:58
ROS camera streaming to TensorFlow
def callback(self, image_msg):
# convert a ROS image message into an cv::Mat using module cv_bridge
cv_image = self._cv_bridge.imgmsg_to_cv2(image_msg, "bgr8")
# copy from
# classify_image.py
# convert (encode) the image format into streaming data and assign it to
# memory cache. It is mainly used for compressing image data format to facilitate
# network transmission
image_data = cv2.imencode('.jpg', cv_image)[1].tostring()
@plusangel
plusangel / vtbl.cpp
Created November 14, 2019 18:55
vtbl example
#include <iostream>
class Base {
public:
virtual void function1() { std::cout << "Base::function1()" << std::endl; }
virtual void function2() { std::cout << "Base::function2()" << std::endl; }
virtual ~Base() { std::cout << "Base destructor" << std::endl; }
};
class Derived1 : public Base {