How to Remove Safe Finder on Mac OS

Summary In this post, I will introduce how to remove Safe Finder, a notorious malware on multiple platforms. This post is not a technical post but really helps. Conclusion Use Malwarebytes. I’m not advertising. And the free version works. Details Safe Finder I come across Safe Finder when I surf a website which requires me…

Const, Pointers and References

Summary In this post, I will introduce const, * and & and their combinations. I also have similar posts discussed auto and &. Conclusion As usual, I present the golden rule first: “read from right to left”. In other words, the const-on-the-right style always puts the const on the right of what it constifies”. When…

SZ and RZ on MAC OS

Summary In this post, I will introduce how to send files from a server to a local machine. Details 1. Use SCP SCP is a well-known command. scp a.zip fighternan@mydestop.com: 2. Use Iterm and SZ&RZ Install Iterm Iterm with tmux helps me a lot. Install lrzsz in the server and the desktop. sudo brew install…

References Versus Pointers

Summary In this post, I will discuss when to use References and when to use Pointers in C++. Conclusion As usual, I present the conclusion first. 1. If the varible can be nullptr, declare the varible as a pointer; 2. If the you want to re-assign the varible, declare the varible as a pointer; 3….

Class not Declared in Scope with .h Included

Summary I come across a compiling error, in which it says class A was not declared. However, I actually include A.h. Details After some research, I find out the bugs. In utils.h, I want to use some static member varible in class A and thus I include A.h. However, since utils.h acts as its name,…

Ping a Specific Port of a Host

Summary In this post, I will introduce how to “ping” a specific port in a host. Details Usually to test the connectivity, we will use the command ping. However, ping will typically send ICMP ECHO_REQUEST packets to network hosts. In ICMP, there are no ports. But in many cases (especially when we have a server…

Moving a Return Value is Easy

Summary In this post, we will discuss rvalue references and move semantics in C++11. Details Rvalue references and move semantics can be very complex, see this article. But the truth is that: the simplest is the best. It starts with three examples of returning values from functions. Read them and ask yourself which of them…

Search Files Under a Directory in C++

Summary In this post, I will introduce how to get a vector of files in a directory in C++. Instead of filesystem in boost or C++ 17, this method is purely based on C++ 11 and Unix platforms. Details The following codes are self-explained. // safe path join in unix-based system string path_join(const string& p1,…

Redirect or Return Views

Summary In this post, I will discuss how to choose one from the other between redirection and returning views. Details I come across a confusion that when a user click a button, should I use redirection or returning views. After researching, I figure out the difference between the two. Return Views Return a view in…

Implement Java String APIs in C++

Summary It is another post related to String in C++. I will introduce some useful codes which implement APIs in Java String. Content String.startsWith() String.endsWith() String.toLowerCase() String.toUpperCase() String.trim() Detials 1. String.startsWith() We implement a.startsWith(b) of java using C++. bool starts_with(const string & a, const string & b) { return b == a.substr(0, b.size()); } int…

Lvalues and Rvalues in C++

Summary In this post, I will introduce lvalues and rvalues in C/C++. But I leave rvalue references and move semantics to the next post. Details Definition Lvalues: (locator value) represents an object that occupies some unique location in memory (has an address in some scope). Rvalues: not lvalues. Important points and examples 1. Rvalues can’t…

Delegating and Inheriting Constructors

Summary In this post, I will show delegating constructors introduced in C++ 11. Details I come across the codes below, and get confused about the systax. class Iterator { struct Data; Data* data; public: Iterator(const vector<int>& nums); Iterator(const Iterator& iter); virtual ~Iterator(); int next(); bool hasNext() const; }; class PeekingIterator : public Iterator { private:…

Change Object While Iterating It

Summary In this post we will discuss how to change object while iterating it. Details Say we have a map. unordered_map<char, int> char_counter ({{‘1’, 1}, {‘a’, 1}, {‘b’, 2}, {‘c’, 3}}); Now, we want to delete all elements whose value is 1. To delete an element using iterator we will use erase() function. But the…

Syntax Sugar in C++

Summary In this post, I will introduce some syntax sugar in C++. Content 1. Initializer List Constructor 2. Range in Container Construtor 3. Copy Constructor Details 1. Initializer List Constructor vector<int> vec({1,2,3,4,5}); unordered_map<char, int> char_counter ({{‘a’, 1}, {‘b’, 2}, {‘c’, 3}}); The syntax below is also legal. // use {} in vector vector<int> nums =…

String in C++

Summary In this post, I will introduce the string class in c++ STL. It covers useful APIs and some of my recommendations. 1. Split 2. Access 3. Comparison 4. Numeric-Conversions Details Split Thanks to this post, we present the conlusions for split first. 1. If you have access to boost, please do Solution 1. 2….

Bookmarks for C++

Summary In this post, I will show some useful websites for C++ learning. The post will be updated from time to time. URLs fluentcpp A great website focused on writing expressive C++ codes developed by Jonathan Boccara. Updated every Tuesday and Friday. Petr Zemek’s Blog A private website by Petr Zemek. Simplify C++ Another great…

Auto Type

Summary In this post, I will introduce auto, const auto, auto&, const auto&, auto&&, and const auto&&. Conclusion We provide the conclusion first. When you want a read-only access (generic or non-generic codes), use auto const &, which will give you a reference rather than a copy. When you want a read-write access in generic…

Common Mistakes in C++

Summary This post will be updated from time to time. The post contains some mistakes that I will make in work and study when coding in C++. Contents container.size() – 1 when the container is empty negative % positive ‘+’ does work in “C_String” remember to delete after new to_string(‘a’) signed integers compared to unsinged…

Auto in C++

Summary In this post, I will introduce auto and decltype in C++ 11. Why Auto In some situations, auto makes codes more readable. It will tell the compiler to deduce the type of a declared variable from the initialization expression. The details are complex. At present, we want to make codes correct, clean, and simple….

Ordered Containers

Summary In this post, I will introduce the map and priority_queue in c++ STL. Why Ordered Containers Unlike the easy version unordered_map, in map, key values are generally used to sort. Thanks to the binary search tree, map has good performance in search and erase elements $(log(n))$. Constructor The following codes are self-explained. // Example…

Intel Threading Building Blocks

Summary In this post, I will introduce how to solve a parallel computation task using Intel Threading Building Blocks. Problem In the deep learning platform, given inputs contains several thousand images, we want to analyze the data path of a certain deep learning model. The analysis part of each image is identical, for example, we…