C++ std::any is a type-safe container for single values of any type. It is useful to put multiple types into a single container such as std::vector which requires all elements stored have the same “type”. It is a part of the C++17 standard library. This blog post will take a close look at a certain
Read more
Category: Programming
Tutorials and tips on programming related to Linux systems, Web and more.
Resource Acquisition Is Initialization (RAII) in C++ with Detailed Examples
Posted onIn this post, we will discuss Resource Acquisition Is Initialization (RAII), a programming idiom in C++ that helps manage resources such as memory, file handles, and network connections. By leveraging constructors, destructors, and scope-bound resource management, RAII enables the creation of more reliable and maintainable C++ code. RAII can not only achieve mostly what a
Read more
Run-Time Type Identification (RTTI) in C++ with Detailed Examples
Posted onIn this post, we will discuss Run-Time Type Identification (RTTI) in C++, a feature that allows us to obtain type information for objects at runtime. We will explore how RTTI works, its applications, and provide detailed examples to demonstrate its usage using snake_case naming convention. What is Run-Time Type Identification (RTTI)? Run-Time Type Identification (RTTI)
Read more
Visualizing CMake Project Dependencies with Graphviz
Posted onWhen working on a large-scale C++ project with multiple dependencies, it can be challenging to understand the relationships between different components and libraries. Thankfully, CMake provides a nifty feature to visualize these dependencies using Graphviz, a widely-used open-source graph visualization software. Using CMake’s –graphviz option and the dot command from Graphviz is a powerful way
Read more
Splitting a String by Another String in C++: A Flexible Utility Function
Posted onIn this post, we will explore a flexible utility function for splitting a string based on a given delimiter using C++ and the standard library. This allows us to break down complex strings into smaller parts that are easier to process and manipulate. The C++ Utility Function to Split a String by Another String Background:
Read more
Why std::vector is the Optimal Choice for Data Structures for Performance in C++
Posted onIn C++ programming, data structures are essential for organizing and manipulating data. When it comes to storing and manipulating data, one data structure stands out above the rest – the std::vector. Efficient Memory Allocation One of the primary benefits of std::vector is its efficient memory allocation. std::vector uses contiguous memory allocation, which means that the
Read more
Sorting Two Lists Together According to The Order of One List in Python
Posted onWe may use two lists to store the values of two properties of a list of elements in Python. Under such data structure arrangement, when we need to sort the properties from one list, we may want to also make sure the other list will be also re-ordered following the same order as the first
Read more
Reading JSON from URL in R
Posted onR is good at analyzing data. Many data are provided as JSON from RESTful APIs with an URL. R natively support many data format. For JSON, we can use some libraries. For reading JSON from URL, we can use the “jsonlite” package. In this example, we use an example of fetching BTC prices of last
Read more
Reading Excel xls/xlsx Files in R
Posted onMany useful data are stored in Excel xls or xlsx format files. R is good at doing analysis on top of data. We would then need to import the data to R by reading the xls/xlsx files to be R data frames. In this post, we check how to import data from Excel files to
Read more
Converting Hex to ASCII Using xxd
Posted onStrings are commonly encoded as hexadecimal (hex) strings for various purposes. Hence, it is also common to convert hex strings to its original strings such as an ASCII string. Hex to ASCII string conversion can be done programmatically in many languages. In command line, we can use xxd to convert hex to ASCII string. This
Read more
Generating RSA Private and Public Key Pair in Go Lang?
Posted onHow to generate a pair of RSA private and public key in Go lang? Go lang has a rich set of standard libraries. Using Go’s standard libraries, we can generate RSA private and Public keys. The Crypto standard libraries in Go lang Go lang standard libraries has a rich set of cryptography functions. Here are
Read more
2 Ways of Resetting All Git Submodules in a Git Repository
Posted onGit submodule is a nice and convenient mechanism in Git to include the other Git repositories and manage the version/commit used from the submodule Git repository. However, there are cases where we would like “reset” the submodule, such as when we find updating a submodule repository will break the code tree, or merge some updates
Read more
Converting Int to String in C++
Posted onIt is common to convert an integer (int) to a string (std::string) in C++ programs. Because of the long history of C++ which has several versions with extended libraries and supports almost all C standard library functions, there are many ways to convert an int to string in C++. This post introduces how to convert
Read more
Installing R and RStudio Desktop in Ubuntu Linux
Posted onWe ever discussed How To Install R and RStudio Server in Ubuntu Linux 20.04. If the purpose is to install a local RStudio IDE instead of a remote RStudio Server, we can install RStudio Desktop. In this post, we introduce how to install R and RStudio Desktop on Ubuntu Linux 20.04. For other Ubuntu version,
Read more
Installing R and RStudio Server in Ubuntu Linux
Posted onR is a language and environment for statistical computing and graphics, providing a wide variety of statistical and graphical techniques. The R environment is open source software under GPL. R has rich software packages and is widely used for statistical analysis. RStudio Server is an R integrated development environment (IDE) that provides many useful features
Read more
Linux Kernel: fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek
Posted onThis change “fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek” (commit 06222e4) in Linux kernel is authored by Josef Bacik <josef [at] redhat.com> on Mon Jul 18 13:21:38 2011 -0400. Description of “fs: handle SEEK_HOLE/SEEK_DATA properly in all fs’s that define their own llseek” The change “fs: handle SEEK_HOLE/SEEK_DATA properly in
Read more
How to Count the Number of Words in a File in PHP?
Posted onCounting the number of words in a file is useful in many programs. In this post, we will discuss how to count the number of words in a file in a PHP script. In PHP standard library, we have function str_word_count($str) which returns the number of words from a string $str. On the other hand,
Read more
4 Features of Python 3.9 That You Can’t Take Your Eyes Off
Posted onPython is one of the most popular programming languages in the world. It is widely popular for a plethora of tasks due to its flexible nature and ease of use. Python has also managed to beat other programming languages such as Java, which were once upon a time, the world’s favorite. In fact, the extent
Read more
Add Inline Comments for Multi-line Command in Bash Script
Posted onIn Bash script, it is common that multiple small commands run together connected by pipes (|) and the whole command is quite long. For clarity, we may write the command in multiple lines. How to add comments for these long multi-line commands? In Bash, the content after # in a line is the comment. Using
Read more
How to Match Multiple Lines using Regex in Perl One-liners
Posted onPerl one-liners with perl’s regular expression statement can be a very powerful text processing tools used as commands in a terminal or a script. By default, the input to the perl one-liner with -p or -n options is passed line by line. However, when we want to match multiple lines, it gets us some trouble.
Read more