Tuesday, May 31, 2022

JavaScript Abort Signal & Semaphore

Abort Signal

The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort it if required via an AbortController object.

fetch returns a promise. And JavaScript generally has no concept of “aborting” a promise. So how can we cancel an ongoing fetch? E.g. if the user actions on our site indicate that the fetch isn’t needed any more.

There’s a special built-in object for such purposes: AbortController. It can be used to abort not only fetch, but other asynchronous tasks as well.

“abort” enables sending a signal to an awaited function to stop processing, i.e. in case the API response takes a while to finish and connection is closed by client (i.e. UI cancel button or similar).
In such case it is useful to stop sub-processing.Potentially long running processing could benefit from being able to receive such “signal”.

With node.js version 18 the message can also include “reason”, so it has almost perfect symmetry with “throw error”. Throw can send custom error object “up the caller stack”, while “abort” can send message “down the stack”. It could be useful.

an alternative, open source library

Semaphore @GitHub

A promise-based semaphore implementation suitable to be used with async/await.

This package can be used to synchronize functions that span multiple iterations of the event loop and prevent other code from being executed while your function is waiting.

good podcast discussion and links:

Google Analytics alternative that protects your data and your customers' privacy

Take back control with Matomo – a powerful web analytics platform that gives you 100% data ownership.

WAPM: WebAssembly Package Manager (!)


introduction to wapm (webassembly package manager) tutorial using wasmer, assemblyscript and as-wasi - YouTube

by Chris Hay

"WAPM is a package manager for WebAssembly created by the folks at WASMER. Think of it as npm but for webassembly. In this video we explore the various features of WAPM and how you can use WASM modules on the online playground and how to install wasm modules locally using WAPM. In addition we get underneath and look at how WAPM packages up the modules and show how it can be used by both wasmer and wasmtime runtimes. In addition, we create and publish our own WAPM package with our own WebAssembly (WASM) module using assemblyscript. We create a simple hello-world program that outputs hello world to the console using WASI (WebAssembly System Interface) and as-wasi. WASI allows you to access console, environment and filesystem from webassembly using extensions. Finally we package our application and publish it to the wapm.io registry."

Monday, May 30, 2022


Postgres.js with Rasmus Porsager (JS Party #221) |> Changelog podcast    

Postgres.js –the fastest full-featured PostgreSQL client for Node.js and Deno.
// users.js
import sql from './db.js'

async function getUsersOver(age) {
  const users = await sql`
    from users
    where age > ${ age }
  // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
  return users

NewSQL: Vitess (PlanetScale DB), CockroachDB, ...

NewSQL is a class of relational database management systems that seek to provide the scalability of NoSQL systems for online transaction processing (OLTP) workloads while maintaining the ACID guarantees of a traditional database system.

NewSQL — The Next Evolution in Databases | by Gokul Prabagaren | Capital One Tech | Medium

TiDB, CockroachDB, FaunaDB, Vitess (PlanetScale)

"NewSQL promises to combine benefits from RDBMS (strong consistency) with benefits from NoSQL (scalability); it mainly achieves this through new architecture patterns and efficient SQL storage engines.

Most current NewSQL databases are based on Google’s Spanner database and the theories in academic papers such as Calvin: Fast Distributed Transactions for Partitioned Database Systems from Yale. Spanner is Google’s scalable, multi-version, globally-distributed, and synchronously-replicated database. It was the first system to distribute data at global scale and support externally-consistent distributed transactions. The Calvin academic paper from Yale was on leveraging determinism to guarantee active replication and full ACID-compliance of distributed transactions without two-phase commit.

TiDB, CockroachDB, FaunaDB, Vitess are a few of the leading NewSQL databases. Each database implementation has its own take on how to ensure strong consistency with scalable architecture. Let’s dive into them."

interview with PlanetScale CEO, that also worked in GitHub

Based on Vitess created by Google for YouTube MySQL DB sharding, in GoLang
originally running on Borg and now on Kubernetes. 

Interesting innovation: "db branches" with ability to "revert back"

Vitess is a database clustering system for horizontal scaling of MySQL through generalized sharding.

5 GB storage
1 billion row reads/mo
10 million row writes/mo
1 production branch
1 development branch

interesting & useful feature
PlanetScale Rewind - Zero Downtime Reverts

PlanetScale - Crunchbase Company Profile & Funding

PlanetScale builds a database-as-a-service offering on Vitess,
an open source sharding middleware system for MySQL.

Is there a similar service for Postgres DB?

CockroachDB is also written in GoLang, and it supports PostgreSQL

Sunday, May 29, 2022

C: Language => OS API protocol ?

 C Isn't A Programming Language Anymore - Faultlore

C is the lingua franca of programming. We must all speak C, and therefore C is not just a programming language anymore – it’s a protocol that every general-purpose programming language needs to speak.

If you want programs written in your language to be good citizens that work well with the major operating systems, you need to interact with the operating system’s interface.

Rust and Swift cannot simply speak their native and comfortable tongues – they must instead wrap themselves in a grotesque simulacra of C’s skin

The simplest local web file server

How do you set up a local testing server? - Learn web development | MDN

with Python (3.x) installed on the computer, it is just one command:

> python -m http.server

By default, this will run the contents of the directory on a local web server, on port 8000. You can go to this server by going to the URL localhost:8000 in your web browser. Here you'll see the contents of the directory listed — click the HTML file you want to run.

On Mac computers may need to use `python3` command instead of  `python`

To run server of different port, just add port number to the command, i.e. for port 9000

> python3 -m http.server 9000 

When using node.js / npm, there is also a web server module, that can be installed "globally"

> npm install http-server -g
and then to can use it in any folder/directory

> cd D:\Folder
> http-server
> http-server D:\Folder
> http-server -a localhost -p 8080
http-party/http-server: a simple zero-configuration command-line http server @GitHub

and to make your own, self-sufficient (no dependencies) exe, GoLang may be the simplest way to go :)

Serve is a very simple static file server in go
  -p="8100": port to serve on
  -d=".":    the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
package main
import (
func main() {
  port := flag.String("p", "8100", "port to serve on")
  directory := flag.String("d", ".", "the directory of static file to host")
  http.Handle("/", http.FileServer(http.Dir(*directory)))
  log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
  log.Fatal(http.ListenAndServe(":" + *port, nil))

of course, then you need Go SDK installed, and need to build with

> go build web_srv.go

then run, with no dependencies on any compatible machine (same OS and CPU type)
> web_srv

to reduce exe size from about 6 MB to about 4MB, remove debug info when compiling
> go build -ldflags "-w" web_srv.go

Friday, May 27, 2022

Dell = VMware => Broadcom

Chipmaker Broadcom to buy cloud services firm VMware in $61 billion deal - CNN

Chipmaker Broadcom (AVGO) is buying cloud services provider VMware (VMW) in a cash-and-stock deal valued at $61 billion to speed up its expansion into the enterprise software business.

Software became a substantial part of Broadcom's business after it acquired CA Technologies for $18.9 billion in 2018 and Symantec's security division for $10.7 billion in 2019.


Because "Broadcom" is not really a chip maker, it is mostly a "brand name" used by technology investors... a successor of HP... 

The company that would later become Broadcom Inc. was established in 1961 as a semiconductor products division of Hewlett-Packard.[9] The division separated from Hewlett-Packard as part of Agilent Technologies in 1999

math, code: Knight's tour

Knight's tour - Wikipedia

knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. If the knight ends on a square that is one knight's move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed (or re-entrant); otherwise, it is open.

The knight's tour problem is the mathematical problem of finding a knight's tour. Creating a program to find a knight's tour is a common problem given to computer science students.

chess Knight's tour - Rosetta Code

Thursday, May 26, 2022

Azure Bicep + ARM vs Terraform vs Pulumi vs AWS CDK + CloudFormation

The "problem" of "Infrastructure as a Code" is that
most in most of current solutions the "code" is actually configuration, 
a simple while custom JSON and YAML.

That does not have expressiveness of a "proper" programming language:
they are not "Turing complete", even with extensions.

The new modern solutions like Pulumi are solving problem by embedding "infrastructure"
as libraries to existing programming languages, 
or like in case of Terraform by a new "DSL" : domain specific language.

AWS has opted to leverage existing programming languages, 
starting from TypeScript as a "base" for code generation,
and using CloudFormation (JSON/YML) as the target.

Azure has opted to create DSL "Bicep" pre-processor for generating JSON ARM,
using custom "purified" and extended syntax, i.e. by adding params, ifs, loops etc.
Bicep is open source, written in C#, the most common language of Microsoft Azure.

So both provide benefit of simplification of syntax, 
while in both cases essential knowledge of underlying platforms is still required.

And unfortunately in all mentioned cases, as well as with all modern programming languages
the transformations tooling is custom, and limited to one or few languages and planforms.

 Azure/bicep: Bicep is a declarative language for describing and deploying Azure resources

Azure Bicep March 2021: Learn everything about the next generation of ARM Templates - YouTube

Infrastructure as Code - An intro - Part 4 - Using Bicep

Infrastructure as code in 2021 - DEV Community

How Azure Bicep is Different. How emerging technologies solve classic… | by Yi Lu | Slalom Build | Medium

The Bicep DSL is an enhancement of JSON configuration language. It introduces some flow-control elements such as loops, ternary operators and one-line resource references, yet it stops short of classes or inheritance. The enhanced syntax greatly improves functionality and reduces code size, at the cost of mildly increased complexity. As an Azure-native technology, Bicep also has two advantages over approach one: day-zero support and no maintenance of state files.

Bicep (name is play on ARM)

param location string = resourceGroup().location param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}' resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = { name: storageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' properties: { accessTier: 'Hot' } }

Result: ARM JSON

{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "", "parameters": { "location": { "type": "string", "defaultValue": "[resourceGroup().location]" }, "storageAccountName": { "type": "string", "defaultValue": "[format('toylaunch{0}', uniqueString(resourceGroup().id))]" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-06-01", "name": "[parameters('storageAccountName')]", "location": "[parameters('location')]", "sku": { "name": "Standard_LRS" }, "kind": "StorageV2", "properties": { "accessTier": "Hot" } } ] }

param deployZone bool resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = if (deployZone) { name: 'myZone' location: 'global' }

param itemCount int = 5 var stringArray = [for i in range(0, itemCount): 'item${(i + 1)}'] output arrayResult array = stringArray

Microsoft Build 2022

Microsoft Build May 24–26 202

Wednesday, May 25, 2022

Azure Bicep vs Terraform vs Pulumi

 Comparing Infrastructure-as-Code with Chris Klug @.NET Rocks! vNext podcast

 Fixing Logging Issues in ASP.NET Bicep Terraform Pulumi Azure Key Vault Soft Delete Farmer

Bicep is a Domain Specific Language (DSL) for deploying Azure resources declaratively. It aims to drastically simplify the authoring experience with a cleaner syntax, improved type safety, and better support for modularity and code re-use. Bicep is a transparent abstraction over ARM and ARM templates, which means anything that can be done in an ARM Template can be done in Bicep

Tuesday, May 24, 2022

Learning Patterns, free book: web, react

Patterns.dev - Modern Web App Design Patterns

Optimized for React developers

React-specific design patterns and their possible modification and implementation using React Hooks.

A focus on Web Performance
...and many more Web Performance patterns and optimizations that can help improve your modern web app!.

Hanselminutes Technology Podcast - Fresh Air and Fresh Perspectives for Developers - Patterns.dev with Lydia Hallie and Addy Osmani

Learning Patterns : Lydia Hallie and Addy Osmani : Free Download, Borrow, and Streaming : Internet Archive

Lydia Hallie | Talks | Rendering Patterns