teleren/devto huggingface dataset:
Vulnerabilities in Cryptographic Algorithms
Tags: md5, sha256, cryptography
Published: 2022-10-08 19:21:17

We all have used Cryptographic algorithms to Secure our data and passwords.
But are they all completely secure?
Let's see for the two most common ones

* [SHA2](#SHA2)
* [MD5](#MD5)

## SHA2 (256, 512, 224, 384)

This family of hash functions relies on sounds and numbers to create a checksum value. The resultant checksums are vulnerable to length extension attacks, which involve a hacker reconstructing the internal state of a file by learning its hash digest.

Public attacks on SHA-2 have been happening since 2008. Just like what happened with SHA-1, the attacks against SHA-2 have been getting increasingly better and weakening SHA-2 over time. Some attacks have SHA-2’s effective protection down to 237. Some of the latest attacks, publicly announced in 2016, consider SHA-2 attacks to already be “practical”. 

## MD5

This hash function creates a checksum value, but each data will not necessarily have a unique hash, so it is open to vulnerabilities if a hacker swaps out some data with the same checksum value.

Desired hash with a different plaintext can be generated maliciously in MD5.

---

So we are not that safe as we thought to be...

To Know More Visit:

1. [Know about Checksums](https://www.techtarget.com/searchsecurity/definition/checksum#:~:text=A%20checksum%20is%20a%20value,running%20a%20cryptographic%20hash%20function.)
2. [ISC2 Community](https://community.isc2.org/t5/Tech-Talk/SHA-2-Vulnerability/td-p/25746)
3. [Stack Exchange](https://security.stackexchange.com/questions/138363/why-is-md5-considered-a-vulnerable-algorithm)
Alterar tabla de base de datos y agregar llaves foraneas.
Tags: sql
Published: 2022-10-08 19:18:52

AQUÍ UN EJEMPLO CON UNA TABLA FACTURAS A LA CUAL QUEREMOS AGREGAR RELACIÓN A TABLA MESEROS, MESAS, TURNOS , ESTACIONES, Y ENCABEZADOS.

``` sql
alter table Facturas add CONSTRAINT FK_FFE foreign key(IdEncabezado) references EncabezadosFacturas(IdEncabezado);
alter table Facturas add CONSTRAINT FK_FFEstacion foreign key(IdEstacion) references Estaciones(IdEstacion);

alter table Facturas add CONSTRAINT FK_FFMesero foreign key(IdMesero) references Usuarios(IdUsuario);

alter table Facturas add CONSTRAINT FK_FFM foreign key(IdMesa) references Mesas(IdMesa);
alter table Facturas add CONSTRAINT FK_FFT foreign key(IdTurno) references Turnos(IdTurno);
```
My Top 5 Commands for Hacktoberfest
Tags: hacktoberfest, bash, programming, productivity
Published: 2022-10-08 18:57:24

In my opinion, every developer should customize their command line environment to be as efficient as possible! Like other languages, you can use existing libraries and commands to automate frequent tasks. Here are my go to commands that I use as tools within other scripts.

## 1. The `Command` Command
This command is super useful for determining when a command exists. The `command` command is similar to the `which` command, however, you can ignore the output when a command is not found.  Since the path of a command only displays when a particular command exists, the `command` command is great for if statements in your script.

```
if ! command -v MyCommand; then
    echo "MyCommand could not be found"
    exit
fi
```

## 2. The `xargs` Command
This command is a lot like the method `map` in popular languages like JavaScript, Python, or Ruby.  This command allows devs to run another command for each space, tab, newline, or EOF (you can change the delimiter). This is my go to command when parsing lists or csv files.

```
# get line count for each php file
ls *.php | xargs wc -l
```

## 3. The `find` Command
This command is like `ls` on steroids. It can list out folder contents but it can also walk a file tree.  This is super useful if you want to find a file with a specific name but you don't know where it is. This command could be a whole other article because it has advance querying capabilities.

```
find $PWD -name "*.php"
```

## 4. The `curl` Command
This command is all you need for fetching remote data through common protocols like FTP, HTTP/S, LDAP, MQTT, SMB, Telnet, etc. As an average Joe, I tend to use curl for consuming REST APIs. For example, you could get JSON from GitHub's or Reddit's public API. 
```
curl -s https://api.github.com/repos/forem/forem/commits\?per_page\=5
```

## 5. The `jq` Command ([Requires Install](https://stedolan.github.io/jq/download/))
This is a command line utility built specifically for parsing JSON. It can index JSON objects/arrays, and it can also handle advanced queries, optional chaining, conditionals, and more.  If you are consuming JSON in your bash scripts, this is a must have.
```
# get a list of unique commit authors from GitHub repo
curl -s "https://api.github.com/repos/forem/forem/commits?per_page=20" \ 
| jq -r '[.[].commit.author.name] | unique | .[]'
```

## 6. Bonus: The `man` Command
Most well engineered commands have a `--help` flag but sometimes that flag only shows you which arguments are accepted.  If you want to get a full overview of how a command works and sometimes "why it works" you should use the `man` command.  This command will show you a specific manual page for a command. Yes, some commands have multiple pages.

```
man find
man 3 echo
man 7 hostname
```

## Conclusion / takeaways
Bash scripting can be overwhelming but once you break down your scripts into components which can be handled by other tools, it becomes a very powerful language for getting things done.
Substring of length k with k-1 distinct elements
Tags: geeksforgeeks, solution, slidingwindow, algorithms
Published: 2022-10-08 18:35:02

## Problem Statement

Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. 

Link to problem statement:: https://practice.geeksforgeeks.org/problems/substrings-of-length-k-with-k-1-distinct-elements/1

> Example 1:

```
Input:
S = "abcc"
K = 2
Output:
1
Explanation:
Possible substrings of length K = 2 are
ab : 2 distinct characters
bc : 2 distinct characters
cc : 1 distinct character
Only one valid substring exists {"cc"}.
```

> Example 2:

```
Input:
S = "aabab"
K = 3
Output :
3
Explanation:
Possible substrings of length K = 3 are
aab : 2 distinct characters
aba : 2 distinct characters
bab : 2 distinct characters.
All of these Substrings are a possible answer,
so the count is 3.
```

#### Expected Time Complexity: O(|S|)

#### Expected Auxiliary Space: O(1)

## Solution
The problem could be approached with help of two pointers as the length of the expected string is constant K. So the window between the two pointers let's say left(*l*) and right(*r) is the same and just needs to slide this window one by one character.
The sliding will encounter the elimination of the previous character and the inclusion of a new character. According to this, character map should be updated. The character map is the map maintaining, characters with their frequency in the window.


```
class Solution {
    static int countOfSubstrings(String S, int k) {
        char[] s = S.toCharArray();
        int l = 0;
        int r = 0;
        int cnt = 0;
        HashMap<Character, Integer> map = new HashMap<>();
        
        // initial map setting for window
        for(; r < k; r++) {
            map.put(s[r], map.getOrDefault(s[r], 0) + 1);
        }
        
        int res = map.size() == k - 1? 1 : 0;
        
        // gradually incrementing window
        for (; r < s.length; r++, l++) {
            // adding the character
            map.put(s[r], map.getOrDefault(s[r], 0) + 1);

            // removing character
            if( map.get(s[l]) == 1 ) {
                // remove character 
                // if it was the only character
                // into the window
                map.remove(s[l]);
            } else {
                map.put(s[l], map.get(s[l]) - 1);
            }
            if(map.size() == k-1) res++;
        }
        
        return res;
    }
}
```
How to pass coding interview for companies like Amazon, Facebook or Microsoft?
Tags: programming, beginners, leetcode, codinginterview
Published: 2022-10-08 18:32:24

For many people coding interviews may sound scary, but when you know a bit more about them they actually not that intimidating.

Such interviews usually consist of simple to medium Leetcode-style coding challenges. Usually you will be able to choose any programming language and will have around 20 minutes to solve the task.

If you want to learn more and also learn what strategy I personally would be using to approach such interviews please check out this video:

{% embed https://youtu.be/on2Aisa96mE %}
Try using websocket with Go Fiber for the first time
Tags: websocket, go, gofiber, chat
Published: 2022-10-08 18:19:22

## Objective
I want to implement simple chatroom with websocket (in go fiber middleware)

---

## Step (code in every step will be in `main.go`)
1) make channels for receive commands `chan` and map channels and user in rooms

![chan-and-map](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbm4op4buu4ywn5tqtko.png)

2) write function to receive command from connection

![func-listen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg6ut6dqlbbznaq2uzvy.png)

3) set endpoint to make connection

![set-path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lpwpujjm8qbf7po1xc4.png)
Exercism #4: Amusement Park Improvements Exercise
Published: 2022-10-08 17:39:25

```
class Attendee
  def initialize(height)
    @height = height
  end
  def issue_pass!(pass_id)
    @pass_id = pass_id
  end
  def revoke_pass!
    @pass_id = nil
  end
  # Do not edit above methods, add your own methods below.
  def has_pass?
    if @pass_id != nil
      pass_id = true
    else
      pass_id = false
    end
    # raise 'Please implement the Attendee#haspass? method'
  end
  def fits_ride?(ride_minimum_height)
     if @height < ride_minimum_height
      ride_minimum_height = false
    else
      ride_minimum_height = true
    end
    
   # raise 'Please implement the Attendee#fits_ride? method'
  end
  def allowed_to_ride?(ride_minimum_height)
    fits_ride?(ride_minimum_height) && has_pass?
    
    # raise 'Please implement the Attendee#allowed_to_ride? method'
  end
end
```
The exercise was to improve the Amusement Park system to allow or reject visitors that have a pass or not and have a qualifying height.

Originally, I did allowed_to_ride? as a if else statement to analyze if both fits_ride? and hass_pass? is true, then it will return allowed_to_ride? true.

However, the if statement didn't work and so I saw this as a solution:

`fits_ride?(ride_minimum_height) && has_pass?`

This works because it already brings a boolean with the end and saves it onto ride_minimum_height. 

According to the mentor, doing an if else statement would be redundant because both allowed_to_ride? and fits_ride? save values onto (ride_minimum_height)
Controlled Forms
Published: 2022-10-08 17:38:29

A controlled form is a form that derives its input values from state. While this means you have to type a bit more code, you can now pass the value to other UI elements too, or reset it from other event handlers.

For controlled inputs you will need a corresponding state and then a class method to update that state with changes. Form input values can be set to state values and then updated via React events.

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

To access the fields in the event handler, you can use the event.target.name and event.target.value syntax.

To update the state, you can use square brackets [bracket notation] around the property name.

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

In React:
- the value of a textarea is placed in a value attribute. 
- the selected value is defined with a value attribute on the select tag:
Angular async pipe
Tags: angular, typescript, rxjs
Published: 2022-10-08 17:35:31

The Angular async pipe is used to show values of an observable in the html of a component. The big advantage is that Angular will handle subscribing and unsubscribing to the observable and you will not have unused subscriptions.

## Without async pipe

Imagine we are building a component to show some quotes

```ts
export class QuotesComponent implements OnInit {
  quotes: string[] = [];

  ngOnInit(): void {
    of([
      'Amor fati',
      'Memento mori',
      'Summum Bonum'
    ]).subscribe((values) => {
      this.quotes = values;
    });
  }
}
```

```html
<div *ngFor="let quote of quotes">
{{quote}}
</div>
```
Now to handle the unsubscription we would also have to implement the onDestroy method, make the observable$ a class level variable and unsubscribe onDestroy of the component. Thats where the async pipe comes in.

## With async pipe

```ts
export class QuotesComponent {
  quotes$: string[] = of([
      'Amor fati',
      'Memento mori',
      'Summum Bonum'
    ]);
}
```
Here we use `| async` to handle the subscription

```html
<div *ngFor="let quote of quotes$ | async">
{{quote}}
</div>
```

Besides the advantage of not having to handle the subscriptions manually it also cleans up the code quite a bit
Being a Developer Advocate: Week Five
Tags: devrel, learninpublic
Published: 2022-10-08 17:32:14

This week was all about documentation and giving the first talks at in person conferences with my new talk [The Future of UI Testing](https://www.slideshare.net/JohannesDienst1/the-future-of-ui-testing-challenges-in-ui-automation).

# Docs as Code
Luckily we use Docs as Code to write technical documentation. Unfortunately with Docusaurus... a framework not familiar to me 🐢. So there is a learning curve involved that slows me down

But writing your docs in a plain text format like Markdown makes it so easy to review and spot bugs. I can not recommend it enough 🤩 

# Docusaurus - Pros and Cons
Docusaurus is a well thought out framework. Many functionalities we need are there out of the box:

* Relative links to .md files
* Easy versioning
* Google Tag Manager support via plugin
* Edit Page on Github link

What I do not like is that some functionality is missing and as easy to add.

For example I wanted to add a link that opens in a new tab. Only possible with plain HTML which is kind of an ugly workaround.

# Giving the First Talk with Livedemo
This week I also attended two conferences with my Talk mentioned above.

One Talk at Software QS-Tag was in english. A First for me when it comes to in person conferences!

Also some livedemos where included and therefor I was extremely nervous because with livedemos you never know if they work.

Luckily enough everything went fine and both audiences where very engaged!

Also the hallway track and discussions are what make in person conferences special as I learned a lot of new things, talked to so many smart people and also got great feedback for our product.
7 Spicy Tailwind CSS Buttons
Tags: webdev, design, tailwindcss
Published: 2022-10-08 17:23:49

Buttons. Ahhh boring buttons. The most basic element we love to neglect. But buttons don't have to be boring. Here are 7 spicy button designs using Tailwind CSS.

## 1) Icon

Adding an icon to a button is a nice cherry on top of it's design and can add some context for its intended action.
![Tailwind icon button](https://i.imgur.com/lq6cHLG.png)

## 2) Solid

Standard button to draw a user’s attention to action. Great for primary actions.
![Tailwind solid button](https://imgur.com/euaiSkQ.png)

## 3) Outlined

Draws attention but not to much. Great for secondary actions.
![Tailwind outlined button](https://imgur.com/iCqlEY9.png)

## 4) Dark & Square

Square buttons should only be used if the rest of your design is lacking border radiuses. Usually meant for a more business-like theme.
![Tailwind dark button](https://imgur.com/M2CLS30.png)

## 5) Fully Rounded

A fully rounded button is meant for more light-hearted designs. Again, if your using rounded buttons, keep the rest of your design consistent with it.
![Tailwind rounded button](https://imgur.com/vDdH2I2.png)

## 6) Raised

Raised buttons give depth to the page and make the element appear closer to the user, giving it a sense of purpose.
![Tailwind raised button](https://imgur.com/atcha2j.png)

## 7) Smooth
Smooth buttons are great for secondary actions. Their designs don't draw as much attention as a solid primary button.
![Tailwind smooth button](https://imgur.com/UAhzGKe.png)

## Beautiful Tailwind CSS Landing Pages

If you enjoyed this, consider checking out my new project - Tailwind Sites

There you will find Expertly crafted Tailwind CSS landing pages. Get a head start on your next big idea. Beautifully designed. Expertly coded.
Using the catchError pipe
Tags: typescript, javascript, rxjs, angular
Published: 2022-10-08 17:14:52

The old way of catching errors in RxJS was a method per subscription like so. Imagine an app using a http service to get some data

```ts
class yourHttpClient {
  get<T>() : Observable<T> {
    return this.http.get<T>('endpoint');
  }
}

yourHttpClient.get().subscribe(() => {
    // Your logic
  },
  (error) => {
    console.log(error);
  }
);
```

The downside to this is that every subscription needs to catch the errors and handle them accordingly.

## The catchError pipe

Instead we can use the catchError pipe in the HttpClient itself to handle our errors. As you can see in the catchError RxJS pipe the error is logged and returned and you no longer need error logic when creating the subscriptions

```ts
class yourHttpClient {
  get<T>() : Observable<T> {
    return this.http.get<T>('endpoint').pipe(
      catchError((error) => {
        console.log(error);
        return error;
      })
  }
}

yourHttpClient.get().subscribe(() => {
    // Your logic
  }
);
```

Looking at this example we can improve it a bit more, we know we only get a single result from the get method. So we can add the `first()` operator to the get request to close the subscription

```ts
class yourHttpClient {
  get<T>() : Observable<T> {
    return this.http.get<T>('endpoint').pipe(
      catchError((error) => {
        console.log(error);
        return error;
      }),
      first()
  }
}
```
Ordenação por seleção - Selection Sort
Tags: javascript, algorithms, algoritmos, braziliandevs
Published: 2022-10-08 17:08:35

Seguindo nossos estudos vamos agora para o **Selection Sort**, um algoritmo simples que é um pouquinho diferente que o último citado o [Bubble sort](https://dev.to/dormin/ordenacao-por-flutuacao-bubble-sort-1hfe) seguindo a notação Big O a complexidade é O(n²)
não é um algoritmo rápido mas como nosso objetivo é estudo ele nos serve bem :D
##Como ele funciona?
A ordenação por seleção é um algoritmo de ordenação baseado em se passar sempre o menor valor do vetor para a primeira posição (ou o maior dependendo da ordem requerida), depois o de segundo menor valor para a segunda posição, e assim é feito sucessivamente.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6rqz66o9kca8aq0l32u.gif) 
Na imagem acima é exemplificado!

Ou seja ele é beeem parecido com o bubble sort que joga o maior valor para o final do vetor, em velocidade nós não ganhamos muito ¯\_ (ツ)_/¯

Mas vamos para o código
```JavaScript
let arr = [17, 14, 23, 2, 4, 9, 15, 1, 0, 3, 5]

for(let i = 0; i < arr.length; i++){
    let min = i
    let aux 
    for(let j = i + 1; j <= arr.length; j++){
        if(arr[j] < arr[min]){
            min = j
        }
    }
    if (i != min) {
        aux = arr[i]
        arr[i] = arr[min]
        arr[min] = aux
    }

}
console.log(arr)
```
Como dito o código não é muito diferente, ainda temos um loop aninhado que resolve um valor por vez como é visto na imagem.
Muito obrigado por ler até aqui, fiquem a vontade em me enviar dúvidas comentários ou críticas.

##Referências

<a target="_blank" href="https://www.amazon.com.br/Entendendo-Algoritmos-Ilustrado-Programadores-Curiosos/dp/8575225634/ref=sr_1_1?keywords=entendo+algoritmos&amp;qid=1665248064&amp;qu=eyJxc2MiOiIwLjczIiwicXNhIjoiMC4yOSIsInFzcCI6IjAuMzQifQ%253D%253D&amp;sprefix=entendo+al%252Caps%252C234&amp;sr=8-1&_encoding=UTF8&tag=dormin0f-20&linkCode=ur2&linkId=c4974c19ccad271886d077fca1397935&camp=1789&creative=9325">Entendo algoritmos</a> - Aditya Y. Bhargava 

[Wikpédia selection sort](https://pt.wikipedia.org/wiki/Selection_sort)
DPS909 Blog :First contirbution in HACKTOBERFEST
Tags: opensource
Published: 2022-10-08 16:42:23

Hey everyone, thanks for reading my Blog post. This post is regarding my first contribution to the [HACKTOBERFEST](https://hacktoberfest.com/).

## Overview
In Release 0.2 we were asked to participate in the Hactoberfest so that we could contribute to real open source projects. Furthermore, the main goal of this release is to help you gain experience and confidence in contributing to open source projects through direct involvement in a number of real projects.

## Finding right Open Source Projects

Finding the right open source project was really challenging for me, we were asked to work on any GitHub hosted open source project with the repo with the [Hacktoberfest topic](https://github.com/topics/hacktoberfest) and/or [Issues with the Hacktoberfest label](https://github.com/search?q=label%3Ahacktoberfest&state=open&type=Issues).
For my first contribution in open source project i have choose this project [Basic-memory-game](https://github.com/Aatmaj-Zephyr/Basic-memory-game). 
This is Basic Concentration (card game). It is a particularly good game for young children, though adults may find it challenging and stimulating as well.

## Finding Issue 

Issue which i have found in [Basic-memory-game](https://github.com/Aatmaj-Zephyr/Basic-memory-game) is about the code indentation.

[Code indent not proper](https://github.com/Aatmaj-Zephyr/Basic-memory-game/issues/2).
In this issue we were asked to `Add code indentation and workflow for automated indentation`

## Fixing the Issue

The issue was simple, so i forked the code locally on my machine and fixed the code indentation and created the workflow which will help to run the prettier action each time when we have push or pull request on the actual code.

## Pull Request

After fixing the code and creating the automated workflow for the prettier to run on each push and pull I have created this [PR](https://github.com/Aatmaj-Zephyr/Basic-memory-game/pull/80).

## Conclusion

Working on Open source projects has really helped me a lot to learn about the new way and let me gain some experience on how to work on open source projects. 

```
Thanks
```
Day18 of #100DaysOfCode
Tags: 100daysofcode, git, github, webdev
Published: 2022-10-08 16:12:59

Day18

I’m now reviewing how to use Git and Github 😂 because my code has gotten to a point where I’m always afraid and paralyzed that I’m going mess up something in the code and everything is going to come crashing down 😂

Finally decided to finalize my personal github account. (I have been procrastinating because I have a few github accounts and couldn’t decide which one to use because one is a personal account and others are work-related.

Now you guys can follow me on Github![Click here](https://github.com/jayyoot)