teleren/devto huggingface dataset:
Improving Database Performance with Parallel Querying in PostgreSQL
Tags: apache, datab, postgressql, opensource
Published: 2023-06-01 18:52:30

## Introduction

In the world of databases, speedy query execution is crucial for efficient data processing. PostgreSQL, a popular open-source database management system, offers a powerful feature called parallel querying that can significantly enhance query performance. In this article, we will explore what parallel querying is, when to use it, and how to harness its benefits.

## Parallel Querying

Parallel querying in PostgreSQL involves executing a single SQL query across multiple parallel worker processes simultaneously. By utilizing the computational power of modern CPUs with multiple cores, parallel querying enables the distribution of query workload among these cores. This parallel processing approach can significantly improve query execution times, leading to enhanced database performance.

## When to Use Parallel Querying

- When dealing with vast datasets, parallel querying can substantially accelerate query execution by leveraging parallelism across multiple cores. By dividing the workload among these cores, the overall processing time is significantly reduced.
- Systems equipped with multiple processors or cores can fully exploit their computational capabilities by enabling parallel querying. This approach allows for efficient utilization of system resources, resulting in faster query execution.
- Data warehousing environments often involve complex analytical queries, including aggregations, joins, and sorting operations. Parallel querying can expedite these operations, leading to quicker generation of insights from the data.

## Enableing Parallel Querying

- Adjust PostgreSQL's configuration parameters to enable parallel querying. Specifically, set "max_parallel_workers" and "max_parallel_workers_per_gather" to suitable values based on your system's capabilities.
- Ensure proper data distribution across segments or partitions. Balanced distribution prevents workload imbalances, leading to optimal parallel query performance.
- PostgreSQL's query planner determines whether a query can benefit from parallel execution. To aid the planner, maintain accurate table statistics, appropriate indexing, and update-to-date query plans.
- By default, PostgreSQL's query planner decides whether to use parallel querying. However, you can explicitly instruct it using hints in your SQL queries. For instance, by adding "/*+ parallel(x) */" to your query, you can specify the desired degree of parallelism (x).

## Conclusion

Parallel querying in PostgreSQL is a powerful feature that enhances query performance by utilizing multiple CPU cores. By enabling parallel execution for suitable queries, you can significantly reduce query execution time and improve overall database performance.
"Error 503 Service Unavailable" You never want to get that message
Tags: react, security, productivity, discuss
Published: 2023-06-01 18:46:02

I'm excited to announce that from tomorrow I'll be launching a series of posts on security for React & Angular applications. In this series, I'll cover a variety of topics, including:

 - Common vulnerabilities in React & Angular applications
 - Solutions to common vulnerabilities
 - Case studies of React & Angular applications that have been hacked

I hope this series will help developers to understand the security risks associated with React & Angular applications and to take steps to mitigate those risks.

**Common vulnerabilities in React & Angular applications**

React & Angular applications are susceptible to a variety of security vulnerabilities, including:

 - Cross-site scripting (XSS)
 - SQL injection
 - CSRF (Cross-site request forgery)
 - Insecure deserialization
 - Information disclosure
 - These vulnerabilities can be exploited by attackers to steal data, inject malicious code, or take control of an application.

**Solutions to common vulnerabilities**

There are a number of things that developers can do to mitigate the risks associated with these vulnerabilities, including:

 - Use a secure development environment
 - Use a security scanner
 - Keep your code up to date
 - Use strong passwords and authentication
 - Use input validation
 - Use error handling
 - Use secure coding practices
By following these security best practices, developers can help to protect their React & Angular applications from attack.

**Case studies of React & Angular applications that have been hacked**

In recent years, there have been a number of high-profile cases of React & Angular applications that have been hacked. These cases have highlighted the importance of security for React & Angular applications.

In one case, a React application was hacked and used to steal user data. In another case, an Angular application was hacked and used to spread malware.

These cases show that React & Angular applications are not immune to attack. By following the security best practices outlined in this series, developers can help to protect their applications from attack.

I hope you'll join me for this series on React & Angular security. I'll be publishing new posts every day.

Thanks for reading!
Passwords Are Bad UX
Tags: security, ux, design
Published: 2023-06-01 18:38:22

My spicy hot opinion of the week: passwords are bad UX.

**Why do we force users to create passwords?**  Better yet, why do we force them to create a password, impose significant limitations on how they create it, and then punish them if they cannot remember it?

We live in an internet age, where web applications assist in essential and common human interactions every second of every day.  Every one of those web applications requires that users create a password.  And every password we require users to create makes them **worse off**.

<u>Users are worse off with passwords because it creates opportunities for pain where they did not exist before</u>.  All of these scenarios occur when you force users to create a password:

1. Users must remember the password, or pay for a tool that will remember/create the password for them.
2. Users must walk through cumbersome password recovery flows if they forget their password.
3. Users will randomly get kicked out of applications when their auth token expires, leading to (1) and (2)
4. Users must monitor or pay for software that monitors every password they've ever made, in case this information is leaked to the dark web.

When a user encounters one of the above while using your application, they can attribute their pain directly to you and your app.

I would argue that **it is irresponsible from a UX/UI perspective (not just a security perspective) to force users to create passwords**.

Is there no better way to ensure a secure connection than a piece of text?  Well, of course there is.  For example, [Google has rolled out passkey support for Google Accounts](https://www.wired.com/story/google-passkey-password-replacement/).  This gets rid of passwords AND 2FA for Google accounts that opt in.

However, there may be other options, and I urge you all to sit down and think for a few minutes today about the question:

**What would the world look like without passwords?**
Simple flat rate pricing for Jamstack consulting.
Tags: career, startup, web3, news
Published: 2023-06-01 18:13:32

Hey everyone!

So, I've been going through a bit of a makeover recently - not me, exactly, but my pricing structure. I've been doing some serious number crunching and have decided that a transparent, flat rate pricing structure would be best.

This idea was heavily influenced by Brett from DesignJoy, but I've also made some significant changes to suit my own circumstances.

It's a challenge to set prices for custom software development; there are just so many variables at play. Some clients want me to be a part of their team, attend meetings, rework old documentation, and the like. Others just need a top-notch UI, no questions asked.

So, I've come up with three pricing tiers that I think will accommodate most of you. Here's a little about each of them:

Foundation - For $2,500 a month, you get unlimited asynchronous consulting, 2 feature requests or bug fixes per month, and biweekly updates. This tier is perfect for those who run marketing sites or need an expert in React for consulting, PR reviews, or other asynchronous tasks. However, if you're looking to build something from scratch rapidly, you might want to consider the next tier.

Elevate - For $8,000 a month, you get unlimited asynchronous consulting, unlimited feature requests or bug fixes, weekly updates, a guaranteed 30 hours of work per week, biweekly meetings, and can request documentation or articles. I believe this tier will be a good fit for most, especially startups and SaaS companies aiming to launch an MVP, add unique features, or rewrite in React.

Amplify - For $10,000 per month, you get all the benefits of Elevate, plus daily standup reports, internal team collaboration, and weekly meetings. The 30-hour cap remains in place. This tier is for companies that need close collaboration with an existing engineering team, whether for task discussions, stakeholder consultations, or React training for your team.

In each of these tiers, you get me, a seasoned software architect with over 7 years of React experience, as your personal service provider. However, bear in mind that once my schedule is full, I won't be able to take on more clients!

If you're interested, please check out my pricing structure [here](https://jamstack.consulting/pricing) and sign up before the slots run out!

Looking forward to working with you!
[PHP] - Desafio Alura - 7 Days of Code - Dia 1
Tags: php, challenge
Published: 2023-06-01 18:07:33

Nesta série de posts, vou apresentar a vocês minha trajetória durante a execução do desafio de PHP **7 Days of Code**, uma iniciativa da Alura.

Tais desafios consistem da apresentação de um problema inicial que, geralmente, é uma simulação de uma demanda do mundo real. A cada dia, nós devemos cuidar de uma parte específica do projeto, implementando uma funcionalidade nova, resolvendo algum problema, ou os dois.

Para falar do primeiro dia, antes vou comentar brevemente sobre a estrutura inicial do projeto:

```
├── boot.php
├── config.php
├── 📁 data
│   └── users.json
├── index.php
├── 📁 resource
├── routes.php
├── 📁 view
```

- **boot.php**: Carrega os arquivos necessários para a execução do projeto;
- **config.php**: Declaração de constantes;
- **data/users.json**: Nosso "banco de dados" local;
- **index.php**: Ponto inicial do projeto;
- **resource/**: Arquivos de imagem e de estilização;
- **routes.php**: Chama a função específica do Controller (a ser implementado) de acordo com a página solicitada;
- **view/**: Contém todos os arquivos de template, os quais serão mostrados de acordo com a rota acessada

A tarefa do primeiro dia consistiu apenas em separar a responsabilidade do arquivo **routes.php** que, além de checar qual página estava sendo requisitada, também mostrava o template correspondente.

```php
routes.php

<?php
$page = ($_GET['page']??'login').'.view';
$content = file_get_contents(VIEW_FOLDER.$page);
echo $content;
```

Com isso, foi requisitada a criação de dois arquivos: **controller.php** e **view.php**. O Controller abriga as funções que serão chamadas pelo arquivo de rotas e executadas de acordo com a página solicitada. Já a View contém a função responsável pela exibição do conteúdo em tela de acordo com  o template solicitado.

```php
controller.php

<?php

function doRegister() {
    renderView('register');
}

function doLogin() {
    renderView('login');
}

function doNotFound() {
    renderView('not_found');
    http_response_code(404);
}
```

```php
view.php

<?php

function renderView($template) {
    $content = file_get_contents(VIEW_FOLDER . $template . '.view');
    echo $content;
}
```

A refatoração em **routes.php** consistiu em criar um `switch` para a variável `$page`. Dessa forma, eu posso **controlar** melhor o que fazer em cada caso, além de melhorar a leitura do código. Também retirei as linhas de código que mostravam o conteúdo na tela e joguei para **view.php**.

```php
routes.php depois da refatoração

<?php

$page = ($_GET['page'] ?? 'login');

switch ($page) {
    case 'login':
        doLogin();
        break;

    case 'register':
        doRegister();
        break;

    default:
        doNotFound();
        break;
}
```

Dessa forma, concluímos o primeiro dia do desafio. Nada muito complicado, porém ainda há muitas funcionalidades e melhorias a serem implementadas. Te vejo na próxima ou nos comentários!
Rusting my brain away - Part 1
Tags: rust, learning
Published: 2023-06-01 18:04:38

Hey there! yeah you, how are you? Feeling like life doesn't have any purpose anymore? Feeling like the social media and internet has taken over our lives? Feeling like the r/ProgrammerHumour is not funny anymore? [I am sorry, I still find it funny] Well don't you worry, I am here to tell you that we are all doomed and we all are in the same boat of rusting our brains, potentially becoming zombies [Maybe I should just let it rust, I can win in comiccon 
for being a realistic zombie, I mean, I've got the looks down, I walk like one, heck why not start thinking like one?]. 

As someone who's a wannabe-super-~~zombie~~developer, I can say I have had enough brian rust in my life. It's time I start doing some engineering for kicks!

This is probably a multi part series which will contain my journey towards learning rust and implementing something FUN with it [no not hello world or microservices or some random tutorial]

# Why?
I like pain. You'll understand when you have a leg day and you don't get muscle pain anymore. I want that pain. I've become desperate and I've started searching for that pain in other parts of my life. Asian level GTA online races have started feeling normal. I think I need help.

# Why rust?
Just cause, bored of using languages I know which scream pain, but it's not enough.

# Resources to get started on learn rust
* I am starting with [tour of rust](https://tourofrust.com/index.html) (taking inspiration from tour of go, which was a really good and quick intro for golang!)
* Some motivation to [try rust](https://www.youtube.com/watch?v=DnT-LUQgc7s)

PS: I know brian is spelt wrong, shows I have a rusty brian
55. Jump Game
Tags: leetcode
Published: 2023-06-01 18:02:18

Problem source: [Jump Game](https://leetcode.com/problems/jump-game/description/)

<strong>1. Understand the problem</strong>
The problem requires to determine if we could jump to the last index in the array using the values of the elements within it.

Let say if we are at index `i` with the value of 3, we can visit all position from `i` till `i + 3`.

<strong>2. First thought</strong>
We can apply a brute force method to solve this.
We can have an array keeping track of whether it is possible to visit an index `i`.
For each element `e` with value `nums[e]`, we can run a loop to mark all element from `e` to `e + nums[e]` to be visitable

Here is a simple code in Java:
```java
// input is int[] nums
int visitable = new boolean[nums.length];

for (int i = 0; i < nums.length; i++) {
    int element = nums[i];
    for (int index = element; index <= element + nums[element]; index ++) {
        visitable[index] = true;
    }
}

return visitable[nums.length -1];
```

This may yeild a time limit exceed since it will require O(n^2) runtims.

<strong>3. Solution</strong>

What could be improved is that we do not need nested for loop for this. We can use greedy method.

One observation we can claim is that: if we could visit index `x`, we can visit all indices `y` with `y < x`.

This can be proven using contradiction. I will leave this to you.

So here is the solution to this problem, which runs in just O(n)
```java
class Solution {
    public boolean canJump(int[] nums) {
        /**
        The steps count from that index to index + step. 
        We can maintain a queue to keep track of which index can be visited, also keep track of a set of index already visit to avoid repetition. 

        Runtime: O(n ^ 2) with n can be 10^5

        Need to improve this:
        - do not care about the value at the last index
        - care whether the other cell could reach the last one. 
        - update the value of the elements to the farthest cell they can reach


        If we can visit cell x, can we claim that we can always visit cell y < x?
        */
        int max = 0;
        int idx = 0;
        while (idx < nums.length && idx <= max) {
            max = Math.max(max, idx + nums[idx]);

            if (max >= nums.length - 1) {
                return true;
            }
            idx ++;
        }

        return false;
    }
}
```
Aprendendo algo novo - Parte 1
Tags: chatwoot, learning, infrastructureascode, programming
Published: 2023-06-01 16:57:50

## Introdução
Fazem 8 meses que entrei em uma empresa que tem um ecossistema de tecnologia muito particular e exclusivas para o contexto da companhia. A linguagem de programação usada não é das mais populares e existem muitas libs que são internas, não precisamos nos preocupar com a infraestrutura pois tudo está automatizado e seguir o mesmo padrão, com isso surgiu a preocupação de ficar desatualizado com o que tem surgido no mercado, portanto decidi criar um projeto para desenvolver e aprimorar novas habilidades.

Realmente não sei se alguém verá esse texto, mas como carecemos de documentos em português brasileiro vamos fazer todos dessa forma.

A ideia desse projeto é utilizar tecnologias open source ou que possuam planos gratuitos.
que eu nunca tinha utilizado em nenhum projeto


## Sobre que é o projeto?
A ideia é implantar uma ferramenta de atendimento, para isso vamos usar o [chatwoot](https://github.com/chatwoot/chatwoot) faremos deploy em alguma cloud(Oracle ou AWS) onde vamos subir um cluster kubernetes, para tudo isso usaremos o [terraform](https://www.terraform.io/) e [ansible](https://www.ansible.com/) para configurar toda a infra.

Para dar suporte ao chatwoot iremos subir um [Elastic APM](https://www.elastic.co/pt/observability/application-performance-monitoring) dentro do cluster para fazer a parte de observabilidade e o sentry para coletar os erros, usando também o [mailslurper](https://www.mailslurper.com/) para criar um servidor de smtp para os testes, usaremos o [sendgrid](https://sendgrid.com/) para o inbound de email e para fazer testes locais usaremos o [ngrok](https://ngrok.com/) para expor um webhook "na internet".

## Como vai funcionar?

Será em duas etapas: 

1. Subir localmente o chatwoot para simular um caso real de atendimento,  usando toda a experiência que já tive em atendimento e conversar com alguns amigos para fazer os casos de usos.
2. Configurar toda a infra e subir o chatwoot na nuvem e validar os casos de uso.

Gostou? Minha  ideia é publicar 1 artigo por semana sobre evolução dos aprendizados, então espero em breve postar algo novo com vocês!

Feedbacks são sempre bem vindos 💡
Sort's Web3 React Components Are Now Open Source!
Tags: react, ethereum, polygon, typescript
Published: 2023-06-01 17:56:08

We're excited to announce the Alpha release of Sort's React Components: [https://github.com/sortxyz/react-components](https://github.com/sortxyz/react-components). This release marks our first iteration of simplifying data-rich UIs for Web3.

We're initially starting with three core components for building data rich UIs:
- **`<LatestTransactions/>`** - Displays a pageable table of the latest transactions of a contract address.
- **`<SQLQuery/>`** - Easily include blockchain data from a Sort SQL Query in your application.
- **`<PushNotifications/>`** - Show real-time transactions for a contract.

All three components support Ethereum, Polygon and Goerli data sources.

## LatestTransactions

The [`<LatestTransactions/>`](https://docs.sort.xyz/docs/latest-transactions) React Component displays a pageable table of the latest transactions of a contract address.

```typescript
<LatestTransactions
  contract_address="0xd1f9c58e33933a993a3891f8acfe05a68e1afc05"
  chain="polygon"
  api_key="API_KEY"
  theme="dark"
/>
```

**Preview:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/apcp2bdlx2eg19rntxq7.png)

## SQLQuery

The [`<SQLQuery/>`](https://docs.sort.xyz/docs/sql-query) React Component lets you easily include blockchain data from a Sort SQL Query in your application.

```typescript
<SQLQuery
  query="select * from polygon.transaction where to_address='0xd1f9c58e33933a993a3891f8acfe05a68e1afc05' order by block_id desc"
  api_key="API_KEY"
/>
```

**Preview:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2rtubd3kqs4gtfelnxv.png)

## PushNotifications

The [`<PushNotifications/>`](https://docs.sort.xyz/docs/push-notifications) React Component lets you easily include live blockchain transactions into your application.

```typescript
<PushNotifications
  contract_address="0xd1f9c58e33933a993a3891f8acfe05a68e1afc05"
  contract_function=""
  num={10}
/>
```

**Preview:**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3cu9fg8fe5ckpisxwpk.png)

## Get Started Today

Head over to Sort to [create a free API Key and start building today](https://docs.sort.xyz/docs/api-keys). Let us know what you think by [opening issues in the repo](https://github.com/sortxyz/react-components) for new feature requests, feedback, or general questions.

---

_P.S. Interested in a free Sort hoodie? [Complete our Developer Survey](https://sort.xyz/survey) and we'll mail you one!_


![Sort hoodie](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd3v1l5vkm2bmkd92pv4.png)

-- Your friends at [Sort](https://sort.xyz)