Any good debugger for Python that is like gdb so that the code can be executed step by step for debugging purpose? You might check pdb. You can debug a program such as prog.py by invoking it through pdb: python -m pdb prog.py Common gdb commands can be found in pdb: (Pdb) h Documented commands
Read more
Author: Q A
How to open a port in iptables?
Posted onHow to open a port, say 3389, in iptables to allow incoming traffics to it? There are several cases for this question: ipv4 or ipv6 or both, TCP or UDP or both and which interface? For simplicity, I give commands to allow all (ipv4 and ipv6, TCP and UDP from all interfaces) using port 3389
Read more
How to divert connection or packet before routing decision entering the default
Posted onbefore 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 check whether a file of a given path is a block device in Python?
Posted onHow to check and test whether a file of a given path is a block device in Python? This can be Linux specific. You can use the os.stat() function to get the stat of the path. Then use the stat.S_ISBLK() function against the stat’s .st_mode to test whether it is a block device. An example:
Read more
How to get the full path and directory of a Python script itself?
Posted onIn 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 test a file or directory exists in C++?
Posted onHow to test a path (a file or directory exists) in C++? In Bash, the [ -f ] and [ -d ] tests can test whether a file or a directory exist. What are the corresponding C++ ways for these tests? To test whether a file or dir (a path) exists, you may call stat()
Read more
How to turn off WiFi and bluetooth easily in iOS 11?
Posted onThe WiFi and bluetooth icons in iOS 11’s control center only disconnect the WiFi and Bluetooth connection being used while leave the WiFi and bluetooth enabled. This costs power. In the Settings app, the WiFi and bluetooth can be disabled totally. But the steps are tedious. How to rurn off WiFi and bluetooth easily in
Read more
How to improve video rendering quality in MPlayer
Posted onMPlayer 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 onThis 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 clean the commit history of a repository?
Posted onHow to clean the commit history of a repository in both of my locally cloned copy and the copy on the git server so that only the files after the last commit are left? git works in branches. Here, we assume removing the history of the master branch. One solution is doing as follows. Rename
Read more
How to escape the XML CData section ending sequence `]]>`?
Posted onHow to escape the XML CData section ending sequence ]]>? The ]]> sequence itself may be part of the content in a CData section. One solution is to split the ]]> token into 2 CData sections. <![CDATA[to split the ]]]]><![CDATA[> token ]]>
How to create a file if not exist and open it in read and write modes in C++?
Posted onHow 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 test whether a file exists and is a block special file in Python on Linux?
Posted onBash has a -b test to test whether a file exists and is a block special file. -b file True if file exists and is a block special file. How to do this in Python? Python’s stat module provides the similar functions for the C standard APIs and macros underlining such as stat() and S_ISBLK().
Read more
How to escape special characters in a Bash string in Linux?
Posted onThe problem is with ssh that makes a quoted string to more than one if there are spaces. For example, ssh user@host cmd “my string” The cmd on host will be executed like cmd my string rather than cmd “my string” It will only work if the string is escaped like ssh user@host cmd my
Read more
`readlink -m` equivalent function in Python to get canonical file name
Posted onreadlink -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 generate a password in Shell on Linux?
Posted onAdmins 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
How to split a string by string in Python?
Posted onHow to split a string by string in Python? For example, “a string separated by space” => [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” => [“a”, “string”, “separated”, “by”, “comma”] Python’s string.split() standard library function, if provided a separator, will split the string by the separator, for example >>> str2 = “a,string,separated,by,,,comma” >>> str2.split(“,”) [‘a’,
Read more
How to make iptables/ip6tables configurations permanent across reboot on CentOS 7 Linux?
Posted onHow to make iptables/ip6tables configurations permanent across reboot on CentOS 7 Linux? CentOS 7 uses FirewallD by default. If you would like to manage iptables/ip6tables rules directly without using FirewallD, you may use the old good iptables-services service which will load the iptables/ip6tables rules saved in /etc/sysconfig/iptables and /etc/sysconfig/ip6tables when it is started during boot
Read more
How to send a POST request in Go?
Posted onHow to send a POST request in Go? For example, send a POST of content like ‘id=8’ to a URL like https://example.com/api. In Go, the http package provides many common functions for GET/POST. Related to POST requests, the package provides 2 APIs: Post Post issues a POST to the specified URL. func (c *Client) Post(url,
Read more