├── Cpp
├── asioTcpServer
│ ├── build
│ │ ├── CMakeFiles
│ │ │ ├── progress.marks
│ │ │ ├── server.dir
│ │ │ │ ├── progress.make
│ │ │ │ ├── depend.make
│ │ │ │ ├── link.txt
│ │ │ │ ├── depend.internal
│ │ │ │ ├── flags.make
│ │ │ │ ├── cmake_clean.cmake
│ │ │ │ ├── CXX.includecache
│ │ │ │ └── DependInfo.cmake
│ │ │ ├── cmake.check_cache
│ │ │ ├── feature_tests.bin
│ │ │ ├── 3.13.4
│ │ │ │ ├── CompilerIdC
│ │ │ │ │ └── a.out
│ │ │ │ ├── CompilerIdCXX
│ │ │ │ │ └── a.out
│ │ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ │ ├── CMakeSystem.cmake
│ │ │ │ └── CMakeCCompiler.cmake
│ │ │ ├── TargetDirectories.txt
│ │ │ ├── CMakeDirectoryInformation.cmake
│ │ │ ├── feature_tests.c
│ │ │ └── Makefile.cmake
│ │ └── cmake_install.cmake
│ ├── CMakeLists.txt
│ └── server.cpp
├── QtOpenCV
│ ├── staticTest
│ │ ├── my_math.cpp
│ │ ├── my_math.h
│ │ ├── .qmake.stash
│ │ ├── staticTest.pro
│ │ └── main.cpp
│ ├── QtOpencvQml
│ │ ├── qml.qrc
│ │ ├── qmlType.h
│ │ ├── main.qml
│ │ ├── qmlType.cpp
│ │ ├── .qmake.stash
│ │ ├── QtOpencvQml.pro
│ │ └── main.cpp
│ ├── Editor
│ │ ├── main.cpp
│ │ ├── editor.pro
│ │ └── mainwindow.h
│ └── Viewer
│ │ ├── main.cpp
│ │ ├── .qmake.stash
│ │ ├── viewer.pro
│ │ └── mainwindow.h
├── reverserInt.cpp
├── nonDerived.cpp
├── findSubstringInString.cpp
├── socketExample
│ ├── main.cpp
│ ├── myserver.h
│ ├── myserver.cpp
│ ├── myclient.h
│ ├── mytask.h
│ ├── mytask.cpp
│ ├── socketExample.pro
│ ├── socketExample.uml
│ └── myclient.cpp
├── firstNonRepeatingChar.cpp
├── findMinReturnType.cpp
├── CustomAllocator.cpp
├── reverseWordsInSentence.cpp
├── openCVExample.cpp
├── maxSubArray.cpp
├── minMove3Consecutive.cpp
├── majorityElementII.cpp
├── conversionOperator.cpp
├── twoSum.cpp
├── numIslandsDFS.cpp
├── RTTI.cpp
├── lambdaOutOfScope.cpp
├── framebuffer1.c
├── nonAutoDuration.cpp
├── partialMocking.cpp
├── asyncProcess.cpp
├── stockPair.cpp
├── longestPalindrome.cpp
├── LongetCommonSubsequence.cpp
├── server.cpp
├── twoOutOfThreef.cpp
├── LongestCommonSubsDynamic.cpp
├── findDuplicate.cpp
├── numberOfIslands_dfs.cpp
├── forSum2.cpp
├── threadLimitTest.cpp
├── stockPair2.cpp
├── travellingSalesMan.cpp
├── FirstUniqueCharacterInaString.cpp
├── minTimeToCompleteTrip.cpp
├── maxArea.cpp
├── nestedStructExample.cpp
├── subtractMin.cpp
├── LongestCommonSubsequence.cpp
├── stringToInt.cpp
├── async_server.cpp
├── forSum22.cpp
├── client.cpp
├── swapNodes.cpp
├── numberOfMoves.cpp
├── stackWithMaxElement.cpp
├── 3sum.cpp
├── longestPalindromeManacher.cpp
├── updateTime.cpp
├── getFramebuffer.cpp
├── addTowNumbers.cpp
├── minimumSwap.cpp
├── async_server2.cpp
├── mergeSortedLinkedLists.cpp
├── BFS.cpp
├── zigzag-conversion.cpp
├── LCS.cpp
├── MinNumberSwapAnagram2.cpp
├── circleGlfw.cpp
├── linkedListCycle2.cpp
├── rangeExpressionLifeTime.cpp
├── superReducedString.cpp
├── productExceptItself.cpp
├── index.html
├── numberOfIslands.cpp
├── zigzag-conversion2.cpp
├── Knapsack.cpp
├── minAbsoluteSumDiff.cpp
├── maxProfit.cpp
├── quickSort.cpp
├── maximumStock.cpp
├── LcsDynamicTable.cpp
├── faceDetection_opencv_cuda.cpp
├── RecorderDataInLogs2.cpp
├── longestPalindromicString.cpp
├── RecorderDataInLogs.cpp
├── largestKthElement.cpp
├── countProtifMonths.cpp
├── LinkedListExample.cpp
└── zipDataList.cpp
├── cmakeExample
├── app
│ ├── CMakeLists.txt
│ └── main.cpp
├── CMakeLists.txt
└── lib
│ ├── src
│ └── lib.cpp
│ ├── include
│ └── lib
│ │ └── lib.h
│ └── CMakeLists.txt
├── LinkTimeSubstitution
├── Data.cpp
├── example.cpp
├── include
│ ├── Data.h
│ └── MockData.h
├── MockData.cpp
├── example_test.cpp
└── CMakeLists.txt
├── googleTest
├── linecoverage.png
├── src
│ ├── foo.cpp
│ ├── dummy.cpp
│ └── example.cpp
├── include
│ ├── foo.hpp
│ ├── foo_if.hpp
│ ├── dummy.hpp
│ └── mock_foo.hpp
└── test.puml
├── CmakeExample2
├── src
│ ├── Example.cpp
│ ├── Formula.cpp
│ ├── main.cpp
│ ├── Example.h
│ ├── Formula.h
│ └── CMakeLists.txt
├── tst
│ ├── main.cpp
│ ├── Formula-test.cpp
│ ├── Example-text.h
│ ├── include
│ │ └── Example-text.h
│ ├── CMakeLists.txt
│ └── Example-text.cpp
└── CMakeLists.txt
├── Py
├── regressionTf.py
├── InteractWithBinance.py
├── runVideo.py
├── ex.py
├── pythonGstreamer.py
├── recordVideo.py
├── gstreamerPython.py
├── drawSingleRect.py
├── FaceDetection.py
├── clientWebsocket.py
├── piCameraVideo.py
├── DrawCircle.py
├── numberOfIslands.py
├── drawRect.py
├── regressinTf.py
├── gstExample.py
├── cameraJetsonNanoGst3.py
└── gradientDescent.py
├── protoExamples
├── test.proto
├── example.proto
├── test.cpp
├── socket_server_json.py
└── socket_server.py
├── sharedCallbackExample
├── exampleAInt.h
├── exampleBInt.h
├── exampleB.cpp
├── main.cpp
├── exampleB.h
├── exampleA.h
└── exampleA.cpp
├── gtestExample
├── example.cpp
└── exampleTest.cpp
└── bash
└── brihtPi.sh
/Cpp/asioTcpServer/build/CMakeFiles/progress.marks:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/cmakeExample/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(app main.cpp)
2 |
3 | target_link_libraries(app lib)
--------------------------------------------------------------------------------
/LinkTimeSubstitution/Data.cpp:
--------------------------------------------------------------------------------
1 | #include "Data.h"
2 |
3 | int Data::call() {
4 | return 42;
5 | }
6 |
--------------------------------------------------------------------------------
/googleTest/linecoverage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/googleTest/linecoverage.png
--------------------------------------------------------------------------------
/CmakeExample2/src/Example.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "Example.h"
3 |
4 | int Example::foo()
5 | {
6 |
7 | return 1;
8 | }
--------------------------------------------------------------------------------
/CmakeExample2/src/Formula.cpp:
--------------------------------------------------------------------------------
1 | #include "Formula.h"
2 |
3 | int Formula::bla(int arg1) {
4 | return arg1 * 2;
5 | }
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/progress.make:
--------------------------------------------------------------------------------
1 | CMAKE_PROGRESS_1 = 1
2 | CMAKE_PROGRESS_2 = 2
3 |
4 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/staticTest/my_math.cpp:
--------------------------------------------------------------------------------
1 | #include "my_math.h"
2 |
3 | double reciprocal(double d) {
4 | return 1.0 / d;
5 | }
6 |
--------------------------------------------------------------------------------
/Py/regressionTf.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pandas as pd
3 | import matplotlib.pyplot as plt
4 | import tensorflow as tf
5 |
6 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/QtOpencvQml/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/cmake.check_cache:
--------------------------------------------------------------------------------
1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file
2 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/staticTest/my_math.h:
--------------------------------------------------------------------------------
1 | #ifndef H_MY_MATH
2 | #define H_MY_MATH
3 |
4 | double reciprocal(double d);
5 |
6 | #endif // H_MY_MATH
7 |
--------------------------------------------------------------------------------
/cmakeExample/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.15)
2 |
3 | project(cmakeExample)
4 |
5 | add_subdirectory(lib)
6 | add_subdirectory(app)
7 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/feature_tests.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/Cpp/asioTcpServer/build/CMakeFiles/feature_tests.bin
--------------------------------------------------------------------------------
/cmakeExample/lib/src/lib.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "lib/lib.h"
4 |
5 | void lib::foo()
6 | {
7 | std::cout<<"hello from foo"<
2 | #include "lib/lib.h"
3 |
4 | int main()
5 | {
6 |
7 | lib lib;
8 | lib.foo();
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/CmakeExample2/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Formula.h"
3 |
4 | int main() {
5 | std::cout << "Bla: " << Formula::bla(2) << std::endl;
6 | return 0;
7 | }
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CompilerIdC/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CompilerIdC/a.out
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CompilerIdCXX/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CompilerIdCXX/a.out
--------------------------------------------------------------------------------
/CmakeExample2/tst/main.cpp:
--------------------------------------------------------------------------------
1 | #include "gtest/gtest.h"
2 |
3 | int main(int argc, char **argv) {
4 | ::testing::InitGoogleTest(&argc, argv);
5 | return RUN_ALL_TESTS();
6 | }
--------------------------------------------------------------------------------
/protoExamples/test.proto:
--------------------------------------------------------------------------------
1 |
2 | syntax = "proto3";
3 |
4 | message Test {
5 |
6 | uint64 number = 1;
7 |
8 | string name = 2;
9 |
10 | repeated int64 id = 3;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/CmakeExample2/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.10)
2 | project(ExampleProject)
3 |
4 | set(CMAKE_CXX_STANDARD 14)
5 |
6 | add_subdirectory(tst)
7 | add_subdirectory(src)
8 |
9 |
--------------------------------------------------------------------------------
/LinkTimeSubstitution/example.cpp:
--------------------------------------------------------------------------------
1 | #include "Data.h"
2 |
3 | class Example {
4 | Data data;
5 |
6 | public:
7 | int foo() {
8 | return data.call();
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CMakeDetermineCompilerABI_C.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CMakeDetermineCompilerABI_C.bin
--------------------------------------------------------------------------------
/sharedCallbackExample/exampleAInt.h:
--------------------------------------------------------------------------------
1 | #ifndef _EXAMPLEAINT_H_
2 | #define _EXAMPLEAINT_H_
3 |
4 | class interfaceA
5 | {
6 | public:
7 | virtual void foo() = 0;
8 | };
9 |
10 | #endif
--------------------------------------------------------------------------------
/CmakeExample2/src/Example.h:
--------------------------------------------------------------------------------
1 | #ifndef EXAMPLE_H
2 | #define EXAMPLE_H
3 |
4 | class Example
5 | {
6 | public:
7 | int foo();
8 |
9 | };
10 |
11 |
12 | #endif //EXAMPLEPROJECT_FORMULA_H
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CMakeDetermineCompilerABI_CXX.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PhysicsX/ExampleCode/HEAD/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CMakeDetermineCompilerABI_CXX.bin
--------------------------------------------------------------------------------
/LinkTimeSubstitution/include/Data.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class Data {
4 | public:
5 | virtual int call();
6 | virtual ~Data() = default; // Add a virtual destructor for good measure
7 |
8 | };
9 |
--------------------------------------------------------------------------------
/sharedCallbackExample/exampleBInt.h:
--------------------------------------------------------------------------------
1 | #ifndef _EXAMPLEBINT_H_
2 | #define _EXAMPLEBINT_H_
3 |
4 | class interfaceB
5 | {
6 | public:
7 | virtual void fooB() = 0;
8 | };
9 |
10 | #endif
--------------------------------------------------------------------------------
/cmakeExample/lib/include/lib/lib.h:
--------------------------------------------------------------------------------
1 | #ifndef LIB_H
2 | #define LIB_H
3 |
4 | #include
5 |
6 | class lib{
7 |
8 | public:
9 | void foo();
10 | };
11 |
12 |
13 | #endif //#ifndef LIB_H
--------------------------------------------------------------------------------
/CmakeExample2/src/Formula.h:
--------------------------------------------------------------------------------
1 | #ifndef EXAMPLEPROJECT_FORMULA_H
2 | #define EXAMPLEPROJECT_FORMULA_H
3 |
4 | class Formula {
5 | public:
6 | static int bla(int arg1);
7 | };
8 |
9 | #endif //EXAMPLEPROJECT_FORMULA_H
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/depend.make:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.13
3 |
4 | CMakeFiles/server.dir/server.cpp.o: ../server.cpp
5 |
6 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/link.txt:
--------------------------------------------------------------------------------
1 | /usr/bin/c++ -rdynamic CMakeFiles/server.dir/server.cpp.o -o server -lboost_system -lboost_thread -lpthread -lboost_chrono -lboost_date_time -lboost_atomic -lpthread
2 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/depend.internal:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.13
3 |
4 | CMakeFiles/server.dir/server.cpp.o
5 | /home/pi/ExampleCode/Cpp/asioTcpServer/server.cpp
6 |
--------------------------------------------------------------------------------
/CmakeExample2/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(BINARY ${CMAKE_PROJECT_NAME})
2 |
3 | file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
4 |
5 | set(SOURCES ${SOURCES})
6 |
7 | add_executable(${BINARY}_run ${SOURCES})
8 |
9 | add_library(${BINARY}_lib STATIC ${SOURCES})
--------------------------------------------------------------------------------
/cmakeExample/lib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(lib SHARED src/lib.cpp)
2 |
3 | message("${CMAKE_CURRENT_SOURCE_DIR} is the current source")
4 | set(CMAKE_SHARED_LIBRARY_PREFIX "s") # change prefix
5 |
6 | target_include_directories(lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/TargetDirectories.txt:
--------------------------------------------------------------------------------
1 | /home/pi/ExampleCode/Cpp/asioTcpServer/build/CMakeFiles/rebuild_cache.dir
2 | /home/pi/ExampleCode/Cpp/asioTcpServer/build/CMakeFiles/server.dir
3 | /home/pi/ExampleCode/Cpp/asioTcpServer/build/CMakeFiles/edit_cache.dir
4 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/flags.make:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.13
3 |
4 | # compile CXX with /usr/bin/c++
5 | CXX_FLAGS =
6 |
7 | CXX_DEFINES =
8 |
9 | CXX_INCLUDES =
10 |
11 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/Editor/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication app(argc, argv);
7 | MainWindow window;
8 | window.setWindowTitle("Viewer");
9 | window.show();
10 | return app.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/Viewer/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mainwindow.h"
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication app(argc, argv);
7 | MainWindow window;
8 | window.setWindowTitle("Viewer");
9 | window.show();
10 | return app.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/sharedCallbackExample/exampleB.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "exampleB.h"
4 | #include "exampleA.h"
5 |
6 |
7 | B::B(std::shared_ptr Aptr)
8 | {
9 | std::cout<<"B const"<Acallback();
11 | }
12 |
13 | void B::fooB()
14 | {
15 |
16 | }
--------------------------------------------------------------------------------
/CmakeExample2/tst/Formula-test.cpp:
--------------------------------------------------------------------------------
1 | #include "gtest/gtest.h"
2 | #include "Formula.h"
3 |
4 | TEST(blaTest, test1) {
5 | //arrange
6 | //act
7 | //assert
8 | EXPECT_EQ (Formula::bla (0), 0);
9 | EXPECT_EQ (Formula::bla (10), 20);
10 | EXPECT_EQ (Formula::bla (50), 100);
11 | }
--------------------------------------------------------------------------------
/LinkTimeSubstitution/MockData.cpp:
--------------------------------------------------------------------------------
1 | #include "Data.h"
2 | #include "MockData.h"
3 | #include
4 |
5 | MockData::Ptr global_mock_data_ptr = std::make_shared();
6 |
7 | #include
8 | int Data::call() {
9 | std::cout<<__LINE__<call();
11 | }
12 |
--------------------------------------------------------------------------------
/LinkTimeSubstitution/include/MockData.h:
--------------------------------------------------------------------------------
1 | #include "Data.h"
2 | #include
3 |
4 |
5 | class MockData {
6 | public:
7 | MOCK_METHOD(int, call, ());
8 | using Ptr = std::shared_ptr;
9 | };
10 |
11 | // Declare the global pointer to MockData
12 | extern MockData::Ptr global_mock_data_ptr;
13 |
--------------------------------------------------------------------------------
/gtestExample/example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | class Example{
6 |
7 | public:
8 |
9 | int ctr = 0;
10 |
11 | void increase(int value)
12 | {
13 | ctr += value;
14 | }
15 |
16 | void decrease(int value)
17 | {
18 | ctr -= value;
19 | }
20 | };
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/cmake_clean.cmake:
--------------------------------------------------------------------------------
1 | file(REMOVE_RECURSE
2 | "CMakeFiles/server.dir/server.cpp.o"
3 | "server.pdb"
4 | "server"
5 | )
6 |
7 | # Per-language clean rules from dependency scanning.
8 | foreach(lang CXX)
9 | include(CMakeFiles/server.dir/cmake_clean_${lang}.cmake OPTIONAL)
10 | endforeach()
11 |
--------------------------------------------------------------------------------
/sharedCallbackExample/main.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include "exampleA.h"
6 |
7 | //g++ -std=c++17 main.cpp exampleA.cpp exampleB.cpp -lpthread
8 |
9 | int main()
10 | {
11 | std::shared_ptr Aptr { std::make_shared() };
12 | Aptr->foo();
13 |
14 | while(1);
15 | }
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 | project(server)
3 |
4 |
5 | find_package(Boost REQUIRED COMPONENTS system thread)
6 |
7 | if(Boost_FOUND)
8 | include_directories(${Boost_INCLUDE_DIR})
9 | add_executable(server server.cpp)
10 | target_link_libraries(server ${Boost_LIBRARIES} pthread)
11 | endif()
12 |
--------------------------------------------------------------------------------
/Py/InteractWithBinance.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import requests
3 | import pprint
4 |
5 | logger = logging.getLogger()
6 |
7 | def get_contracts():
8 | response_object = requests.get("https://fapi.binance.com/fapi/v1/exchangeInfo")
9 | print(response_object.status_code)
10 | pprint.pprint(response_object.json())
11 |
12 | get_contracts()
--------------------------------------------------------------------------------
/googleTest/src/foo.cpp:
--------------------------------------------------------------------------------
1 | #include "foo.hpp"
2 |
3 | int foo::fooInt(std::string& str)
4 | {
5 | return str.size();
6 | }
7 |
8 | void foo::fooStr(std::string& str)
9 | {
10 | str = "ExampleStr";
11 | }
12 |
13 | void foo::fooThrow()
14 | {
15 | // throw runtime error
16 | }
17 |
18 | void foo::callbackMethod(std::function& callback)
19 | {
20 | callback();
21 | }
--------------------------------------------------------------------------------
/googleTest/include/foo.hpp:
--------------------------------------------------------------------------------
1 | #ifndef FOO_HPP
2 | #define FOO_HPP
3 |
4 | #include "foo_if.hpp"
5 | #include
6 | #include
7 |
8 | class foo : public fooIf
9 | {
10 | public:
11 | int fooInt(std::string& str);
12 | void fooStr(std::string& str);
13 | void fooThrow();
14 | void callbackMethod(std::function& callback);
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/googleTest/include/foo_if.hpp:
--------------------------------------------------------------------------------
1 | #ifndef FOO_IF_HPP
2 | #define FOO_IF_HPP
3 | #include
4 | #include
5 |
6 | class fooIf
7 | {
8 | public:
9 | virtual int fooInt(std::string& str) = 0;
10 | virtual void fooStr(std::string& str) = 0;
11 | virtual void fooThrow() = 0;
12 | virtual void callbackMethod(std::function& callback) = 0;
13 | };
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/Cpp/reverserInt.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int reverseInteger(int n)
4 | {
5 | int reversed {0};
6 |
7 | while(n)
8 | {
9 | int reminder = n%10;
10 |
11 | reversed = reversed * 10 + reminder;
12 | n /= 10;
13 | }
14 |
15 | return reversed;
16 | }
17 |
18 |
19 | int main()
20 | {
21 | int n = 12345;
22 | std::cout<
4 | #include
5 | #include "foo_if.hpp"
6 |
7 | class dummy
8 | {
9 | public:
10 | dummy(fooIf& f):mfoo(f){}
11 | int dummyInt(std::string& str);
12 | void dummyStr(std::string& str);
13 | void dummyThrow();
14 | void dummyCallback(std::function callback);
15 |
16 | fooIf& mfoo;
17 | };
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/sharedCallbackExample/exampleB.h:
--------------------------------------------------------------------------------
1 | #ifndef _EXAMPLEB_H_
2 | #define _EXAMPLEB_H_
3 |
4 | #include
5 | #include
6 | #include "exampleBInt.h"
7 | #include "exampleA.h"
8 |
9 | class B : public interfaceB, public std::enable_shared_from_this
10 | {
11 | public:
12 | B(std::shared_ptr Aptr);
13 | void fooB() override;
14 |
15 | std::shared_ptr mAptr;
16 |
17 | };
18 |
19 | #endif
--------------------------------------------------------------------------------
/googleTest/include/mock_foo.hpp:
--------------------------------------------------------------------------------
1 | #include "foo_if.hpp"
2 | #include
3 | #include
4 |
5 | class mockFoo : public fooIf
6 | {
7 | public:
8 | MOCK_METHOD(int, fooInt, (std::string& str), (override));
9 | MOCK_METHOD(void, fooStr, (std::string& str), (override));
10 | MOCK_METHOD(void, fooThrow, (), (override));
11 | MOCK_METHOD(void, callbackMethod, (std::function&),(override));
12 |
13 | };
14 |
--------------------------------------------------------------------------------
/Cpp/nonDerived.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //without final keyword inheritance
4 |
5 | class A
6 | {
7 |
8 |
9 | private:
10 | A(){};
11 | friend class B;
12 |
13 | };
14 |
15 | class B : virtual public A
16 | {
17 |
18 |
19 | };
20 |
21 | class C : public B
22 | {
23 |
24 |
25 | };
26 |
27 | int main()
28 | {
29 |
30 | C c;
31 |
32 | return 0;
33 |
34 | }
--------------------------------------------------------------------------------
/googleTest/src/dummy.cpp:
--------------------------------------------------------------------------------
1 | #include "dummy.hpp"
2 |
3 | int dummy::dummyInt(std::string& str)
4 | {
5 | return mfoo.fooInt(str);
6 | }
7 |
8 | void dummy::dummyStr(std::string& str)
9 | {
10 | mfoo.fooStr(str);
11 | //str = "ExampleStr";
12 | }
13 |
14 | void dummy::dummyThrow()
15 | {
16 | mfoo.fooThrow();
17 | }
18 |
19 | void dummy::dummyCallback(std::function callback){
20 | mfoo.callbackMethod(callback);
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/CmakeExample2/tst/Example-text.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Example.h"
3 |
4 |
5 | class TestBase : public ::testing::Test
6 | {
7 | public:
8 | TestBase(void);
9 | virtual ~TestBase(void);
10 | static void SetUpTestCase();
11 | static void TearDownTestCase();
12 | virtual void SetUp(void);
13 | virtual void TearDown(void);
14 |
15 | public:
16 | static int mArgc;
17 | static char** mArgs;
18 |
19 | static Example* pSC;
20 |
21 | };
--------------------------------------------------------------------------------
/CmakeExample2/tst/include/Example-text.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Example.h"
3 |
4 |
5 | class TestBase : public ::testing::Test
6 | {
7 | public:
8 | TestBase(void);
9 | virtual ~TestBase(void);
10 | static void SetUpTestCase();
11 | static void TearDownTestCase();
12 | virtual void SetUp(void);
13 | virtual void TearDown(void);
14 |
15 | public:
16 | static int mArgc;
17 | static char** mArgs;
18 |
19 | static Example* pSC;
20 |
21 | };
--------------------------------------------------------------------------------
/Cpp/findSubstringInString.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | int main()
5 | {
6 | std::string str = "hello world";
7 | std::string str2 = "l";
8 |
9 | std::size_t pos = str.find(str2);
10 |
11 | while(pos != std::string::npos)
12 | {
13 | std::cout<<"found"<
5 | #include
6 | #include "exampleAInt.h"
7 | #include "exampleBInt.h"
8 |
9 | class A : public std::enable_shared_from_this, public interfaceA
10 | {
11 | public:
12 | A();
13 |
14 | void foo() ;
15 |
16 | void Acallback();
17 |
18 | std::shared_ptr Bptr;
19 |
20 | };
21 |
22 | #endif
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/CXX.includecache:
--------------------------------------------------------------------------------
1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">])
2 |
3 | #IncludeRegexScan: ^.*$
4 |
5 | #IncludeRegexComplain: ^$
6 |
7 | #IncludeRegexTransform:
8 |
9 | /home/pi/ExampleCode/Cpp/asioTcpServer/server.cpp
10 | iostream
11 | -
12 | boost/asio.hpp
13 | -
14 | boost/beast/core.hpp
15 | -
16 | boost/beast/websocket.hpp
17 | -
18 | boost/asio/dispatch.hpp
19 | -
20 | boost/asio/strand.hpp
21 | -
22 |
23 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/QtOpencvQml/qmlType.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 |
11 | class qmlType : public QQuickPaintedItem
12 | {
13 | Q_OBJECT
14 | public:
15 |
16 | qmlType(QQuickItem *parent = nullptr);
17 | void paint(QPainter *painter) override;
18 |
19 | void updateImage(const QImage& img);
20 |
21 | QImage *image;
22 | };
23 |
24 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/3.13.4/CMakeSystem.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_HOST_SYSTEM "Linux-4.19.118-v7l+")
2 | set(CMAKE_HOST_SYSTEM_NAME "Linux")
3 | set(CMAKE_HOST_SYSTEM_VERSION "4.19.118-v7l+")
4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "armv7l")
5 |
6 |
7 |
8 | set(CMAKE_SYSTEM "Linux-4.19.118-v7l+")
9 | set(CMAKE_SYSTEM_NAME "Linux")
10 | set(CMAKE_SYSTEM_VERSION "4.19.118-v7l+")
11 | set(CMAKE_SYSTEM_PROCESSOR "armv7l")
12 |
13 | set(CMAKE_CROSSCOMPILING "FALSE")
14 |
15 | set(CMAKE_SYSTEM_LOADED 1)
16 |
--------------------------------------------------------------------------------
/CmakeExample2/tst/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(BINARY ${CMAKE_PROJECT_NAME}_tst)
2 |
3 | file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false ../src/Formula.cpp ../src/Example.cpp *.cpp)
4 |
5 | set(SOURCES ${TEST_SOURCES})
6 | set(THREADS_PREFER_PTHREAD_FLAG ON)
7 | find_package(Threads REQUIRED)
8 |
9 | include_directories(../src include)
10 |
11 | add_executable(${BINARY} ${TEST_SOURCES})
12 |
13 | add_test(NAME ${BINARY} COMMAND ${BINARY})
14 |
15 | target_link_libraries(${BINARY} PUBLIC Threads::Threads gtest)
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/QtOpencvQml/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.12
2 | import QtQuick.Window 2.12
3 | import QtQuick.Controls 2.0
4 | import Painter 1.0
5 |
6 | Window {
7 | width: Screen.width
8 | height: Screen.height
9 | visible: true
10 | title: qsTr("OpencvToQml")
11 |
12 |
13 | QmlType {
14 | objectName: "inputCamera"
15 | id: inputView
16 | //streamerThreadSlot: VideoStreamer
17 | width: parent.width
18 | height: parent.height
19 |
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/Cpp/socketExample/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "myserver.h"
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QCoreApplication a(argc, argv);
7 |
8 | // Create an instance of a server and then start it.
9 | MyServer server;
10 | server.startServer();
11 |
12 | return a.exec();
13 | }
14 |
15 | // while true; do echo "ulas" | netcat localhost 1234 -w 1; sleep 0.1; done;
16 | // echo "ulas" | netcat localhost 1234 -w 1
17 |
18 | // stress test
19 | // while true; do echo "ulas" | netcat localhost 1234 & disown; done;
20 |
21 |
--------------------------------------------------------------------------------
/Py/ex.py:
--------------------------------------------------------------------------------
1 | #connect to camera and record it
2 |
3 | import cv2
4 | cap = cv2.VideoCapture(0)
5 |
6 | width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
7 | height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
8 |
9 | output = cv2.VideoWriter('myVideo.mkv', cv2.VideoWriter_fourcc(*'XVID'),20,(width, height))
10 |
11 | while True:
12 | ret, frame = cap.read()
13 |
14 | output.write(frame)
15 |
16 | cv2.imshow('frame', frame)
17 | if cv2.waitKey(5) & 0xFF == 27:
18 | break
19 |
20 |
21 | cap.release()
22 | output.release()
23 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/Py/pythonGstreamer.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | print(cv2.__version__)
3 |
4 |
5 | # Cam properties
6 | fps = 30.
7 | frame_width = 1920
8 | frame_height = 1080
9 |
10 |
11 |
12 | dispW=640
13 | dispH=480
14 | flip=2
15 | #Uncomment These next Two Line for Pi Camera
16 | camSet = ('videotestsrc ! videoconvert ! appsink')
17 |
18 | cam= cv2.VideoCapture(camSet)
19 |
20 |
21 |
22 | while True:
23 | ret, frame = cam.read()
24 | cv2.imshow('nanoCam',frame)
25 | if cv2.waitKey(1)==ord('q'):
26 | break
27 | cam.release()
28 | cv2.destroyAllWindows()
29 |
--------------------------------------------------------------------------------
/Py/recordVideo.py:
--------------------------------------------------------------------------------
1 | #connect to camera and record it
2 |
3 | import cv2
4 | cap = cv2.VideoCapture(0)
5 |
6 | width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
7 | height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
8 |
9 | output = cv2.VideoWriter('myVideo.mkv', cv2.VideoWriter_fourcc(*'XVID'),20,(width, height))
10 |
11 | while True:
12 | ret, frame = cap.read()
13 |
14 | output.write(frame)
15 |
16 | cv2.imshow('frame', frame)
17 | if cv2.waitKey(5) & 0xFF == 27:
18 | break
19 |
20 |
21 | cap.release()
22 | output.release()
23 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/Py/gstreamerPython.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | print(cv2.__version__)
3 |
4 |
5 | # Cam properties
6 | fps = 30.
7 | frame_width = 1920
8 | frame_height = 1080
9 |
10 |
11 |
12 | dispW=640
13 | dispH=480
14 | flip=2
15 | #Uncomment These next Two Line for Pi Camera
16 | camSet = ('videotestsrc ! videoconvert ! appsink')
17 |
18 | cam= cv2.VideoCapture(camSet)
19 |
20 |
21 |
22 | while True:
23 | ret, frame = cam.read()
24 | cv2.imshow('nanoCam',frame)
25 | if cv2.waitKey(1)==ord('q'):
26 | break
27 | cam.release()
28 | cv2.destroyAllWindows()
29 |
30 |
--------------------------------------------------------------------------------
/googleTest/test.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 |
3 | class fooIf<>
4 | {
5 | + {abstract} fooStr(std::string&): void
6 | }
7 |
8 | class foo
9 | {
10 | + fooStr(std::string&): void
11 | }
12 |
13 | class mockFoo
14 | {
15 | + fooStr(std::string&): void
16 | }
17 |
18 | class dummy
19 | {
20 | + dummy(fooIf&)
21 | # fooIf foo
22 | }
23 |
24 | class test
25 | {
26 | # mockFoo fooMock
27 | # unique_ptr testDummy
28 | }
29 |
30 |
31 |
32 | fooIf <|.. foo
33 | fooIf <|.. mockFoo
34 | dummy -right-> fooIf
35 |
36 | test *-- dummy
37 | test *-- mockFoo
38 |
39 | @enduml
40 |
--------------------------------------------------------------------------------
/Py/drawSingleRect.py:
--------------------------------------------------------------------------------
1 | import cv2
2 |
3 | cap = cv2.VideoCapture(0)
4 |
5 | width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
6 | height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
7 |
8 | x = width // 2
9 | y = height // 2
10 |
11 | w = width // 4
12 | h = height // 4
13 |
14 | while True:
15 | ret, frame = cap.read()
16 |
17 | cv2.rectangle(frame, (x,y), (x+w, y+h), color=(255,0,255), thickness=5)
18 |
19 | cv2.imshow('frame', frame)
20 |
21 | if cv2.waitKey(3) & 0xFF == 27:
22 | break
23 |
24 |
25 | cap.release()
26 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/Cpp/firstNonRepeatingChar.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | char firstNonRepeatingChar(const std::string& str)
6 | {
7 | std::unordered_map map;
8 |
9 | for(const auto& c : str)
10 | {
11 | map[c] ++;
12 | }
13 |
14 | for(const auto& c : str)
15 | {
16 | if(map[c] == 1)
17 | {
18 | return c;
19 | }
20 | }
21 |
22 | return '\0';
23 | }
24 |
25 | int main()
26 | {
27 | std::string s = "helloFromGithub";
28 | std::cout<fill(QColor("yellow"));
7 |
8 | // If camera is open here, it is not possible to send the frames.
9 | // need another thread to send the frames over this class
10 | }
11 |
12 | void qmlType::paint(QPainter *painter) {
13 | painter->drawImage(this->boundingRect(), *image);
14 | }
15 |
16 | void qmlType::updateImage(const QImage& img)
17 | {
18 | *image = img;
19 | update();
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/LinkTimeSubstitution/example_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "example.cpp"
4 | #include "MockData.h"
5 |
6 | extern std::shared_ptr global_mock_data_ptr;
7 |
8 | class testFixture : public testing::Test
9 | {
10 | public:
11 | testFixture()
12 | {
13 | }
14 | ~testFixture()
15 | {
16 | global_mock_data_ptr.reset(); // delete the global mock
17 | }
18 | };
19 |
20 |
21 | TEST_F(testFixture, FooReturnsMockedValue) {
22 |
23 | EXPECT_CALL(*global_mock_data_ptr, call()).WillOnce(::testing::Return(99));
24 |
25 | Example ex;
26 | ASSERT_EQ(99, ex.foo());
27 | }
28 |
--------------------------------------------------------------------------------
/LinkTimeSubstitution/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | set(CMAKE_CXX_STANDARD 14)
3 |
4 | project(ExampleGtest LANGUAGES CXX)
5 |
6 | include(FetchContent)
7 | FetchContent_Declare(
8 | googletest
9 | GIT_REPOSITORY https://github.com/google/googletest.git
10 | GIT_TAG bf66935e07825318ae519675d73d0f3e313b3ec6
11 | )
12 | FetchContent_MakeAvailable(googletest)
13 |
14 | add_executable(${PROJECT_NAME} example_test.cpp MockData.cpp)
15 |
16 | target_link_libraries(${PROJECT_NAME} gtest_main gmock_main)
17 |
18 | include(GoogleTest)
19 | gtest_discover_tests(${PROJECT_NAME})
20 |
21 | #include headers
22 | include_directories(include)
--------------------------------------------------------------------------------
/Cpp/findMinReturnType.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | using namespace std;
5 |
6 | template
7 | auto findMin(A a, B b) -> decltype( (a < b) ? a: b) // decltype is not necessary for c++14
8 | {
9 | return (a < b) ? a : b;
10 | }
11 |
12 | auto foo(int a, double b)
13 | {
14 | return (a < b) ? a : b;
15 | }
16 |
17 | int main()
18 | {
19 |
20 | std::cout<::value<::value<
2 |
3 | auto allocated = size_t{0};
4 | // Overload operator new and delete to track allocations
5 | auto operator new(size_t size) -> void* {
6 | void* p = std::malloc(size);
7 | allocated += size;
8 | return p;
9 | }
10 |
11 | auto operator delete(void* p) noexcept -> void {
12 | return std::free(p);
13 | }
14 |
15 | auto main() -> int {
16 | allocated = 0;
17 | auto s = std::string{"12345678901234567890123"};
18 | //auto s = std::string{"1234"};
19 |
20 | std::cout << "stack space = " << sizeof(s)
21 | << ", heap space = " << allocated
22 | << ", capacity = " << s.capacity() << '\n';
23 | }
--------------------------------------------------------------------------------
/Cpp/reverseWordsInSentence.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | std::string reverseWords(std::string str)
6 | {
7 | std::stringstream ss(str);
8 | std::string word;
9 |
10 | std::deque words;
11 |
12 | while(ss>>word)
13 | {
14 | words.push_front(word);
15 | }
16 |
17 | std::string result;
18 | while(!words.empty())
19 | {
20 | result += words.front() + " ";
21 | words.pop_front();
22 | }
23 |
24 | result.pop_back();
25 |
26 | return result;
27 | }
28 |
29 | int main()
30 | {
31 | std::string str = "Electric cars are cool";
32 | std::cout<
2 | #include
3 |
4 | // sudo apt install libopencv-dev
5 | // g++ openCVExample.cpp `pkg-config --libs --cflags opencv4` -o example
6 | // g++ openCVExample.cpp $(pkg-config --libs --cflags opencv4) -o example
7 |
8 | using namespace cv;
9 | using namespace std;
10 |
11 | int main()
12 | {
13 | std::cout<<"Example"<
7 | #include
8 | #include
9 | #include
10 |
11 | #include "myclient.h"
12 |
13 | class MyServer : public QTcpServer
14 | {
15 | // Q_OBJECT is the base class for all qt libraries
16 | Q_OBJECT
17 | QThreadPool *pool; // this can be used also global isntead of dependency injection
18 | public:
19 | explicit MyServer(QObject *parent = 0);
20 | void startServer();
21 |
22 | protected:
23 | void incomingConnection(qintptr socketDescriptor);
24 |
25 | signals:
26 |
27 | public slots:
28 |
29 | };
30 |
31 | #endif // MYSERVER_H
32 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/server.dir/DependInfo.cmake:
--------------------------------------------------------------------------------
1 | # The set of languages for which implicit dependencies are needed:
2 | set(CMAKE_DEPENDS_LANGUAGES
3 | "CXX"
4 | )
5 | # The set of files for implicit dependencies of each language:
6 | set(CMAKE_DEPENDS_CHECK_CXX
7 | "/home/pi/ExampleCode/Cpp/asioTcpServer/server.cpp" "/home/pi/ExampleCode/Cpp/asioTcpServer/build/CMakeFiles/server.dir/server.cpp.o"
8 | )
9 | set(CMAKE_CXX_COMPILER_ID "GNU")
10 |
11 | # The include file search paths:
12 | set(CMAKE_CXX_TARGET_INCLUDE_PATH
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 |
--------------------------------------------------------------------------------
/Cpp/maxSubArray.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | class Solution {
7 | public:
8 | int maxSubArray(std::vector& nums) {
9 |
10 | int largestSum = nums[0]; //SHRT_MIN;
11 | int sum = nums[0]; //SHRT_MIN;
12 |
13 | for(int i=0; i vec {-2,1,-3,4,-1,2,1,-5,4};
29 |
30 | std::cout<setMaxThreadCount(5);
10 |
11 | }
12 |
13 | void MyServer::startServer()
14 | {
15 | if(listen(QHostAddress::Any, 1234))
16 | {
17 | qDebug() << "Server: started";
18 | }
19 | else
20 | {
21 | qDebug() << "Server: not started!";
22 | }
23 | }
24 |
25 | void MyServer::incomingConnection(qintptr socketDescriptor)
26 | {
27 | // At the incoming connection, make a client
28 | // and set the socket
29 | MyClient *client = new MyClient(this, pool);
30 | client->setSocket(socketDescriptor);
31 | }
32 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/CMakeDirectoryInformation.cmake:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.13
3 |
4 | # Relative path conversion top directories.
5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/pi/ExampleCode/Cpp/asioTcpServer")
6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/pi/ExampleCode/Cpp/asioTcpServer/build")
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 |
--------------------------------------------------------------------------------
/Cpp/minMove3Consecutive.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | class Solution
5 | {
6 | public:
7 | int minMoves(const std::string& str)
8 | {
9 | int res{0};
10 | size_t size = str.size();
11 |
12 | for(size_t i = 0; i < size;)
13 | {
14 | int next = i + 1;
15 |
16 | while( (next < size) && (str[i] == str[next])) {next ++;}
17 | // next - i is the length of the sequence
18 | // Each third letter should be changed to remove
19 | // too long sequenes
20 | res += (next-i)/3;
21 | i = next;
22 | }
23 |
24 | return res;
25 | }
26 | };
27 |
28 | int main()
29 | {
30 | std::cout<
7 | #include
8 | #include
9 | #include
10 | #include "mytask.h"
11 |
12 | class MyClient : public QObject
13 | {
14 | QThreadPool *pool;
15 | Q_OBJECT
16 | public:
17 | explicit MyClient(QObject *parent = 0, QThreadPool *pool = 0);
18 | void setSocket(qintptr Descriptor);
19 |
20 | signals:
21 |
22 | public slots:
23 | void connected();
24 | void disconnected();
25 | void readyRead();
26 |
27 | // make the server fully ascynchronous
28 | // by doing time consuming task
29 | void TaskResult(int Number);
30 |
31 | private:
32 | QTcpSocket *socket;
33 |
34 | };
35 |
36 | #endif // MYCLIENT_H
37 |
--------------------------------------------------------------------------------
/Cpp/socketExample/mytask.h:
--------------------------------------------------------------------------------
1 | // mytask.h
2 |
3 | #ifndef MYTASK_H
4 | #define MYTASK_H
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // Q_OBJECT missing in the original file generated by class wizard.
11 | // because we set this class with base class QRunnable
12 | // with no inheritance in the class wizard
13 | // We do not have this. So, we cannot use signal/slot
14 | // But we need them.
15 | // Thus, we should use multiple inheritance: QObject inserted here
16 |
17 | class MyTask : public QObject, public QRunnable
18 | {
19 | Q_OBJECT
20 | public:
21 | MyTask();
22 |
23 | signals:
24 | // notify to the main thread when we're done
25 | void Result(int Number);
26 |
27 | protected:
28 | void run();
29 | };
30 |
31 | #endif // MYTASK_H
32 |
--------------------------------------------------------------------------------
/Cpp/majorityElementII.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | class Solution {
6 | public:
7 | std::vector majorityElement(std::vector& nums) {
8 | std::unordered_map map;
9 | for(auto num : nums)
10 | {
11 | map[num] ++;
12 | }
13 |
14 | std::vector result;
15 | result.reserve(map.size());
16 | for(const std::pair& p : map)
17 | {
18 | if(p.second > nums.size()/3)
19 | result.push_back(p.first);
20 | }
21 | return result;
22 | }
23 | };
24 |
25 | int main()
26 | {
27 | std::vector vec {3,2,3};
28 |
29 | for(auto v : Solution{}.majorityElement(vec))
30 | std::cout<
2 | #include
3 |
4 | using namespace std;
5 |
6 | class example
7 | {
8 | public:
9 | int foo()
10 | {
11 | return 1;
12 | }
13 |
14 | };
15 |
16 | class exampleFixture : public testing::Test
17 | {
18 | public:
19 | exampleFixture(){
20 | testExPtr = new example();
21 | }
22 | ~exampleFixture()
23 | {
24 | delete testExPtr;
25 | }
26 |
27 | void SetUp(){}
28 | void TearDown(){}
29 |
30 | example* testExPtr;
31 | };
32 |
33 | TEST_F(exampleFixture, test1)
34 | {
35 | ASSERT_EQ(1,testExPtr->foo());
36 | }
37 |
38 | TEST_F(exampleFixture, test2)
39 | {
40 | ASSERT_NE(0,testExPtr->foo());
41 | }
42 |
43 | int main(int argc, char **argv)
44 | {
45 | testing::InitGoogleTest(&argc, argv);
46 | return RUN_ALL_TESTS();
47 | }
48 |
--------------------------------------------------------------------------------
/Cpp/conversionOperator.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //how to use conversion operator
5 | class smart;
6 | class dummy
7 | {
8 | dummy()=default;
9 | public:
10 | friend class smart;
11 | };
12 |
13 | class smart
14 | {
15 | public:
16 | dummy d;
17 |
18 | // conversion operator overloading
19 | operator dummy()
20 | {
21 | return d;
22 | }
23 | };
24 |
25 | int main()
26 | {
27 |
28 | // possible usages
29 | // each line call the operator dummy() method
30 | dummy d = smart();
31 |
32 | smart s2;
33 | dummy d2 = s2;
34 |
35 | dummy d3 = smart().operator dummy();
36 |
37 | smart s3;
38 | dummy d5 = s3.operator dummy();
39 |
40 | auto s4 = smart();
41 |
42 | }
--------------------------------------------------------------------------------
/CmakeExample2/tst/Example-text.cpp:
--------------------------------------------------------------------------------
1 | #include "Example-text.h"
2 |
3 | int TestBase::mArgc = 0;
4 | char** TestBase::mArgs = NULL;
5 |
6 | Example* TestBase::pSC = NULL;
7 |
8 | TestBase::TestBase(void)
9 | {
10 |
11 | }
12 |
13 | TestBase::~TestBase(void)
14 | {
15 |
16 | }
17 |
18 | void TestBase::SetUpTestCase()
19 | {
20 | std::cout << "Set up test cases." << std::endl;
21 |
22 | if ( pSC != NULL )
23 | {
24 | delete pSC;
25 | }
26 |
27 | pSC = new Example;
28 | }
29 |
30 | void TestBase::TearDownTestCase()
31 | {
32 | std::cout << "Tear down test cases." << std::endl;
33 |
34 | delete pSC; pSC = NULL;
35 | }
36 |
37 | void TestBase::SetUp(void)
38 | {
39 |
40 | }
41 |
42 | void TestBase::TearDown(void)
43 | {
44 |
45 | }
46 |
47 | TEST_F(TestBase, tmp)
48 | {
49 | Example a;
50 | int tmp = pSC->foo();
51 | EXPECT_EQ(tmp,1);
52 | }
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/Viewer/.qmake.stash:
--------------------------------------------------------------------------------
1 | QMAKE_CXX.INCDIRS = \
2 | /usr/include/c++/7 \
3 | /usr/include/aarch64-linux-gnu/c++/7 \
4 | /usr/include/c++/7/backward \
5 | /usr/lib/gcc/aarch64-linux-gnu/7/include \
6 | /usr/local/include \
7 | /usr/lib/gcc/aarch64-linux-gnu/7/include-fixed \
8 | /usr/include/aarch64-linux-gnu \
9 | /usr/include
10 | QMAKE_CXX.LIBDIRS = \
11 | /usr/lib/gcc/aarch64-linux-gnu/7 \
12 | /usr/lib/aarch64-linux-gnu \
13 | /usr/lib \
14 | /lib/aarch64-linux-gnu \
15 | /lib
16 | QMAKE_CXX.QT_COMPILER_STDCXX = 201402L
17 | QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 7
18 | QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 5
19 | QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
20 | QMAKE_CXX.COMPILER_MACROS = \
21 | QT_COMPILER_STDCXX \
22 | QMAKE_GCC_MAJOR_VERSION \
23 | QMAKE_GCC_MINOR_VERSION \
24 | QMAKE_GCC_PATCH_VERSION
25 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/QtOpencvQml/.qmake.stash:
--------------------------------------------------------------------------------
1 | QMAKE_CXX.QT_COMPILER_STDCXX = 201402L
2 | QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 7
3 | QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 5
4 | QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
5 | QMAKE_CXX.COMPILER_MACROS = \
6 | QT_COMPILER_STDCXX \
7 | QMAKE_GCC_MAJOR_VERSION \
8 | QMAKE_GCC_MINOR_VERSION \
9 | QMAKE_GCC_PATCH_VERSION
10 | QMAKE_CXX.INCDIRS = \
11 | /usr/include/c++/7 \
12 | /usr/include/aarch64-linux-gnu/c++/7 \
13 | /usr/include/c++/7/backward \
14 | /usr/lib/gcc/aarch64-linux-gnu/7/include \
15 | /usr/local/include \
16 | /usr/lib/gcc/aarch64-linux-gnu/7/include-fixed \
17 | /usr/include/aarch64-linux-gnu \
18 | /usr/include
19 | QMAKE_CXX.LIBDIRS = \
20 | /usr/lib/gcc/aarch64-linux-gnu/7 \
21 | /usr/lib/aarch64-linux-gnu \
22 | /usr/lib \
23 | /lib/aarch64-linux-gnu \
24 | /lib
25 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/staticTest/staticTest.pro:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Automatically generated by qmake (3.1) Mon Nov 7 14:39:27 2022
3 | ######################################################################
4 |
5 | TEMPLATE = app
6 | TARGET = staticTest
7 | INCLUDEPATH += .
8 | LIBS += -L/home/ulas/staticTest -lmy_math
9 | # You can make your code fail to compile if you use deprecated APIs.
10 | # In order to do so, uncomment the following line.
11 | # Please consult the documentation of the deprecated API in order to know
12 | # how to port your code away from it.
13 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
14 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
15 |
16 | # Input
17 | # HEADERS += my_math.h
18 | SOURCES += main.cpp
19 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/build/CMakeFiles/feature_tests.c:
--------------------------------------------------------------------------------
1 |
2 | const char features[] = {"\n"
3 | "C_FEATURE:"
4 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 304
5 | "1"
6 | #else
7 | "0"
8 | #endif
9 | "c_function_prototypes\n"
10 | "C_FEATURE:"
11 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 304 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
12 | "1"
13 | #else
14 | "0"
15 | #endif
16 | "c_restrict\n"
17 | "C_FEATURE:"
18 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L
19 | "1"
20 | #else
21 | "0"
22 | #endif
23 | "c_static_assert\n"
24 | "C_FEATURE:"
25 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 304 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
26 | "1"
27 | #else
28 | "0"
29 | #endif
30 | "c_variadic_macros\n"
31 |
32 | };
33 |
34 | int main(int argc, char** argv) { (void)argv; return features[argc]; }
35 |
--------------------------------------------------------------------------------
/protoExamples/example.proto:
--------------------------------------------------------------------------------
1 | // See README.txt for information and build instructions.
2 | //
3 | // Note: START and END tags are used in comments to define sections used in
4 | // tutorials. They are not part of the syntax for Protocol Buffers.
5 | //
6 | // To get an in-depth walkthrough of this file and the related examples, see:
7 | // https://developers.google.com/protocol-buffers/docs/tutorials
8 |
9 | // [START declaration]
10 | syntax = "proto3";
11 |
12 | // [START messages]
13 | message Person {
14 |
15 | optional uint32 id = 1;
16 | optional string number = 2; // Unique ID number for this person.
17 | optional uint32 anotherId = 3;
18 | optional uint32 aid = 4;
19 | optional uint32 bid = 5;
20 | optional uint32 cid = 6;
21 | optional uint32 did = 7;
22 | optional uint32 eid = 8;
23 | optional uint32 fid = 9;
24 | optional uint32 gid = 10;
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/Cpp/twoSum.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | // 1. Two Sum
6 |
7 | class Solution {
8 | public:
9 | std::vector twoSum(std::vector& nums, int target) {
10 |
11 | std::unordered_map map;
12 |
13 | for(size_t i{0}; i{static_cast(i), it->second};
18 |
19 | map[nums[i]] = i;
20 | }
21 | return std::vector{};
22 | }
23 | };
24 |
25 | int main(){
26 | std::vector vec{2,7,11,15};
27 | auto res = Solution{}.twoSum(vec, 9);
28 | std::copy(res.begin(),res.end(),std::ostream_iterator(std::cout, " " ));
29 |
30 | }
--------------------------------------------------------------------------------
/Py/clientWebsocket.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import asyncio
4 | import websockets
5 | import threading
6 | import sys
7 |
8 | async def hello():
9 | for x in range(100000):
10 | async with websockets.connect("ws://localhost:8083") as websocket:
11 | await websocket.send(str(x))
12 | name = await websocket.recv()
13 | #print("< {}".format(name))
14 | print(name,end = ' ', flush=True)
15 | sys.stdout.flush()
16 |
17 | #asyncio.run(hello())
18 |
19 |
20 | async def main():
21 |
22 | await asyncio.wait([
23 | hello(),
24 | hello(),
25 | hello(),
26 | hello(),
27 | hello(),
28 | hello(),
29 | hello(),
30 | hello(),
31 | hello(),
32 | hello(),
33 | hello()
34 | ])
35 |
36 | loop = asyncio.get_event_loop()
37 | loop.run_until_complete(main())
--------------------------------------------------------------------------------
/Cpp/numIslandsDFS.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int numIslands(vector>& grid) {
4 | int m = grid.size(), n = m ? grid[0].size() : 0, islands = 0;
5 | for (int i = 0; i < m; i++) {
6 | for (int j = 0; j < n; j++) {
7 | if (grid[i][j] == '1') {
8 | islands++;
9 | eraseIslands(grid, i, j);
10 | }
11 | }
12 | }
13 | return islands;
14 | }
15 | private:
16 | void eraseIslands(vector>& grid, int i, int j) {
17 | int m = grid.size(), n = grid[0].size();
18 | if (i < 0 || i == m || j < 0 || j == n || grid[i][j] == '0') {
19 | return;
20 | }
21 | grid[i][j] = '0';
22 | eraseIslands(grid, i - 1, j);
23 | eraseIslands(grid, i + 1, j);
24 | eraseIslands(grid, i, j - 1);
25 | eraseIslands(grid, i, j + 1);
26 | }
27 | };
28 |
--------------------------------------------------------------------------------
/Cpp/RTTI.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | // to disable the RTTI -fno-rtti
3 | // g++ -fno-rtti RTTI.cpp -o RTTI
4 | class Animal{
5 | //virtual void dummy(){}
6 | };
7 |
8 | class StrayCat : public Animal
9 | {
10 | public:
11 | void meow(){std::cout<<"meoww"<(animalPtr);
20 | //if(catPtr)
21 | catPtr->meow();
22 | //else{std::cout<<"Related instance "<<
23 | // "has no meow"<
2 | #include
3 | #include
4 |
5 | // Example of passing this to lambda expression
6 | // that is not working for out of scope case for
7 | // dummy foo object
8 |
9 | // should be used *this. It is available after c++17
10 |
11 | // note: with this (without *this) example will NOT work with x86-64 gcc 11.2
12 | // but it will work with x86-64 clang 13.0.0
13 |
14 | struct foo
15 | {
16 | int id;
17 | std::string name;
18 | //std::function run()
19 | auto run()
20 | {
21 | return[this]{ std::cout << id << ' ' << name << '\n'; };
22 | //return[*this]{ std::cout << id << ' ' << name << '\n'; };
23 | }
24 | };
25 |
26 | //std::function boo()
27 | auto boo()
28 | {
29 | return foo{ 42, "john" }.run();
30 | }
31 |
32 | int main()
33 | {
34 | auto l = boo();
35 | l(); // does not print 42 john
36 | }
37 |
--------------------------------------------------------------------------------
/Cpp/socketExample/mytask.cpp:
--------------------------------------------------------------------------------
1 | // mytask.cpp
2 |
3 | #include "mytask.h"
4 | #include
5 | #include
6 | #include
7 |
8 | MyTask::MyTask()
9 | {
10 | qDebug() << "MyTask()";
11 | }
12 |
13 | // When the thread pool kicks up
14 | // it's going to hit this run, and it's going to do this time consuming task.
15 | // After it's done, we're going to send the results back to our main thread.
16 | // This runs in the separate thread, and we do not have any control over this thread,
17 | // but Qt does.
18 | // This may just stay in the queue for several ms depending on how busy the server is.
19 |
20 | void MyTask::run()
21 | {
22 | // time consumer
23 |
24 | qDebug() << "Task started";
25 |
26 | int iNumber = 0;
27 | for(int i = 0; i < 100; i++)
28 | {
29 | iNumber += 1;
30 | }
31 | std::this_thread::sleep_for(std::chrono::milliseconds(2000));
32 |
33 |
34 | qDebug() << "Task done";
35 | emit Result(iNumber);
36 | }
37 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/QtOpencvQml/QtOpencvQml.pro:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Automatically generated by qmake (3.1) Sat Sep 3 21:58:11 2022
3 | ######################################################################
4 |
5 | QT += quick
6 |
7 | CONFIG += c++11
8 |
9 | CONFIG += link_pkgconfig
10 | PKGCONFIG += opencv4
11 |
12 | TEMPLATE = app
13 | TARGET = QtOpencvQml
14 | INCLUDEPATH += .
15 |
16 | RESOURCES += qml.qrc
17 |
18 |
19 | # You can make your code fail to compile if you use deprecated APIs.
20 | # In order to do so, uncomment the following line.
21 | # Please consult the documentation of the deprecated API in order to know
22 | # how to port your code away from it.
23 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
25 |
26 | # Input
27 | SOURCES += main.cpp qmlType.cpp
28 |
29 | HEADERS += qmlType.h
30 |
--------------------------------------------------------------------------------
/Cpp/framebuffer1.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | // application entry point
10 | int main(int argc, char* argv[])
11 | {
12 | int fbfd = 0; // framebuffer filedescriptor
13 | struct fb_var_screeninfo var_info;
14 |
15 | // Open the framebuffer device file for reading and writing
16 | fbfd = open("/dev/fb0", O_RDWR);
17 | if (fbfd == -1) {
18 | printf("Error: cannot open framebuffer device.\n");
19 | return(1);
20 | }
21 | printf("The framebuffer device opened.\n");
22 |
23 | // Get variable screen information
24 | if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var_info)) {
25 | printf("Error reading variable screen info.\n");
26 | }
27 | printf("Display info %dx%d, %d bpp\n",
28 | var_info.xres, var_info.yres,
29 | var_info.bits_per_pixel );
30 |
31 | // close file
32 | close(fbfd);
33 |
34 | return 0;
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Cpp/nonAutoDuration.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // g++ nonAutoDuration.cpp -o example -lpthread
5 | // valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./example
6 | class Example
7 | {
8 | public:
9 | int a = 1;
10 | };
11 |
12 | void foo()
13 | {
14 | static Example ex;
15 |
16 | ex.a = 1;
17 |
18 | std::thread t([&ex]()mutable{
19 |
20 | std::cout<
2 | #include
3 | // https://godbolt.org/z/jqEhvo13Y
4 |
5 | class Concrete {
6 | public:
7 | int NonMockedMethod() {
8 | return 42;
9 | }
10 |
11 | virtual int MockedMethod() {
12 | return 43;
13 | }
14 | };
15 |
16 | class MockConcrete : public Concrete {
17 | public:
18 | MOCK_METHOD(int, MockedMethod, (), (override));
19 |
20 | MockConcrete() {
21 | // Call the real implementation by default
22 | ON_CALL(*this, MockedMethod())
23 | .WillByDefault([this]() { return Concrete::MockedMethod(); });
24 | }
25 | };
26 |
27 | TEST(MockConcreteTest, CanMockConcrete) {
28 | MockConcrete obj;
29 |
30 | // When we call NonMockedMethod, we call the real implementation
31 | EXPECT_EQ(42, obj.NonMockedMethod());
32 |
33 | EXPECT_EQ(43, obj.MockedMethod());
34 |
35 | // We can still override MockedMethod to return a different value
36 | EXPECT_CALL(obj, MockedMethod()).WillOnce(::testing::Return(44));
37 | EXPECT_EQ(44, obj.MockedMethod());
38 | }
--------------------------------------------------------------------------------
/Py/DrawCircle.py:
--------------------------------------------------------------------------------
1 | import cv2
2 |
3 |
4 | def draw_circle(event,
5 | x,
6 | y,
7 | flags,
8 | param):
9 | global center, clicked
10 |
11 | # get the mouse click down & up
12 | # and Track the center
13 | if event == cv2.EVENT_LBUTTONDOWN:
14 | center = (x, y)
15 | clicked = False
16 |
17 | if event == cv2.EVENT_LBUTTONUP:
18 | clicked = True
19 |
20 |
21 | # zero drawing of the circle
22 | center = (0, 0)
23 | clicked = False
24 |
25 | # Take a video
26 | cap = cv2.VideoCapture(0)
27 |
28 | # Create a Named Window for the Connections
29 | cv2.namedWindow('Testing')
30 |
31 | # Bind Our Function with mouse click
32 | cv2.setMouseCallback('Testing', draw_circle)
33 |
34 | while True:
35 | ret, frame = cap.read()
36 |
37 | if clicked:
38 | cv2.circle(frame, center=center, radius=50, color=(255, 255, 255), thickness=3)
39 |
40 | cv2.imshow('Testing', frame)
41 |
42 | if cv2.waitKey(3) & 0xFF == 27:
43 | break
44 |
45 | cap.release()
46 | cv2.destroyAllWindows()
47 |
--------------------------------------------------------------------------------
/Cpp/QtOpenCV/Viewer/viewer.pro:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Automatically generated by qmake (3.1) Thu Aug 18 22:08:08 2022
3 | ######################################################################
4 |
5 | TEMPLATE = app
6 | TARGET = viewer
7 | INCLUDEPATH += .
8 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
9 |
10 | # The following define makes your compiler warn you if you use any
11 | # feature of Qt which has been marked as deprecated (the exact warnings
12 | # depend on your compiler). Please consult the documentation of the
13 | # deprecated API in order to know how to port your code away from it.
14 | DEFINES += QT_DEPRECATED_WARNINGS
15 |
16 | # You can also make your code fail to compile if you use deprecated APIs.
17 | # In order to do so, uncomment the following line.
18 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
19 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
20 |
21 | # Input
22 | SOURCES += main.cpp mainwindow.cpp
23 |
24 | HEADERS += mainwindow.h
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gtestExample/exampleTest.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "example.cpp"
4 |
5 | using namespace std;
6 | // g++ -Wall -g -pthread exampleTest.cpp example.cpp -lgtest_main -lgtest -lpthread -o test
7 | // test fixture
8 | class ExampleTest : public testing::Test
9 | {
10 | protected:
11 | Example *ex;
12 | void SetUp()
13 | {
14 | ex = new Example;
15 | cout<<"Created"<increase(100);
28 | EXPECT_EQ(100,ex->ctr);
29 | }
30 |
31 | TEST(Example, test1)
32 | {
33 | Example inst;
34 | inst.increase(100);
35 | EXPECT_EQ(100, inst.ctr);
36 | }
37 |
38 | TEST(Example, test2)
39 | {
40 | Example inst;
41 | inst.increase(100);
42 | ASSERT_EQ(500, inst.ctr);
43 |
44 | inst.decrease(50);
45 | EXPECT_EQ(100, inst.ctr);
46 | }
47 |
48 | int main(int argc, char **argv)
49 | {
50 | testing::InitGoogleTest(&argc, argv);
51 |
52 | return RUN_ALL_TESTS();
53 | }
--------------------------------------------------------------------------------
/Cpp/asyncProcess.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int main()
8 | {
9 |
10 | std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
11 |
12 | //int cnt{0};
13 | std::atomic cnt{0};
14 | int iterator{1'000'000};
15 | std::mutex lockMutex;
16 |
17 |
18 | std::future obj1 = std::async(std::launch::async, [&]()
19 | {
20 | //std::lock_guard guardMutex(lockMutex); //RAII style mechanism
21 | // lockMutex automatically released when guardMutex is out of scope
22 | for(int i{0}; i guardMutex(lockMutex);
29 | for(int i{0}; i(end-begin).count()<<"[us]"<
2 | #include
3 | #include
4 |
5 | class Solution
6 | {
7 | public:
8 | int stockPairs(std::vector stocksProfit,
9 | long target)
10 | {
11 | int result {0};
12 | std::unordered_map m;
13 | for(size_t i{0}; i vec {5, 7, 9, 9, 13, 11, 6, 6, 3, 3};
39 | int target = 12;
40 |
41 | std::cout<
2 | #include
3 |
4 | class Solution
5 | {
6 | public:
7 | std::string longestPalindrome(const std::string& s)
8 | {
9 | size_t size {s.size()};
10 |
11 | unsigned int max_length {0};
12 | unsigned int min_start {0};
13 |
14 | for(unsigned int i{0}; i < size;)
15 | {
16 | if((size-i) <= max_length/2) break;
17 | unsigned int k {i}, j {i};
18 |
19 | while( k 0 && (s[k+1] == s[j-1])) // expand
23 | {
24 | ++k;
25 | --j;
26 | }
27 |
28 | unsigned int new_length {k-j+1};
29 | if(new_length > max_length){ max_length = new_length; min_start=j;}
30 | }
31 |
32 | return size ? size==1 ? s : s.substr(min_start,max_length) : "";
33 | }
34 | };
35 |
36 | int main()
37 | {
38 | const std::string str = "asddabbasswe";
39 |
40 | std::cout<
2 |
3 | //A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Longest common subsequence (LCS) of 2 sequences is a subsequence, with maximal length, which is common to both the sequences.
4 |
5 |
6 | using namespace std;
7 |
8 | using iter = string::const_iterator;
9 |
10 | int MaxChildRanges(iter b1, iter e1, iter b2, iter e2)
11 | {
12 |
13 | if(b1==e1 || b2==e2)
14 | return 0;
15 |
16 | if(*b1 == *b2)
17 | return 1 + MaxChildRanges(next(b1), e1, next(b2), e2);
18 |
19 | return max( MaxChildRanges(next(b1), e1, b2, e2),
20 | MaxChildRanges(b1, e1, next(b2), e2));
21 | }
22 |
23 | int commonChild(const string& s1, const string& s2) {
24 |
25 | return MaxChildRanges(s1.begin(), s1.end(), s2.begin(), s2.end());
26 |
27 | }
28 |
29 | int main()
30 | {
31 |
32 | std::string str1 {"SHINCHAN"};
33 | std::string str2 {"NOHARAAA"};
34 |
35 | int result = commonChild(str1, str2);
36 |
37 | cout << result << "\n";
38 |
39 |
40 | return 0;
41 | }
42 |
--------------------------------------------------------------------------------
/sharedCallbackExample/exampleA.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "exampleB.h"
7 | #include "exampleA.h"
8 |
9 |
10 | A::A()
11 | {
12 | std::cout<<"A cons"<(shared_from_this()); // can not be called inside of the constructor
14 |
15 | // std::thread([this](){
16 |
17 | // std::this_thread::sleep_for (std::chrono::seconds(1));
18 | // Bptr = std::make_shared(shared_from_this());
19 |
20 | // }).detach();
21 |
22 | //std::this_thread::sleep_for (std::chrono::seconds(3));
23 |
24 | }
25 |
26 | void A::foo()
27 | {
28 | Bptr = std::make_shared(shared_from_this()); // can not be called inside of the constructor
29 | //It is permitted to call shared_from_this only on a previously shared object, i.e. on an object managed by std::shared_ptr (in particular, shared_from_this cannot be called during construction of *this).
30 | // terminate called after throwing an instance of 'std::bad_weak_ptr
31 | }
32 |
33 | void A::Acallback()
34 | {
35 | std::cout<<"Acallback"<
6 | #include
7 |
8 | //using namespace boost::asio
9 | //using ip::tcp
10 |
11 | using std::string;
12 | using std::cout;
13 | using std::endl;
14 |
15 | int main()
16 | {
17 | boost::asio::io_service io_service;
18 | //listen for new connection
19 | boost::system::error_code ec;
20 | boost::asio::ip::tcp::acceptor acceptor_(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 1234 ));
21 | boost::asio::ip::tcp::socket socket_(io_service);//socket creation
22 | acceptor_.accept(socket_);//waiting for connection
23 | //read operation
24 | boost::asio::streambuf buf;
25 | boost::asio::read_until( socket_, buf, "\n",ec);
26 | if(ec){std::cout<(buf.data());
28 | cout << data << endl;
29 | //write operation
30 | boost::asio::write( socket_, boost::asio::buffer(data) ,ec);
31 | if(ec){std::cout<
2 | #include
3 | #include
4 |
5 | class Solution {
6 | public:
7 | std::vector twoOutOfThree(std::vector& nums1, std::vector& nums2, std::vector& nums3) {
8 | struct found
9 | {
10 | bool n1;
11 | bool n2;
12 | bool n3;
13 | };
14 |
15 | std::unordered_map map;
16 | for(auto n : nums1) map[n].n1 = true;
17 | for(auto n : nums2) map[n].n2 = true;
18 | for(auto n : nums3) map[n].n3 = true;
19 |
20 | std::vector result;
21 | result.reserve(map.size());
22 |
23 | for(const auto x : map)
24 | {
25 | if(x.second.n1 + x.second.n2 + x.second.n3 >= 2)
26 | result.push_back(x.first);
27 | }
28 |
29 | return result;
30 | }
31 | };
32 |
33 | int main()
34 | {
35 | std::vector vec1 {3,1};
36 | std::vector vec2 {2,3};
37 | std::vector vec3 {1,2};
38 |
39 | for(const auto v : Solution{}.twoOutOfThree(vec1, vec2, vec3))
40 | std::cout<
2 |
3 | //A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Longest common subsequence (LCS) of 2 sequences is a subsequence, with maximal length, which is common to both the sequences.
4 |
5 |
6 | using namespace std;
7 |
8 | using iter = string::const_iterator;
9 |
10 | int MaxChildRanges(iter b1, iter e1, iter b2, iter e2)
11 | {
12 |
13 | int result;
14 | if(b1==e1 || b2==e2)
15 | result = 0;
16 | else if(*b1 == *b2)
17 | result = 1 + MaxChildRanges(next(b1), e1, next(b2), e2);
18 | else
19 | result = max(MaxChildRanges(next(b1), e1, b2, e2),
20 | MaxChildRanges(b1, e1, next(b2), e2));
21 |
22 | return result;
23 | }
24 |
25 | int commonChild(const string& s1, const string& s2) {
26 |
27 | return MaxChildRanges(s1.begin(), s1.end(), s2.begin(), s2.end());
28 |
29 | }
30 |
31 | int main()
32 | {
33 |
34 | std::string str1 {"SHINCHAN"};
35 | std::string str2 {"NOHARAAA"};
36 |
37 | int result = commonChild(str1, str2);
38 |
39 | cout << result << "\n";
40 |
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/protoExamples/test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "test.pb.h"
5 | #include "google/protobuf/io/zero_copy_stream_impl.h"
6 | #include "google/protobuf/text_format.h"
7 |
8 | using ::google::protobuf::RepeatedField;
9 | using ::google::protobuf::int64;
10 |
11 | int main()
12 | {
13 | Test test;
14 | test.add_id(10);
15 | test.add_id(20);
16 | test.add_id(30);
17 |
18 | std::cout<& id_vec = test.id();
23 | for(auto a : id_vec)
24 | {
25 | // *itr += 1000; // this will throw an compiler error. It is not mutable.
26 | std::cout<< "id: "<* mut_vec = test.mutable_id();
34 |
35 | for(auto itr = mut_vec->begin(); itr != mut_vec->end(); ++itr)
36 | {
37 | *itr += 1000; // this will throw an compiler error. It is not mutable.
38 | std::cout<< "id: "<<*itr<
2 | #include
3 |
4 |
5 | /*
6 | * It is like finding a start point of circle in linked list
7 | * Start point of the circle is the first repeated number
8 | * Lets define array like linked list with using index
9 | * 1 3 4 2 2 (vector itself)
10 | * 0 1 2 3 4 (index)
11 | *
12 | * 0 goes to 1, 1 goies to 3, 3 goes to 2,
13 | * 0 -> 1 -> 3 -> 2 -> 4
14 | * 4 -> 2, as it is seen there is a loop between 2 and 4.
15 | * And the 2 is the start point of the circle which is
16 | * first repeated number in the array/vector.
17 | *
18 | *
19 | */
20 |
21 | class Solution {
22 | public:
23 | int findDuplicate(std::vector& nums) {
24 | int slow = nums[0];
25 | int fast = nums[nums[0]];
26 |
27 | while(slow != fast)
28 | {
29 | slow = nums[slow];
30 | fast = nums[nums[fast]];
31 | }
32 |
33 | slow = 0;
34 | while(slow != fast)
35 | {
36 | slow = nums[slow];
37 | fast = nums[fast];
38 | }
39 |
40 | return slow;
41 | }
42 | };
43 |
44 | int main()
45 | {
46 | std::vector vec {1,3,4,2,2};
47 | std::cout<
2 | #include
3 |
4 | class Solution
5 | {
6 | public:
7 | void dfs(std::vector> &map, int x, int y)
8 | {
9 | if(x < 0 || y < 0 || x >= map.size() || y >= map[0].size() || map[x][y] == '0')
10 | return;
11 |
12 | map[x][y] = '0';
13 | dfs(map, x + 1, y);
14 | dfs(map, x - 1, y);
15 | dfs(map, x, y + 1);
16 | dfs(map, x, y - 1);
17 | }
18 | int numberOfIslands(std::vector> &map)
19 | {
20 | int result = 0;
21 |
22 | if(map.size() == 0)
23 | return result;
24 |
25 | for(int i = 0; i < map.size(); i++)
26 | {
27 | for(int j = 0; j < map[0].size(); j++)
28 | {
29 | if(map[i][j] == '1')
30 | {
31 | result ++;
32 |
33 | dfs(map,i,j);
34 | }
35 | }
36 | }
37 |
38 |
39 | return result;
40 | }
41 | };
42 |
43 |
44 | int main()
45 | {
46 |
47 | std::vector> map
48 | {
49 | {'1','0','1','0','1'},
50 | {'1','0','1','0','1'},
51 | {'1','0','1','0','1'},
52 | {'1','0','1','0','1'},
53 | {'1','0','0','0','0'},
54 | {'1','0','1','0','1'},
55 | {'1','0','0','0','1'},
56 | {'1','0','0','0','1'},
57 | {'1','0','0','0','1'},
58 | {'1','0','1','1','1'}
59 | };
60 |
61 | Solution s;
62 | std::cout<= 0 and nr < m and nc >= 0 and nc < n and grid[nr][nc] == '1':
23 | queue.append((nr, nc))
24 | grid[nr][nc] = '0'
25 | return count
26 |
27 |
28 | tmp = Solution()
29 | grid = [
30 | ['1', '0', '1', '0', '1', '0', '1'],
31 | ['1', '0', '0', '0', '0', '0', '1'],
32 | ['0', '0', '0', '1', '0', '0', '1'],
33 | ['1', '0', '1', '0', '1', '1', '1'],
34 | ['1', '0', '1', '0', '1', '0', '1'],
35 | ['1', '0', '1', '0', '1', '0', '1']
36 | ]
37 | print(tmp.numOfIslands(grid))
38 |
--------------------------------------------------------------------------------
/protoExamples/socket_server_json.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import socket
4 | from time import sleep
5 | import json
6 | import sys
7 |
8 | HOST = '127.0.0.1' # Standard loopback interface address (localhost)
9 | PORT = 2389 # Port to listen on (non-privileged ports are > 1023)
10 |
11 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
12 | s.bind((HOST, PORT))
13 | s.listen()
14 | conn, addr = s.accept()
15 | with conn:
16 | print('Connected by', addr)
17 | while True:
18 | data = conn.recv(172)
19 | if not data:
20 | break
21 |
22 | data = data.decode('utf-8')
23 | #print(data)
24 | d = json.dumps(data)
25 |
26 | send_data = {}
27 | send_data['id'] = '5001'
28 | send_data['id2'] = '5001'
29 | send_data['id3'] = '5001'
30 | send_data['id4'] = '5001'
31 | send_data['id5'] = '5001'
32 | send_data['id6'] = '5001'
33 | send_data['id7'] = '5001'
34 | send_data['id8'] = '5001'
35 | send_data['id9'] = '5001'
36 | send_data['id10'] = '5001'
37 |
38 | json_data = json.dumps(send_data)
39 | #print(sys.getsizeof(json_data))
40 |
41 | conn.sendall(bytes(json_data,encoding="utf-8"))
42 |
--------------------------------------------------------------------------------
/Cpp/asioTcpServer/server.cpp:
--------------------------------------------------------------------------------
1 | //simple tcp socket server example with boost asio
2 | //sudo apt install libboost-dev
3 | //g++ -lpthread -lboost_system server.cpp -o server
4 |
5 | #include
6 | #include
7 |
8 |
9 | //using namespace boost::asio
10 | //using ip::tcp
11 |
12 | int main(int argc, char* argv[])
13 | {
14 |
15 | if(argc != 3)
16 | {
17 | std::cout<<"Wrong parameter\n"<<"Example usage 127.0.0.1 1234"<(buf.data());
35 | std::cout << data << std::endl;
36 | //write operation
37 | boost::asio::write( socket_, boost::asio::buffer(data) ,ec);
38 | if(ec){std::cout<
2 | #include
3 | #include
4 |
5 | // leetcode 454. 4Sum II
6 | // Given four integer arrays v1, v2, v3, and v4 all of length n, return the number of tuples (i, j, k, l) such that:
7 | // 0 <= i, j, k, l < n
8 | // nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
9 |
10 | class Solution
11 | {
12 | using vec = const std::vector;
13 | public:
14 | int fourSumCount(vec& v1, vec& v2, vec& v3, vec& v4)
15 | {
16 | unsigned int result {0};
17 |
18 | std::unordered_map map;
19 |
20 | const size_t size {v1.size()};
21 | // nums1[i] + nums2[j] = -(nums3[k] + nums4[l])
22 | for(int i{0}; i vec1 {1,2};
37 | std::vector vec2 {-2,-1};
38 | std::vector vec3 {-1,2};
39 | std::vector vec4 {0,2};
40 |
41 | std::cout<
3 | #include
4 | #include // std::chrono::seconds
5 | #include
6 | //g++ -std=c++17 threadLimitTest.cpp -lpthread -o binary
7 |
8 | int main() {
9 | unsigned int n = std::thread::hardware_concurrency();
10 | std::cout << n << " concurrent threads are supported.\n";
11 | std::atomic a {1};
12 | //for(int i = 0; i<100000; i++)
13 | try
14 | {
15 | while(a > 0)
16 | {
17 |
18 | std::thread([&](){
19 |
20 |
21 | while(1)
22 | {
23 | //a ++;
24 | //std::cout<
2 | #include
3 | #include
4 |
5 | // Function to find the number of distinct pairs of stocks that sum to the target profit
6 | class Solution
7 | {
8 | public:
9 | int stockPairs(std::vector& profits, int target) {
10 | // Initialize a hash set to store the profits that have been seen
11 | std::unordered_set seen;
12 |
13 | // Initialize a counter to keep track of the number of pairs
14 | int count = 0;
15 |
16 | // Iterate through the array of profits
17 | for (int profit : profits) {
18 | // Check if the target profit minus the current profit has been seen before
19 | if (seen.count(target - profit)) {
20 | // If it has, increment the counter
21 | count++;
22 | }
23 | // Add the current profit to the hash set
24 | seen.insert(profit);
25 | }
26 |
27 | // Return the number of pairs found
28 | return count;
29 | }
30 | };
31 |
32 | int main() {
33 | // Define the array of profits and the target profit
34 | std::vector profits = {5, 7, 9, 9, 13, 11, 6, 6, 3, 3};
35 | int target = 12;
36 |
37 | std::cout<
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int tsp(int mask, int pos,
8 | std::vector>& vec,
9 | std::vector>& dp)
10 | {
11 |
12 | const int size {vec.size()};
13 |
14 | if(mask == ((1<>& vec)
39 | {
40 | std::vector> dp(vec.size()*vec.size(),std::vector(vec.size(),-1));
41 | return tsp(1,0,vec,dp);
42 | }
43 |
44 |
45 | int main()
46 | {
47 |
48 | std::vector> dist{
49 | {0,20,42,25},
50 | {20,0,30,34},
51 | {42,30,0,10},
52 | {25,34,10,0},
53 | };
54 |
55 | std::cout<
2 | #include
3 | #include
4 |
5 | /*
6 | *
7 | * Given string find firt non repeating unique character if there is none return -1
8 | *
9 | * leetcode returns 0
10 | * loveleetcode returns 2
11 | *
12 | * */
13 |
14 |
15 | using namespace std;
16 |
17 | class Solution
18 | {
19 |
20 | public:
21 | int firstUniqueCharacterInString(string &str)
22 | {
23 |
24 | std::unordered_map map;
25 | int ans = INT_MAX;
26 |
27 | for(int i=0; i
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | class MainWindow : public QMainWindow
15 | {
16 | Q_OBJECT
17 |
18 | public:
19 | explicit MainWindow(QWidget *parent=nullptr);
20 | ~MainWindow();
21 |
22 | private:
23 | void initUI();
24 | void createActions();
25 | void showImage(QString);
26 | void setupShortcuts();
27 |
28 | private slots:
29 | void openImage();
30 | void zoomIn();
31 | void zoomOut();
32 | void prevImage();
33 | void nextImage();
34 | void saveAs();
35 |
36 | private:
37 | QMenu *fileMenu;
38 | QMenu *viewMenu;
39 |
40 | QToolBar *fileToolBar;
41 | QToolBar *viewToolBar;
42 |
43 | QGraphicsScene *imageScene;
44 | QGraphicsView *imageView;
45 |
46 | QStatusBar *mainStatusBar;
47 | QLabel *mainStatusLabel;
48 |
49 | QAction *openAction;
50 | QAction *saveAsAction;
51 | QAction *exitAction;
52 | QAction *zoomInAction;
53 | QAction *zoomOutAction;
54 | QAction *prevAction;
55 | QAction *nextAction;
56 |
57 | QString currentImagePath;
58 | QGraphicsPixmapItem *currentImage;
59 | };
60 |
61 | #endif // MAINWINDOW_H
62 |
--------------------------------------------------------------------------------
/Cpp/minTimeToCompleteTrip.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include