Posts

Oclif - Delegate / Wrap Existing CLI Commands

CLI Wrap with Spawn and Programmatic Access

Oclif is a Nodejs command line generator tool that grants you the ability to conveniently create a CLI with the following

npx oclif single mycoollistofthings

Supposedly you have your own custom CLI, but you wish to delegate some of these commands to an existing CLI tool. You are then wrapping another CLI command for the intent of adding additional functionality with mycoollistofthings. Here is the new command's mapping behavior of the ls -r command.

npx mycoollistofthings -r
Categories: #shell #typescript
Tags: #NodeJs
Playwright - Cleaner Promise Chains

Fluent API

As with many JavaScript libraries, asynchronous operations are dealt with using promises, and the commonly preferred way of structuring promises flows entails the use of async / await.

From the Playwright documentation

const { webkit } = require('playwright');

(async () => {
  const browser = await webkit.launch();
  const page = await browser.newPage();
  await page.goto('http://whatsmyuseragent.org/');
  await page.screenshot({ path: `example.png` });
  await browser.close();
})();

Every page operation will require the use of an await since each yields a promise. However, this simple example shows the extra effort needed to tame async control flow by having to prepend each operation with an await. This is a bit noisy and detracts from the true intent of the tests steps.

Categories: #testing
Pandoc - LaTeX - Table of Contents

As a LateX document accumulates more content, navigating to a specific piece of information would be cumbersome if there was not an easy way to quickly jump to the area of interest. Providing a table of contents in the beginning of the document will greatly enhance the ability to find relevant data.

Categories: #shell #latex
Tags: #pandoc
RxJS - Library Picks #1

Rxdeep

For the easier determination of a value change inside a deeply nested object, use Rxdeep's state's output observable for wrapping an object to subscribe to the change events.

import { state } from 'rxdeep';
 
const s = state([ { name: 'John' }, { name: 'Jack' }, { name: 'Jill' } ]);

// Listen to changes on 'name' property of index 1 on the list:
s.sub(1).sub('name').subscribe(console.log);     // --> logs `Jack`
Categories: #JavaScript
Tags: #RxJS
Pandoc - Quick Tips #1

Render Full Html Site

By default, converting a LaTeX file into an HTML file only produces a partial HTML page. Pandoc conversion strictly contains the content wrapped in the basic HTML equivalent tags, which is spartan as the following example would only output a paragraph tag without a html, head, nor body tag available.

\documentclass{article}

\usepackage[margin=0.5in]{geometry}
\title{Tex}
\date{}

\begin{document}
\maketitle

some content

\end{document}

To fix this problem, the "full html" page requires the "-s" flag (standalone mode) to achieve the proper conversion.

pandoc -o 'my-output-file.html' 'my-input-file.tex' -s
Categories: #shell
Tags: #pandoc
Webpage Svg Screenshots

Accessible screenshots of web pages

Taking a screenshot on a webpage illustrates and preserves the layout information with accompanying text, however, taking a screenshot where the content is primarily text implies a lost of useful information because you can no longer select the text nor zoom into the image without significant quality lost as is the case with most commonly used image formats such as png and jpeg.

Categories: #browser
Tags: #svg
RxJS - Key Combination Detection

Hot Keys

A hot key combination such as "ctrl + shift + alt + a" could be used to trigger a behavior in a web application such as the opening of a dialog or panel. It also provides a convenient shortcut when an action is often repeated in a workflow. There are certainly many libraries out there designated for such a task, but if you are already using RxJS, it is flexible enough that this functionality can be replicated without using an additional library.

Categories: #JavaScript
Tags: #RxJS