How to divert connection or packet before routing decision entering the default

Posted on

before the packets ports (443) entering the firewall i would like to divert incoming packet of server (443) to input chain goes to FORWARD chain<br> so thats the incoming packets 100.43.xx.xx –sport 443 are send it to FORWARD instead of input chain<br> how to configure this in OUTPUT,FORWARD,POST AND PREROUTING CHAIN and this is my
Read more

How to get the full path and directory of a Python script itself?

Posted on

In a Python script, how to get the full path and directory of the Python script itself? To get the path of the current file (the script itself), you can use __file__. To resolve any symbolic links in the path, you can use os.path.realpath(). Putting them together, you can do os.path.realpath(__file__) to get the full
Read more

How to improve video rendering quality in MPlayer

Posted on

MPlayer has lots options for video rendering and filtering. Any suggestions on good MPlayer options that improve video rendering quality nicely? My ~/.mplayer/config is as follows with 2 profiles: [fast] vf=eq2 [default] vf=hqdn3d vo=gl:yuv=3:lscale=5:cscale=5 ao=pulse The default one gives good video quality by using the hqdn3d video filter while the CPU usage is high. If
Read more

How to configure /dev/shm size of Linux?

Posted on

/dev/shm is a nice in memory disk on Linux. The default size seems half of the physical memory’s size. How to configure shm size of Linux? And what’s the consequence? To change the configuration for /dev/shm, add one line to /etc/fstab as follows. tmpfs /dev/shm tmpfs defaults,size=8g 0 0 Here, the /dev/shm size is configured
Read more

How to exclude a package from a specific repository only in yum?

Posted on

This post https://www.systutorials.com/1661/making-dnf-yum-not-update-certain-packages/ introduces how to exclude a package from yum. But is it possible to exclude a package from a specific repository only? For example, a repository R1 I am using contains an updated version of gdb while I don’t want to use the gdb from it as I trust the version (although older)
Read more

How to resize a virtual disk of KVM

Posted on

I test it for qcow2 format. Other formats are TBA. qemu-img resize kvm1.qcow2 +20G cp kvm1.qcow2 kvm1-orig.qcow2 virt-resize –expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2 Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/ I test it for qcow2 format. Other formats are TBA. qemu-img resize kvm1.qcow2 +20G cp kvm1.qcow2 kvm1-orig.qcow2 virt-resize –expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2 Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/

How to create a file if not exist and open it in read and write modes in C++?

Posted on

How to create a file if not exist and open it in read and write modes in C++? For example, I would like open a fstream on /tmp/cache to be able to read it and append to it. If the file does not exist yet, create one. A simple code like std::fstream fs(“/tmp/cache”, std::ios::in |
Read more

How to not use concrete types in lambda function parameters in C++11?

Posted on

C++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 on

In 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 generate a password in Shell on Linux?

Posted on

Admins usually need to generate some passwords for others, such as when creating a new user in a Linux system. How to generate a password in Shell on Linux? Several possible and short methods. Here, we generate a password of length 8. Using pwgen: $ pwgen 8 1 dao3PaW9 Password based on base64 (note that
Read more

`readlink -m` equivalent function in Python to get canonical file name

Posted on

readlink -m can get canonical file name by resolving every symlinks in every component of the given path recursively. In Python, the os.readlink() function does not do so. Any equivalent function in Python to the readlink -m command line? Specifically, it does: canonicalize by following every symlink in every component of the given name recursively,
Read more

How to operator[] access element in a const map in C++?

Posted on

How 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 make Vim indent C++11 lambdas correctly?

Posted on

Vim 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