Convert PNG Images To WebP Images Losslessly Using cweb in GNU/Linux

Last updated on October 18, 2024

To losslessly convert a PNG image to a WebP image on GNU/Linux, run the following command:

cwebp -z 9 input.png -o output.webp

9 indicates the best effort to compress the image, resulting in the smallest image size. You can replace 9 with a smaller number if you prefer a less aggressive compression effort.

If you haven't installed cwebp yet, it is available in the webp package in Debian and Ubuntu.

View the TLS Certificate Details of a Website on the Command Line Using GnuTLS

Last updated on December 27, 2023

With GnuTLS, we can view the certificate details of a website with the following commands (replace "example.com" with the website of your interest):

gnutls-cli --print-cert example.com < /dev/null | certtool --certificate-info

In the command above, gnutls-cli --print-cert example.com < /dev/null prints the certificate of the website in PEM format to the standard output. Its output is then sent as the standard input to certtool --certificate-info, which prints information on the given certificate.

Continue reading

Platform Dependent Python Coverage Test with Tox

Last updated on December 20, 2020

When testing Python programs, coverage.py is often used in measuring code coverage, and enforcing 100% code coverage is regarded as a good practice:

# .coveragerc
[coverage:report]
# Enforce 100% coverage test
fail_under = 100
show_missing = True

However, if there are some lines of code that are platform dependent (i.e., they are never executed on at least one platform), code coverage tests usually fail. For example, the following code snippet would always lead to a coverage that is less than 100% on a platform other than Windows:

if os.name != 'nt':
    # Do something if the OS is not Windows...

You can ask coverage.py to ignore this block by adding a comment # pragma: no cover, but then coverage.py would ignore it on all platforms, including all non-Windows platforms. If you use tox for testing, this issue can be resolved cleanly.

Continue reading

5 Misconceptions Web Developers Believe About Mobile App Development

Last updated on October 29, 2020

Mobile apps have emerged as a competitive alternative to websites. Although websites are still irreplaceable parts of digital presence for business brands, mobile apps have been forcing them to change. The emergence of Progressive Web Apps (PWA) showcases this shift.

In spite of this overwhelming popularity of mobile apps, many web developers still hesitate to improve their skills and extend their focus on mobile app development. What misconceptions the web developers mostly harbor regarding app development? Well, this is what we are going to explain here.

Continue reading

Catching FileNotFoundError? Watch Out!

Last updated on October 3, 2020

In Python, FileNotFoundError is an exception that is raised when a requested file does not exist. Many people assume that when their programs fail to open a file in read-only mode or delete a file, FileNotFoundError must be raised and they should only need to process that. For example, some people would write code similar to:

def process_file(path):
    import sys

    try:
        f = open(path, 'r')  # or os.remove(path)
    except FileNotFoundError as e:
        print(f"File {path} not found!", file=sys.stderr)
        return
    # process the file...

However, this code may actually trigger unexpected errors. The reason is that, the failure to open a file in read-only mode or delete a file is not necessarily caused by the non-existence of the file. Very often, it's for different reasons: insufficient permission, or the file is a directory. In this case, PermissionError or IsADirectoryError would be thrown instead of FileNotFoundError. So, in the example above, one would want to catch all of them:

Continue reading