This Week I Learned #7
Tags: devops, javascript, php, node
Published: 2018-05-29 13:43:16

---
title: This Week I Learned #7
published: true
description: Logic, Promises, NPM, PHP, ML, and a bunch of other acronyms in this episode of This Week I Learned!
tags: devops,javascript,php,node
series: This Week I Learned
---

![This Week I Learned](https://thepracticaldev.s3.amazonaws.com/i/jrmvuir64pudz7uzk3kd.JPG)

> 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](https://medium.com/@jepedesu/this-week-i-learned-7-e1c3c9417029).

## [De Morgan’s Laws](https://www.wikiwand.com/en/De_Morgan%27s_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](https://thepracticaldev.s3.amazonaws.com/i/u8bftpkrkpstvidpcvgg.png)

![Testing the function in Chrome](https://thepracticaldev.s3.amazonaws.com/i/19sidrm1qs1ofsz7wf6e.png)

## [Promise.notAll/Promise.allMost](https://gist.github.com/johnpaulada/fe5532f49f10f3579d2b337667aee73e)

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](https://medium.com/@kurtgerm)’s suggestion. Anyway, here’s the code for it.

![Promise.notAll Code](https://thepracticaldev.s3.amazonaws.com/i/co1sec4jl34xl6ficymd.png)

And here's how you'd use it:

![Promise.notAll usage](https://thepracticaldev.s3.amazonaws.com/i/76y4iy48mth5quym00eg.png)

## [npm --](https://docs.npmjs.com/cli/run-script#description)
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:

```sh
npm run test -- --verbose
```

## [npm audit](https://docs.npmjs.com/getting-started/running-a-security-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](https://github.com/sindresorhus/ow)

![Ow](https://thepracticaldev.s3.amazonaws.com/i/u7y3fp9d95odtm1z27sb.png)

Ow! is a library for *Function argument validation for humans* built by the prolific [Sindre Sorhus](https://github.com/sindresorhus). 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](https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet)

![ML .NET](https://thepracticaldev.s3.amazonaws.com/i/7v6wfxb0scs0rrv7gj09.png)

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](https://github.com/GoogleChrome/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](https://github.com/GoogleChrome/rendertron).

## [PHP UI](http://php.net/manual/en/book.ui.php)

![PHP UI](https://thepracticaldev.s3.amazonaws.com/i/kvas2m5e3zlijtb9gw35.png)

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!