C++ cool cheetsheet produced by ChatGPT to refresh your memory

chatGPT is really helpful tool to programmers. these cheetsheet were produced by chatGPT 3.5 to help refresh your memory. if you are advanced programmer or have background in other languages. it can help to look at simple one liners instead of going through long pages of documentations

Keep in mind, chatGPT sometimes produces inaccurate information and sometimes it hallucinates:

  • Declaration of variables: int a = 10;
  • Conditional statements: if (a == 10) { ... } else { ... }
  • Loops: for (int i = 0; i < 10; i++) { ... } or while (condition) { ... }
  • Functions: void myFunction(int arg1, double arg2) { ... }
  • Classes and objects: class MyClass { ... }; MyClass myObject;
  • Inheritance: class ChildClass : public ParentClass { ... }
  • Polymorphism: virtual void myFunction() { ... } and override keyword in child classes
  • Templates: template void myFunction(T arg) { ... }
  • Standard libraries: #include for input/output, #include for dynamic arrays, #include for string manipulation, and many others.
  • Pointers and references: int *ptr = &a; and int &ref = a;
  • Memory management: new and delete for dynamic memory allocation and deallocation
  • Exception handling: try { ... } catch (exceptionType e) { ... }
  • Namespaces: namespace myNamespace { ... }
  • Macros: #define MY_MACRO(value) (value * 2)
  • Preprocessor directives: #include for header files, #ifdef and #ifndef for conditional compilation
  • Operator overloading: operator+, operator-, etc. can be overloaded for custom classes
  • Type casting: static_cast, dynamic_cast, reinterpret_cast, and const_cast
  • Standard Template Library (STL): provides containers like vector, map, set, and algorithms like sort, find, and accumulate
  • File input/output: fstream for reading/writing to files
  • String streams: stringstream for parsing and formatting strings
  • Multi-threading: std::thread for creating threads, std::mutex for thread synchronization
  • Function objects: std::function for storing and invoking callable objects
  • Lambda expressions: [] (int a, int b) { return a + b; } for inline functions or function objects
  • Range-based for loop: for (auto x : myVector) { ... } for iterating over a range of values
  • Smart pointers: std::unique_ptr and std::shared_ptr for automatic memory management
  • Regular expressions: std::regex for pattern matching and search in strings
  • Type traits: std::is_integral, std::is_floating_point, and others for compile-time type analysis
  • Move semantics: std::move for efficient transfer of ownership of objects
  • Variadic templates: template void myFunction(Args... args) { ... } for functions that can take any number of arguments.
  • Type deduction: auto for automatic type deduction of variables and lambda expressions
  • Rvalue references: int &&rref = 42; for binding to temporaries and move semantics
  • User-defined literals: 42_milliseconds or 3.14_pi for custom literals of user-defined types
  • Initialization lists: {1, 2, 3} for initializing objects and containers
  • Uniform initialization: MyClass obj{1, "hello"}; for consistent initialization syntax
  • constexpr functions: constexpr int factorial(int n) { ... } for compile-time evaluation of functions
  • Type aliases: using myInt = int; for creating aliases for types or templates
  • Concepts: template concept MyConcept = ... for expressing requirements on template arguments
  • Modules: import myModule; for modularization of code and faster compilation
  • Co-routines: co_await and co_yield for implementing asynchronous code and generators.
  • esign patterns: C++ supports many design patterns such as the Singleton pattern, the Observer pattern, and the Factory pattern.
  • Multiple inheritance: C++ allows classes to inherit from multiple base classes, providing flexibility in class hierarchy design.
  • C++11 features: C++11 introduced new language features such as lambdas, range-based for loops, and smart pointers to improve expressiveness and safety of C++ code.
  • C++14 features: C++14 added new features such as binary literals, generic lambdas, and extended constexpr to further improve the language.
  • C++17 features: C++17 added new features such as structured bindings, constexpr if, and fold expressions to provide more powerful and expressive templates.
  • C++20 features: C++20 introduced new features such as concepts, coroutines, and modules to further improve the language.
  • Third-party libraries: C++ has a vast ecosystem of third-party libraries such as Boost, Eigen, and OpenCV that provide additional functionality for C++ developers.
  • IDEs: Integrated development environments (IDEs) such as Visual Studio, CLion, and Code::Blocks provide powerful tools for editing, debugging, and testing C++ code.
  • Here are some briefs about common C++ headers, Qt headers, controls, and external libraries:C++ headers:
    • : Input/output library for C++.
    • : STL container for dynamic arrays.
    • : STL container for strings.
    • : Input/output library for files.
    • : STL algorithms for containers.

    Qt headers:

    • : Main application class for Qt Widgets.
    • : Main application class for Qt Quick.
    • : Base class for all Qt Widgets.
    • : Base class for all Qt Quick items.
    • : Base class for all Qt Widgets layouts.
    • : Class for creating QML objects dynamically.

    Common Qt controls:

    • QLabel: Control for displaying text and images.
    • QLineEdit: Control for editing text.
    • QPushButton: Control for triggering actions.
    • QCheckBox: Control for toggling on/off states.
    • QRadioButton: Control for selecting a single option from a set.
    • QComboBox: Control for selecting one option from a drop-down list.
    • QSpinBox: Control for selecting a numeric value from a range.
    • QSlider: Control for selecting a numeric value from a range with a slider.
    • QTableView: Control for displaying data in a table format.

    External libraries:

    • Boost: Collection of libraries for C++, including support for smart pointers, regular expressions, and numerical algorithms.
    • OpenCV: Library for computer vision and image processing.
    • Eigen: Library for linear algebra.
    • Qt Charts: Library for creating charts and graphs in Qt applications.
    • Qt WebEngine: Library for embedding web content into Qt applications.
    • Qt Network: Library for network programming in Qt applications.
    • Qt Multimedia: Library for audio and video playback and recording in Qt applications.

How to read an image from url in python 3 and get the height and width

To read an image directly from url and then reads its size. you can use urllib.request and PIL aka Pillow.
If you don’t have pillow installed. you can use:

python -m pip install Pillow

and before that you might need to upgrade pip, especially if you get an error

python -m pip install --upgrade pip

Here is how to read an image from url.

import urllib.request from PIL import Image url = 'http://www.example.com/my_image_is_not_your_image.png' image = Image.open(urllib.request.urlopen(url)) width, height = image.size print (width,height)

If you followed a tutorial that uses urllib2 you can change that to urllib.request in python 3.

‘cp932’ codec can’t encode character ‘\xa1’ in position 62: illegal multibyte sequence

When using print in python with some multibyte character or when decoding from another encoding you might encounter this fatal error:

Traceback (most recent call last): File "skynet.py", line 28, in print(skyname_wakeup_word) UnicodeEncodeError: 'cp932' codec can't encode character '\xa1' in position 62: illegal multibyte sequence

To sort of fix it, you can use


This occurs because python can’t convert that character to the traditional windows ansi used in windows terminal (cmd). cp932 is code page 932 the Japanese version of shift-JIS.
Other encodings: cp874, cp936, cp949, cp950, cp1251, cp1252, cp1253, cp1254, cp1255, cp1256, cp1257, cp1258. Source

IE 11 not opening, crashing on Windows 10 after upgrade from windows 7, How to solve

After upgrading from windows 7 to 10,  IE 11 doesn’t open.  I have searched a lot but didn’t find a solution.  One solution suggested it was due to logitech camera’s process monitor. but removing that didn’t solve the problem.   The error log in event viewer was this:

Faulting application name: iexplore.exe, version: 11.0.10240.16412, time stamp: 0x55b99d3f
Faulting module name: ntdll.dll, version: 10.0.10240.16430, time stamp: 0x55c59f92
Exception code: 0xc0000409

After some digging, it turned out it was due to EMET 5.2 Microsoft mitigation service.  seems Microsoft security service breaks its own program.   I uninstalled it, IE 11 worked. I reinstalled it after downloading it again from Microsoft site.  IE 11 stopped working.  I opened EMET notification and went into apps and tested the different checkboxes for IE.  unchecked EAF and leaving other checks worked.

TL;DR;  If you have EMET 5.2 installed, opening EMET, going to APPS -> unchecking EAF in front of Internet Explorer and then OK should make IE work again.  what security implication that means not sure. but Microsoft should fix this soon.