Chrome at the Command-Line to Dump Website Structure

You can use Chrome to dump the DOM, PDF, or screenshot of a webpage, or do a number of other cool things:

https://developers.google.com/web/updates/2017/04/headless-chrome

Open a website in a Chrome process headless-mode, which you can then query from a client process or another browser:

$ chrome --headless --disable-gpu --remote-debugging-port=9222 https://www.chromestatus.com

Print the site HTML:

$ chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com

Capture a PDF:

$ chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com

Capture a PNG screenshot:

$ chrome --headless --disable-gpu --screenshot https://www.chromestatus.com

Open a REPL console in which to run JavaScript expressions against the DOM:

$ chrome --headless --disable-gpu --repl https://www.chromestatus.com
Advertisements

Use GPG to Quickly Encrypt at the Command-Line


$ echo "cleartext" | gpg --passphrase "some-passphrase" -c --no-use-agent > text.encrypted
$ cat text.encrypted | gpg --passphrase "passphrase" --no-use-agent 2>/dev/null
$ cat text.encrypted | gpg --passphrase "some-passphrase" --no-use-agent 2>/dev/null
cleartext

Without “–no-use-agent”, you might very well be prompted by some system keyring/agent every time.

Colored Logging in Python Under Jenkins

Setting-up the coloredlogs package is easy. Just install the coloredlogs package from PIP, import coloredlogs, and initialize like the following:

coloredlogs.install(isatty=True)

Note the isatty parameter. By default, coloredlogs detects whether or not you’re in a terminal and enabled ANSI output accordingly. This means that you won’t see ANSI output in Jenkins unless you explicitly pass True.

Make sure to check “Color ANSI Console Output” in your job config. Using “xterm” for “ANSI color map” worked fine for me.

As this will add another handler to the logging, you may see duplicate logging if you have any other handlers.

For more information on configuration, see the documentation.

Listing Available Package Versions in Ubuntu: The “Madison” Subcommand

There is an unlisted subcommand to apt-cache called “madison”. This will simply list all available versions:

$ apt-cache madison git
git | 1:2.11.0-2~ppa0~ubuntu14.04.1 | http://ppa.launchpad.net/git-core/ppa/ubuntu/ trusty/main amd64 Packages
git | 1:1.9.1-1ubuntu0.3 | http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
git | 1:1.9.1-1ubuntu0.3 | http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
git | 1:1.9.1-1 | http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
git | 1:1.9.1-1 | http://us.archive.ubuntu.com/ubuntu/ trusty/main Sources
git | 1:1.9.1-1ubuntu0.3 | http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main Sources
git | 1:1.9.1-1ubuntu0.3 | http://security.ubuntu.com/ubuntu/ trusty-security/main Sources

In all likelihood this will work under Debian, too.