DEV Community

John Paul Ada
John Paul Ada

Posted on • Edited on

This Week I Learned #7

This Week I Learned

Logic, Promises, NPM, PHP, ML, and a bunch of other acronyms in this episode of This Week I Learned!

This was originally posted on Medium.

De Morgan’s Laws

The rules can be expressed in English as:

  • the negation of a disjunction is the conjunction of the negations;
  • and the negation of a conjunction is the disjunction of the negations;

The De Morgan’s laws are a set of rules that allow us to transform a logic expression. I use these to make my boolean expressions simpler.

De Morgan's code

Testing the function in Chrome

Promise.notAll/Promise.allMost

Sometimes you need a list of Promises and you want them all to complete then return the array with the expected values. You’d usually use Promise.all for this in JavaScript, right? But what if one of the Promises rejects but you still want to get the ones that succeeded on their respective positions?

We encountered this problem so we built Promise.notAll! We also called it Promise.allMost (get it?) thanks to Kurt Jerome Obispo’s suggestion. Anyway, here’s the code for it.

Promise.notAll Code

And here's how you'd use it:

Promise.notAll usage

npm --

This enables you to add arguments to your call to an NPM script. For example, if you have an npm script called test and would like to add a verbose flag to it, then you can do:

npm run test -- --verbose
Enter fullscreen mode Exit fullscreen mode

npm audit

npm audit analyzes your dependencies and lists the vulnerable packages and their level of severity. You can even see the link to the security report on the vulnerable packages! This makes it easier to secure our node applications.

Ow

Ow

Ow! is a library for Function argument validation for humans built by the prolific Sindre Sorhus. It‘s batteries-included and has a great chainable API. You can also use create your own validator if you want! All in all, this would help you keep your code away from bugs and malicious input.

:: placeholder

Apparently you can style textbox placeholders! I didn’t know that. LOL. But apparently you can use the ::placeholder pseudoselector to select placeholders and style them with CSS.

ML .NET

ML .NET

Just install the Microsoft.ML package and enjoy the power of Machine Learning whether you’re using C# or F# or whatever language that uses the .NET framework! I don’t have much to say about this so just jump right in and try it out instead! 😆

Rendertron

Rendertron is a dockerized, headless Chrome rendering solution designed to render & serialise web pages on the fly.

Rendertron is Google’s answer to Prerender, which allows you to render your SPAs and that’s what’s served to search engines for SEO and indexing purposes. So you basically spin up a server running Rendertron server and you access the site via the rendertron server. The server will request your real web app and will display it when it has completely loaded. You can let Rendertron decide when the site has loaded or you can explicitly set it. To know more about Rendertron, visit their Github repo.

PHP UI

PHP UI

Yep. You’re seeing it right. You can actually build cross-platform desktop applications with PHP! It’s in the official documentation folks! In the introduction:

This extension wraps libui to provide an OO API for the cross platform development of native look-and-feel user interfaces .

Who says PHP is only for the web? 🙊

Kubernetes Autoscaling

Last time I checked when you setup Horizontal Pod Autoscaling for Kubernetes, you use the CPU usage as the metric. Now you can use the RAM usage, HTTP requests, or other metrics as the trigger for when you would automatically scale your Kubernetes cluster. That is pretty great news!

Top comments (0)