Sparse files are common in Linux/Unix and are also supported by Windows (e.g. NTFS) and macOSes (e.g. HFS+). Sparse files uses storage efficiently when the files have a lot of holes (contiguous ranges of bytes having the value of zero) by storing only metadata for the holes instead of using real disk blocks. They are
Read more
Author: Eric Ma
Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.How to Add a File Based Swap for Linux
Posted onWe may want to add some swap space for a Linux box while only find that all disk space is partitioned and mounted. Some partition has large available free space. For such cases, we may not want to change the partition allocation. The solution may be to add a file based swap for Linux as
Read more
How to decode a quoted URL in Python?
Posted onHow to decode a quoted URL in Python? For example, an quoted URL as follows https://www.example.com/tag/%E9%93%B6%E8%A1%8C/ should be decoded to https://www.example.com/tag/银行/ In Python 3, we can use `urllib.parse_plus()` (for URL only). One example is as follows. $ python3 Python 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0] on linux Type “help”, “copyright”, “credits” or “license”
Read more
How to produce a patch file for a specific git commit?
Posted onHow to produce a patch file for a specific git commit so that the changes in that commit can be emailed/sent? git show 550a38b52 generate a quite close content while it is not exactly a patch. You can use this command git format-patch -1 550a38b52 It will generate a file like 0001-<commit-title>.patch in the current
Read more
How to not use concrete types in lambda function parameters in C++11?
Posted onC++11 requires that lambda function parameters be declared with concrete types. This is sometimes annoying. auto is really nice, especially when the type is complex like std::vector<std::string>::iterator is quite long to type. I know C++14 allows auto in lambda functions. But how to not use concrete types in lambda function parameters in C++11? In C++11,
Read more
Checking Whether a String Starts with Another String in C++
Posted onIn many text processing tasks, we often need to check if a given string starts with a specific substring. In this article, we will demonstrate how to achieve this using the std::string::compare() function from the C++ Standard Library. The compare() function has several overloads, but the one of interest for our purpose is: int compare(size_type
Read more
How to split and iterate a string separated by a specific character in C++?
Posted onHow to split and iterate a string separated by a specific character in C++? For example, “a string separated by space” by ‘ ‘=> [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” by ‘,’ => [“a”, “string”, “separated”, “by”, “comma”] C++ standard library’s getline() function can be used to build a function. getline() can accept a
Read more
Hiding Private IP from Email Headers in Thunderbird
Posted onIt seems Thunderbird sends out my private/lan IP to the SMTP server. For example, in an Email sent out by Thunderbird, the header contains Received: from [192.168.1.2] (example.com [1.2.3.4]) by mail.example.com (Postfix) with ESMTPSA id 92CD297DEA; It is fine that the SMTP server records the public IP (1.2.3.4) as it is what it sees. But
Read more
How to make Vim indent C++11 lambdas correctly?
Posted onVim seems not indent C++11 lambas very well. How to make Vim indent C++11 lambdas correctly? For this following program, Vim indents it as #include <iostream> #include <string> #include <vector> #include <algorithm> int main () { std::vector<std::string> strs({“one”, “two”}); std::vector<std::string> newstrs; std::transform(strs.begin(), strs.end(), std::back_inserter(newstrs), [](const std::string& s) -> std::string { if (s == “one”) {
Read more
How to operator[] access element in a const map in C++?
Posted onHow to operator[] access element in a const map in C++? For example, the compiler will report error on this piece of code: #include <iostream> #include <string> #include <map> std::int64_t count(const std::map<std::string, std::int64_t>& map) { return map[“one”] + map[“two”]; } int main () { std::map<std::string, std::int64_t> map = { {“one”, 1}, {“two”, 2} }; std::cout
Read more
How to enable Email address auto completion in Evolution?
Posted onDoes Evolution support automatic email address filling/completing in the “To” or “CC” fields which is commonly seen in other Email clients such as Thunderbird. Is is possible and how to enable Email address auto completion in Evolution? Evolution supports the contact autocompletion. To enable it, do as follows in Evolution. In Evolution Preferences dialog, in
Read more
Making Evolution Not Wrap Lines in Composed Emails
Posted onEvolution seems wrap long lines automatically in “Plain Text” mode. How to make Evolution not wrap lines in composed Emails? Evolution does not have (so far) “Flowing Text” mode where “the text is soft broken at the composer edge, but those soft breaks aren’t translated to hard breaks when the mail is sent” ( Reference:
Read more
How to list start and end sectors of a partition by parted in Linux?
Posted onHow to list start and end of a partition by the sectors in parted on Linux? The default behavior seems be listing the start and end by bytes in parted. # parted /dev/sdc print Model: Innostor IS888 ext. HDD (scsi) Disk /dev/sdc: 2000GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End
Read more
How to apply the Email sort order to all folders in Evolution?
Posted onEvolution’s default Email sort order is not very convenient, at least to me. How to apply the settings of sort order for a folder to all folders in Evolution? Manually setting the email sort order for each dir is tedious. Evolution has a function to “apply the same view settings to all folder” so that
Read more
How to check CPU working frequency in iOS on iPhone?
Posted onHow to check CPU working frequency in iOS on iPhone, such as my iPhone 6? The Litum Info Lite free app (Litum Info full version app) can show you the info of CPU including its frequency. The CPU frequency: You can find the CPU info page from the menu:
How to unignore some files or dirs in git?
Posted onI set up rules to ignore all files under git by adding a .gitignore like * But how to unignore some files or dirs in git? For example unignore all files under ./bin/tool1/ under the git repository. You can use patterns with ! as the prefix to “unignore” files. From gitignore man page: An optional prefix “!”
Read more
How to get a path’s mtime in C++ on Linux?
Posted onHow to get a path’s mtime in C++ on Linux? The path can be a file or a dir. You may call the standard library function lstat() for the file or dir under the path. int lstat(const char *pathname, struct stat *statbuf); From the returned stat struct, there is a field st_mtim which is the
Read more
How to remove newline characters from a string in C++?
Posted onHow to remove newline characters from a string in C++? For example, a string like line 1 line 3 line 4 should be converted to line 1line 3line 4 Method 1: use `erase()` and `remove()` In short, use this code snippet: input.erase(std::remove(input.begin(), input.end(), ‘\n’), input.end()); std::remove() shifts all elements that are equal to the value
Read more
How to test whether a given path is a directory or a file in C++?
Posted onHow to test whether a given path is a directory or a file in C++? For example, pathtype(“/”) –> “a dir” pathtype(“/tmp/file.txt”) –> “a file” # if there is a file file.txt pathtype(“/tmp/dir.txt”) –> “a dir” # if there is a dir named dir.txt The type of a file/dir can be found out using lstat()
Read more
How to change the default target of `make`?
Posted onThe default target of make is the first target. But can I change the default target in Makefile and how to change the default target of make? The default goal of make is the first target whose name does not start with ‘.’ if .DEFAULT_GOAL is not set. Ref: make manual. To set the default
Read more