teleren/devto huggingface dataset:
Creating Observables from an array of sequentially completing Promises
Tags: angular, typescript, javascript
Published: 2020-01-02 19:00:43

A super-quick post from me today, as I wanted to share some newly acquired knowledge.

Let's say you have an array of data, userIds in this example:

```
export class PageComponent {
  userIds = ['user_1', 'user_2', 'user_3'];
}
```

And you want to create an Observable stream of `User` objects from an API request, where each API request is run in sequence - ie. the request for `user_2` won't be made until `user_1` has resolved. How would you do it?

Let's assume we have a function which returns a promise of our `User` object.

You may be tempted to map over the `userIds` and use `Promise.all` like so:

```
export class PageComponent {
  userIds = ['user_1', 'user_2', 'user_3'];
  users: User[];

  async ngOnInit(): void {
    this.users = await Promise.all([
      ...this.userIds.map(userId => this.userService.getUser(userId))
    ]);
  }
}
```

However, this will make all asynchronous calls at the same time and won't set `this.users` until all inner promises have resolved.

Observables are a much better pattern for this kind of use-case.

What we want to do is create an Observable from the `userIds` array with the rxjs `from` function, then use the `concatMap` operator to map each `userId` to an inner observable (or promise in this case), which won't be subscribed to until the previous one has completed.

```
export class PageComponent {
  userIds = ['user_1', 'user_2', 'user_3'];
  users$: Observable<User>;

  ngOnInit(): void {
    this.users$ = from(this.userIds).pipe(
      concatMap(userId => this.userService.getUser(userId))
    );
  }
}
```

When subscribed to, this observable will request and emit each user in sequence, emitting 3 `User` objects over time before completing.

## Bonus points - use `scan` to accumulate values over time

Let's say you wanted the Observable to build up an array of `User` objects over time and not just emit individual `User` objects. Let's use the rxjs `scan` operator!

```
export class PageComponent {
  userIds = ['user_1', 'user_2', 'user_3'];
  users$: Observable<User[]>;

  ngOnInit(): void {
    this.users$ = from(this.userIds).pipe(
      concatMap(userId => this.userService.getUser(userId)),
      scan((acc, curr) => acc.push(curr), [])
    );
  }
}
```

Et voila! Simply loop over `users$ | async` in your template and watch your user list grow.

The power and magic of rxjs and Observables everybody :)
CSS display "stack"
Tags: css
Published: 2020-01-02 18:55:21

**NOTE: `display: stack` does not exist. Read on for more info.**

##Background

Two and half years ago, I wrote a post on Medium about this possible new kind of display I called `stack` that "would be a hybrid of flexbox and z-index".

https://medium.com/@alexpds/css-display-stack-7bdc02bc1434

>This new layout method, would allow the ‘stack’ wrapping element to automatically assume the height of the tallest of it’s childs.
>So, with similar syntax to flexbox, we could override the order (z-order) of the various elements, more or less like we can with z-index, but the tallest child would affect the ‘stack’ height and thus no issues with unwanted overflows, uncontrollable overlaps.


##Grid to the rescue!

Back then (May 2017), CSS Grid was still being defined and if what I'm showing below was possible back then I didn't know. 
But today CSS Grid support is very broad and it allows exactly what I described in the original article.

```css
.stack { 
  display: grid;
  grid-template-areas: "stack"; /* or whatever name you prefer */
}

.stack > * {
  grid-area: stack; /* same name as used above without quotes */
}

.stack .top-most {
  z-index: 1; /* default order is 0. Highest shows on top  */
}
```


**Example on CodeSandbox**
{% codesandbox 0nv9b %}
https://codesandbox.io/s/dry-worker-0nv9b
JDK11 HttpClient example
Tags: java, httpclient
Published: 2020-01-02 18:49:25

---
title: JDK11 HttpClient example
published: true
description: 
tags: java,httpclient
---

Small example of how to call out to a URI using Java 11 HttpClient. Nothing new here really. Just for me to remember one day.

```java
import java.net.URI;
import java.net.http.*;
import java.net.http.HttpClient.Redirect;
import java.net.http.HttpClient.Version;
import java.time.Duration;

public class Junk {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
        .version(Version.HTTP_1_1)
        .followRedirects(Redirect.NORMAL)
        .connectTimeout(Duration.ofSeconds(20))
        .build();
        HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://crossbrowsertesting.com"))
        .build();
        HttpResponse response = client.send(request, 
            HttpResponse.BodyHandlers.ofString());
        System.out.println(response);
        System.out.println(response.body());
    }
}
```

Java docs are here: https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html
Using Python to create MySQL tables with random schema
Tags: mysql, database, metadata, python
Published: 2020-01-02 18:28:53

Having a large amount of test data sometimes take a lot of effort,  and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for MySQL.


## Environment

##### Activate your virtualenv
```bash
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
```

##### Install the requirements for the metadata generator
```bash
pip install -r requirements.txt
```

## Code
{% gist https://gist.github.com/mesmacosta/baca6adce53733860e92b2d87f652330 %}

## Execution
```bash
export MYSQL_SERVER=127.0.0.1
export MYSQL_USERNAME=test_user
export MYSQL_PASSWORD=test_user_pwd
export MYSQL_DATABASE=test_db

python metadata_generator.py \
--mysql_host=$MYSQL_SERVER \
--mysql_user=$MYSQL_USERNAME \
--mysql_pass=$MYSQL_PASSWORD \
--mysql_database=$MYSQL_DATABASE
```

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!
Why choose the JAMstack?
Tags: jamstack, jamuary
Published: 2020-01-02 18:28:13

There are many ways to build a website in 2020. From the more traditional approaches like LAMP and MEAN, to more modern ones like server side rendering (SSR) and the JAMstack, developers are spoilt for choice when it comes to picking a stack. While architectural choices vary based on use case, the JAMstack offers so much freedom of choice that it emerges as one of the most flexible stacks out there today. This flexibility is largely a result of the JAMstack’s focus on methodology over technology. Instead of prescribing what to use, the JAMstack converges on the why and how websites are built. With the JAMstack, developers are encouraged to build complexity consciously by choosing the various moving parts of their application and even outsourcing functionality to external APIs. Not only does this sort of decoupling reduce complexity and the cognitive load that follows it, it also makes JAMstack architectures more reusable. Other benefits of the JAMstack include significant performance boosts from serving static assets via a CDN, cost savings from not having to pre-scale servers, and greatly improved security from a reduced surface area for attack. The JAMstack offers all this and more in addition to a top notch developer experience. I'd say that's a pretty sweet deal.

If I’ve yet to convince you about the benefits of the JAMstack or if you'd like to dig in further, check out [this fantastic book covering the wonders of the JAMstack over on the Netlify site](https://www.netlify.com/oreilly-jamstack/?utm_source=twitter&utm_medium=jamstackbook-div&utm_campaign=devex).
Using Python to create Greenplum tables with random schema
Tags: greenplum, database, metadata, python
Published: 2020-01-02 18:25:29

Having a large amount of test data sometimes take a lot of effort,  and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for Greenplum.

If you want to set up a Greenplum environment for dev and test purposes, take a look at: https://dev.to/mesmacosta/quickly-set-up-a-greenplum-environment-on-gcp-2lkd

## Environment

##### Activate your virtualenv
```bash
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
```

##### Install the requirements for the metadata generator
```bash
pip install -r requirements.txt
```

## Code
{% gist https://gist.github.com/mesmacosta/e0f326b677b1020c51cb4cd208a29b4d %}

## Execution
```bash
export GREENPLUM_SERVER=127.0.0.1
export GREENPLUM_USERNAME=gpadmin
export GREENPLUM_PASSWORD=gppassword
export GREENPLUM_DATABASE=gpadmin

python metadata_generator.py \
--greenplum-host=$GREENPLUM_SERVER \
--greenplum-user=$GREENPLUM_USERNAME \
--greenplum-pass=$GREENPLUM_PASSWORD \
--greenplum-database=$GREENPLUM_DATABASE
```

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!
Using Python to create Oracle tables with random schema
Tags: oracle, database, metadata, python
Published: 2020-01-02 18:18:45

Having a large amount of test data sometimes take a lot of effort,  and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for Oracle.

If you want to set up an Oracle environment for dev and test purposes, take a look at: https://dev.to/mesmacosta/quickly-set-up-an-oracle-environment-on-gcp-hfd


## Environment

##### Activate your virtualenv
```bash
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
```

##### Install the requirements for the metadata generator
```bash
pip install -r requirements.txt
```

## Code
{% gist https://gist.github.com/mesmacosta/8999bcbda19705eed93c0dba909f1b0b %}

## Execution
```bash
export ORACLE_SERVER=127.0.0.0
export ORACLE_SERVER_PORT=1521
export ORACLE_USERNAME=system
export ORACLE_PASSWORD=system_pwd
export ORACLE_DATABASE_SERVICE=XEPDB1


python metadata_generator.py \
--oracle-host=$ORACLE_SERVER \
--oracle-port=$ORACLE_SERVER_PORT \
--oracle-user=$ORACLE_USERNAME \
--oracle-pass=$ORACLE_PASSWORD \
--oracle-db-service=$ORACLE_DATABASE_SERVICE \
--number-tables=500

```

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!
Flask vs Django — Rotas
Tags: python, flask, webdev, django
Published: 2020-01-02 18:16:06

Todo framework web (ou quase todos, não cheguei a trabalhar com todos) tem seu meio de fazer rotas entre suas função e as requisições do que vem do cliente. Nessas rotas também é possível configurar o método HTTP, onde uma rota `/user` com o método `GET` irá gerar um resultado diferente da rota `/user` com o método `DELETE`.

No modelo de arquitetura `REST`, os métodos HTTP têm semântica. Nele é recomendado que o método `GET` seja usado para consultas, o método `POST` para inserir informações, o `PUT` para atualizar e o `DELETE` para deletar. O `REST` determina outras boas práticas mas elas não vem ao caso agora.

No Django, as rotas são criadas num arquivo chamado `urls.py`, numa lista chamada `urlpatterns`.

{% gist https://gist.github.com/rjLelis/d7c25a9e35c60b5466e79e88c3dd71c2 %} 


Essa lista recebe a função `path()`, onde é passado a rota e qual a função do módulo `views.py` irá ser chamada.

{% gist  https://gist.github.com/rjLelis/c3fdeb4efd420a30626eccb5cd80d8c9 %}

No caso do Flask, um [decorator](https://pythonacademy.com.br/blog/domine-decorators-em-python) é usado para criar as rotas.

É o mesmo princípio usado no Django, cada função recebe um decorator,  `app.routes`, onde é passado sua rota.

A diferença aqui, é que o Django faz isso em arquivos separados e o Flask consegue fazer em um arquivo só (na verdade o Flask permite criar uma aplicação em um único arquivo se você quiser).

Outra grande diferença é o segundo argumento no decorator do Flask. Nele nós passamos uma lista de métodos HTTP e quando essa rota for chamada, dependendo do método, uma função diferente é chamada.

{% gist  https://gist.github.com/rjLelis/668cf3fbcb7a8f6835b8054e464d6ad5 %}

No exemplo acima, a rota é a mesma mas os métodos são diferentes, separando as funções que vão ser chamadas.

No Django, a diferenciação de métodos HTTP deve ser feita dentro da função chamada pela rota.

{% gist https://gist.github.com/rjLelis/67f4eb1b86fe3790d898f6f9a478d3a3 %}

Com isso, sempre que houver a necessidade de alteração em alguma lógica de inserção ou de busca, a alteração vai acontecer em uma única função. Isso deixa a manutenção do código mais engessada.

Enquanto o Flask oferece mais flexibilidade e simplicidade nas rotas, o Django oferece mais velocidade na prototipagem (class based views for the win!) e uma arquitetura bem definida, embora obrigue o desenvolvedor a usar suas convenções.
Using Python to create SqlServer tables with random schema
Tags: sqlserver, metadata, database, python
Published: 2020-01-02 18:14:04

Having a large amount of test data sometimes take a lot of effort,  and to simulate a more realistic scenario, it’s good to have a large number of tables with distinct column types. This script generates random tables schema for SQLServer.


## Environment

##### Activate your virtualenv
```bash
pip install --upgrade virtualenv
python3 -m virtualenv --python python3 env
source ./env/bin/activate
```

##### Install the requirements for the metadata generator
```bash
pip install -r requirements.txt
```

##### Install ODBC Driver 17 for SQL Server
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

## Code
{% gist https://gist.github.com/mesmacosta/ae00548a95b4418928e9274af3080372 %}

## Execution
```bash
export SQLSERVER_SERVER=127.0.0.1
export SQLSERVER_USERNAME=sqlserver
export SQLSERVER_PASSWORD=sqlserver_pwd
export SQLSERVER_DATABASE=test_db

python metadata_generator.py \
--sqlserver-host=$SQLSERVER_SERVER \ 
--sqlserver-user=$SQLSERVER_USERNAME \
--sqlserver-pass=$SQLSERVER_PASSWORD \ 
--sqlserver-database=$SQLSERVER_DATABASE

```

And that's it!

If you have difficulties, don’t hesitate reaching out. I would love to help you!
Using theharvester OSINT tool in python scripts
Published: 2020-01-02 18:06:31

# theHarvester

 is a very simple, yet effective tool designed to be used in the early stages of a penetration test. It can be used for open source intelligence gathering and helping to determine a company's external threat landscape on the internet.

With this tool you can scrounge the following information from the internet

* [E-mails](https://www.nmmapper.com/kalitools/theharvester/email-harvester-tool/online/)

* [Subdomains](https://www.nmmapper.com/sys/tools/subdomainfinder/)

* Social names

* [Portscanner](https://www.nmmapper.com/st/networkmapper/nmap/online-port-scanning/)

## Installing theHarvester

```bash
pip3 install theHarvester
```

or you can perform the following

```bash
sudo apt-get install python3-pip
sudo pip3 install virtualenv 

#
# Create virtualenv

virtualenv venv 

# Or create a python version specific virtualenv

virtualenv -p python3 myenv
#
# Now clone the git repo
git clone https://github.com/laramies/theHarvester.git
#
pip3 install -r requirements.txt
#
# Wait until the installation is done.
```

### Using it in your python scripts

```python
import theHarvester
from theHarvester.discovery import bingsearch
from theHarvester.discovery import googlesearch

#....and more....
# or
# from theHarvester.discovery import *

baidu = baidusearch.SearchBaidu("nmmapper.com", 100)
baidu.do_search()

# Each discovery engine has it's own method
# not all have get_emails

emails = baidu.get_emails()
hostnames = baidu.get_hostnames()
# That's how you can use theHarvester in any other python3 module

```

This tool is very powerful. And among it's most powerful public sources includes googlesearch, though google blocks the IP making the request if the request is made several times. Currently they are working on a solution to google blocking.

### References
* https://github.com/laramies/theHarvester
* https://www.nmmapper.com/kalitools/theharvester/email-harvester-tool/online/
Where to now?
Published: 2020-01-02 18:01:04

Just read this lovely post: 

https://dev.to/devteam/you-can-now-generate-self-hostable-static-blogs-right-from-your-dev-content-via-stackbit-7a5

And I wonder if I should start posting things here.

Also, is this still valid?

https://vocal.media/01/13-clean-and-simple-open-source-blogging-platforms-for-your-developer-blog
Tinymce Bootstrap plugin now for Tinymce 5 + Bootstrap 4
Tags: tinymce, bootstrap, javascript
Published: 2020-01-02 17:45:33

# Bootstrap 4 toolbar for tinymce 5

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/nfu95x9nsjyzmnd23vll.png)

## Transform Tinymce into a complete Bootstrap 4 content editor.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/2y4om57zydaus1ypu8t4.png)

The Bootstrap toolbar provides the ability to add/edit bootstrap components and code snippets:
- Button
- Icon
- Image
- Table
- Template
- Breadcrumb
- Pagination
- Badge
- Alert
- Card
- Any Custom Snippet

The plugin demo is available here: https://www.tinymce-bootstrap-plugin.com/demo/index
Unit Testing with Javascript in a nutshell
Tags: javascript, testing, webdev
Published: 2020-01-02 17:41:45

# What is Unit Testing ?

Unit testing usually test a small part of the code. For example we test a function, we input something and we expect the function return something.


Look add the code in app.js below
{% gist https://gist.github.com/Bbw0706/d57f0110394e915c2ff8411833002c9e %}

We have a function named sum and it accept a & b arguments, and the function return the sum of a & b.

You're good ? Nice, now how we test this function and make sure it works like what we expected ?.


## First let me introduced you to Jest

What is Jest ? it's just a testing library created and maintained by Facebook and you can find it more to learn in [here](https://jestjs.io/docs/en/getting-started).

But keep this in your head when you read this article, it doesn't matter if you not learn all the stuff in Jest, because you can still look up on it everytime you need the methods, it just syntax matter. What i mean is you must learn the concept and not the library.


## Generate some new Projects
Lets generate some new Express Project for making a unit test app

```
~ mkdir learn_ut
~ cd learn_ut
~/learn_ut touch app.js
~/learn_ut yarn init -y
~/learn_ut yarn add express
~/learn_ut yarn add -D jest
```

Right, we're good. If you confused on this stuff then keep it simple, We're just generate a light Express applicaton here using yarn.

Now, let's config the jest in package.json file
{% gist https://gist.github.com/Bbw0706/5120652b585c6c26f64a63544f9fba71 %}
I'm added the block code of Jest in that json file. What happened ? it just a small config for Jest to work on our project, That's all.

Also i added the scripts tag for us to run easily, usually this called npm scripts. for example, i don't need to run `jest` everytime on my terminal, so i just use `yarn test`.

All right, now let's create the test file and we must import the sum function in our test.
{% gist https://gist.github.com/Bbw0706/f4870f27b2bedbcf884ea54329955f1a %}

Oh my god, what's these new syntax ? 

It's just a normal test syntax, a `test()` function is just like a statement of what you expect the return would be and it's accept a normal string in first argument and a callback in second argument, you can write whatever you want in first argument but i recommend you to write as what you expect the test would be.

Let's talk about the callback statement, here i expect the sum of 1 & 2 will be 3. `expect()` function is a Jest function and it has a bunch of method you can use like `toBe()` or `toBeTruthy()`etc.


What happened when you run the test ? Let's try it
```
~/learn_ut yarn test
```

![Unit test result](https://beebeewijaya-image.s3.amazonaws.com/Screen+Shot+2020-01-03+at+00.35.36.png)

All right!, we're done. 

That's all for a Unit Testing in a nutshell.
I'm sorry if i can't write so good it's my first writing here, but i'm giving my best and i will contribute more in dev.to and for the Javascript community.

Wait for my next article, Thank you very much!
Do 0 ao CKA pt 1/??
Tags: kubernetes, devops, beginners
Published: 2020-01-02 17:37:06

Olá, esse é o meu primeiro post em um blog de TI, hahaha (nervoso) então qualquer crítica é muito bem vinda. 

Espero que gostem do conteúdo que irei produzir aqui. Essa é uma pequena forma de compartilhar o pouco que sei. E o que me motivou muito a escrever aqui, foi o fato de eu ter me envolvido nas comunidades, isso fez total diferença no meu 2019.


Essa série de posts terá uma quantidade indefinida, vou tentar mostrar minha rotina de estudos e materiais utilizados na preparação para a  [CKA - Certified Kubernetes Administrator] (https://www.cncf.io/certification/cka/).

Bom, vamos lá.

Primeiramente existem alguns pré requisitos para iniciar no mundo do kubernetes (doravante k8s), que são:

1. Docker ou outro container runtime (nessa série, vou focar no docker):
  * [Docker para Desenvolvedores] (https://leanpub.com/dockerparadesenvolvedores) do [@gomex] (https://twitter.com/gomex) - pt-br ;
  * [Descomplicando Docker] () do [@badtux_] (https://twitter.com/badtux_) ;
  {% youtube T3lpAjOcbU8%}

2. YAML
  * [Learn X in Y minutes; Where X=yaml] (https://learnxinyminutes.com/docs/yaml/) - pt-br ;
  * Vídeo do [kodekloud] (https://kodekloud.com/) sobre Yaml - en ; {% youtube U9_gfT0n_5Q%}
  * [Exercícios] (https://kodekloud.com/p/yaml-introduction) - en ;



{% twitter 1212321984245358592%}
Tech's short-sighted perspective fails to recognize impending doom
Tags: watercooler, tech, industry
Published: 2020-01-02 17:09:31

---
title: Tech's short-sighted perspective fails to recognize impending doom
published: true
description: In a tech community that worships unicorn startups where is the retrospective on their failures?
tags: watercooler, tech, industry
---

I'm looking for a discussion here. TL;DR is, "Why do we as a tech community think that companies that are successful now are some kind of template for success, rather than considering they may be next year's failure?"

Hear me out: one of the first "unicorns" was Groupon. And there was a now-predictable cycle that it went through:

1. being valued at billions of dollars
2. [receiving acquisition offers but rejecting them](https://www.businessinsider.com/groupon-pivot-2011-3) and preparing for IPO
3. being worshiped and copycatted by the tech community
4. [having the highest IPO since Google](https://en.wikipedia.org/wiki/Groupon#Initial_public_offering)
5. descending into oblivion (just look at its stock price now)

"So what?" you're probably thinking. Groupon is for old people who don't know any better. 

Maybe. But Groupon's story is being relived over and over again by Snap, Uber, Lyft, and more.

And a lot of "it" companies of the past also failed spectacularly after being huge for awhile. Atari, AOL, Yahoo, Compaq, Nokia, etc.

At the same time, I hear a lot of people talking up how these companies approach product and engineering, as though they're a template worthy to be followed. I'm not saying they aren't, but I do think we need to have some more careful consideration on that. I think it's worth pausing a moment and considering the past before plunging into all the latest software process crazes just because a company that's successful right now uses them.

Thoughts?