Posts

Selenium - Python - Quick Tips #1

Webdriver Manager

Use the latest version of the web driver for your browser of choice when testing by installing the webdriver_manager package.

pip install webdriver-manager

The package will automatically download the newest version when tests are run with Selenium. This will relieve you of having to manually download the driver for inclusion in a folder while testing.

Categories: #testing #python
Tags: #selenium
Angular - Module for Routes

Organize Routes into Modules

In Angular, to make routing cleaner, routes may be defined inside modules to localize the path definition to where a specific component is associated.

Here, we have the "/useful/" route and nested child route of "/useful/stuff" defined for our "useful component".

//useful.module.ts

import { UsefulComponent } from "./useful.component";
import { NgModule } from "@angular/core";

import { RouterModule } from "@angular/router";
const routes = [
  {
    path: "",
    component: UsefulComponent,
    children: [{ path: "stuff", component: UsefulComponent }],
  },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
})
export class UsefulModule {}
Categories: #typescript
Tags: #Angular
TypeScript - Descriptive String Arrays

Strings from a Union Type

Often times, an array would contain one of many possible string values, and it would be expressed as such

interface BuildFlagsStatus {
  optionalArgsFlagKeys: Array<string>
}

However, this is a not very helpful approach because usually the string values allowed placement inside the array comes from a select group of strings.

To be more descriptive, create a string union type and use that for typing an array.

Categories: #typescript
Recording CLI Output

Take a Frame from an Asciicast Recording

Using asciinema is a convenient way to create an accessible recording of your terminal if you want to demo features of a CLI app because the output media permits you to select the text that actually runs in the asciinema player.

On occasions, you might be only interested in taking a screenshot of the recording when focusing one command. With the help of "svg-term-cli", a select frame from asciicast recordings can be exported to a svg file.

It is also helpful to record a series of steps on the CLI at a time as to not disrupt your train of thought when you are going through each CLI command intended for something like an instructional tutorial.

# Record your cast
asciinema rec my-super-amazing.cast
Categories: #shell
Tags: #svg
RxJS - Dependent Observable for Multiple Matches

Give Precedence to Greater Satisfied Criteria

Observables tend to be created from other observables through transformations by operators in a pipe. On some occasions, one observable is created from another, it creates a chain where you have the latter observable and initial observable both triggering when the initial base condition is met. However, there might be cases, where you would only want the latter observable to trigger because you want to find the observable which matches the most conditions.

Categories: #JavaScript
Tags: #RxJS
Snowpack - "Unbundler"

Configure a Snowpack Plugin

Snowpack is a frontend build tool that promotes itself as an alternative to Webpack because it uses new JS modules features, and the workflow is "unbundled" which skips the build steps during development to make for a faster workflow.

Snowpack has some sensible defaults which permits the import of commonly used asset files such as scss, .css, .svg in your JavaScript files.

Categories: #Tooling
Tags: #frontend
RxJS - Logical Operators

Logical Evaluation

In traditional JavaScript, one would use the logical operators "&&", "||", "!" when evaluating variables for the "and", "or", and "not" conditions respectively. Similarly, there are RxJS operators which looks like the ones found in JavaScript when you wish to treat observable like values that needs to be compared against one another.

For the examples below, "true" in this sense refers to the observable have "truly" emitted a value and not have it base upon the actual underlying value within the observable.

AND

Use the "forkJoin" operator when every single observable must be activated for the subscription to run.

// When the observables will emit at least once in any order

import { forkJoin, of, interval } from 'rxjs';
import { take } from 'rxjs/operators';

const timer$ = interval(1000).pipe(take(1)),
  truthfulness$ = of(true);

forkJoin([
  timer$,
  truthfulness$
])
.subscribe(() => {
  console.log('All completed once');
});

Alternatively, you might be able to use "combineLatest" when you have long-lived observables. Tangentially, "concat" or "zip" will work if a strict order needs to be imposed for activation of observables in a series.

Categories: #JavaScript
Tags: #RxJS