teleren/devto huggingface dataset:
Configure Python Formatter and Linter for a VSCode Dev Container
Tags: vscode, devcontainer, python, cleancode
Published: 2023-01-10 16:52:26

## tl;dr

Code example here:
[Gist of only devcontainer.json](https://gist.github.com/IzzleNizzle/997f36145db751ca6f340af8e5dde07c)
[Full Example Repo](https://github.com/IzzleNizzle/Python-Dev-Container-w-Linter-Formatter) – I recommend cloning and opening with Github Codespaces to see this in action


## Goal

I had a goal to set up a python coding environment, pre-configured with all needed tools to develop, lint and format my code. I found that with a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) this could be a relatively frictionless process and be ready to go immediately following the initial devcontainer build process. 


## Benefit

The top benefits I want from this is twofold. First is a clear coding standard easily adopted that ensures consistent code styling and practices. Second is fast and easy onboarding. This ensures that as I load my code, I can get up to speed quickly and tools are configured automatically.


## Drawbacks

This approach is really convenient, but it is attached to VsCode and docker devcontainers. So it's not super portable. Also linting and formatting are opinionated topics, so inevitably someone is going to disagree with my approach.

For me these drawbacks are no big deal, the benefit outweighs the drawbacks.


## How to set up

The [devcontainer.json](https://gist.github.com/IzzleNizzle/997f36145db751ca6f340af8e5dde07c) holds all the configuration for this to work.

The fastest way to see this work is by cloning the full example repo linked above, then opening with Github Codespaces. It will build and everything will be ready to go. You can test and see that linting and formatting happen automatically on file save, as dictated by the rules set in the devcontainer.json file.

If adding a .devcontainer directory and file into an existing project in VsCode, bring up the Command Palette. On mac it’s `⇧⌘P` Then search for Reopen in Container. This should do all the work for you.

Be sure you have this extension installed: ms-vscode-remote.remote-containers

The initial build process takes a few minutes, works on all platforms (M1 mac tested).

This example uses the [Docker in Docker](https://github.com/devcontainers/templates/tree/main/src/docker-in-docker) dev container. There are others that may suit you better, feel free to customize to your needs. This example doesn’t rely on the exact type of dev container used.
Timeout with Fetch API
Tags: javascript, node, api
Published: 2023-01-10 16:42:04

---
title: Timeout with Fetch API
date: 2023-01-10 16:42:00 UTC
published: true
tags: ['javascript', 'node', 'api']
canonical_url: https://sevic.dev/notes/timeout-fetch/
---

Setting up a timeout for HTTP requests can prevent the connection from hanging forever, waiting for the response. It can be set on the client side to improve user experience, and on the server side to improve inter-service communication. Fetch API is fully available in Node as well from version 18.

[AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) can be utilized to set up timeouts. Instantiated abort controller has a `signal` property which represents reference to its associated `AbortSignal` object. Abort signal object is used as a `signal` parameter in the request with Fetch API, so HTTP request is aborted when `abort` method is called.

```js
const HTTP_TIMEOUT = 3000;
const URL = 'https://www.google.com:81';

(async () => {
  const controller = new AbortController();
  const timeoutId = setTimeout(() => controller.abort(), HTTP_TIMEOUT);

  try {
    const response = await fetch(URL, {
      signal: controller.signal
    }).then((res) => res.json());
    console.log(response);
  } catch (error) {
    console.error(error);
  } finally {
    clearTimeout(timeoutId);
  }
})();
```

Use this snippet also to simulate aborted requests.

### Boilerplate

Here is the [link](https://sevic.dev/nestjs-starter?ref=devto-fetch) to the template I use for the development.
Wrapping useContext in custom hook and HOC adapter
Tags: react, typescript, javascript, programming
Published: 2023-01-10 16:34:53

You have a component and there are lots of nested sub-component. There is need to share the state between the sub component. We create a state in parent component and pass down the state to the nested component.

It is very inconvenient if there is vary few sub-component is using the state and it is nested level down.

Other way to solve this problem is `useContext` Hook.
wrap the parent component with ContextProvider and now we can use the state anywhere in sub-component.

If you have a lot of Context.The code readability decreases and it gets ugly.

One of the way to make it better is using custom hook and Provider HOC on top of the useContext.

Let's say we have a isAuth state to be shared in sub-component.

### Create AuthProvider HOC wrapper and useAuth hook

```React
const AuthContext = React.useContext<boolean>(false);

export type AuthProviderProps = {
   children: JSX.Element | JSX.Element[];
   isAuth: boolean;
}
export const AuthProvider = ({children, isAuth} : AuthProviderProps) => {
   return (<AuthContext.Provider value={isAuth}>
      {children}
   </AuthContext.Provider>);
}

export const useAuth = () => {
   const isAuth = React.useContext(AuthContext);
   return { isAuth };
}
```

### How to use the hook and HOC
Use the AuthProvider HOC in parent component to wrap the child components.

```react

const [isAuth, setIsAuth] = React.useState<boolean>(false);
....
....
return (
   <AuthProvider isAuth={isAuth}>
      ...
      child components
      ...
   </AuthProvider>);
```

Somewhere in nested child component, use the useAuth hook to access the isAuth state.
```react
const {isAuth} = useAuth();
...
...
return <div> You are {isAuth ? "" : "not"} authenticated</div>
```
GO88 - Chơi Game GO88 Mới Nhất 2023 | Tải GO88 Android/IOS
Published: 2023-01-10 16:33:08

https://go88.land/ Go88 ✔️ Cộng đồng game thủ tham gia cá cược trực tuyến trên thiểt bị di động và PC✔️ Tài xỉu, bắn cá, sicbo, quay hũ✔️✔️✔️
37 Ông Ích Khiêm, Phường 10, Quận 11, Thành phố Hồ Chí Minh, Việt Nam
0868686868
https://slides.com/go88land
https://solo.to/go88land
https://scrapbox.io/go88land
https://wakelet.com/@go88land
https://heylink.me/go88land/
https://www.bloggang.com/mainblog.php?id=go88land
Your favorite article of 2022
Tags: opensource, news, microservices, luos
Published: 2023-01-10 16:32:07

📈 We have been looking at the content we’ve shared with you over the past year and since the **community** has grown so much, we have brought back a favorite of yours! 

🎖️ **The article on l’embarqué** that announced that Luos engine is now **plug-and-play compatible** with the ESP32 family was your favorite article this past year!

⏩ [Take a look]( https://www.lembarque.com/article/le-francais-luos-apporte-la-notion-de-microservices-aux-microcontroleurs-a-radio-integree-esp32)
Getting Telescope to work
Tags: webdev, javascript, programming, tutorial
Published: 2023-01-10 16:23:25

#### Setting up Telescope ####

Setting up telescope this time around is fairly easy. Following the docs [environment setup](https://telescope.cdot.systems/docs/getting-started/environment-setup), should allow the user to be able to run at least the "front-end" of the program.

#### Complications ####

The issue I had with running telescope initially was that I was unable to gain access of the back-end of the program. I asked one of the contributors to help me work on my issue by creating a fresh telescope repository in my computer.

The set up was a lot faster this time around due to having [Ubuntu](https://ubuntu.com/) and [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install) installed in my computer. There was no issue when running the program locally this time around. The only problem was I did not install [pnpm](https://pnpm.io/) globally last time; I had to install it globally this time around as to not run to this issues.

With the program finally running locally this time around, I was excited and scrolled down. Only to find out that there are no database. I never got in touch with docker as much as I should have from the previous semester, thus making my understanding of it a bit lackluster. With the help of another contributor, this portion didn't take longer than it would have been if I was by myself.

> Seeding Database

This portion confused me in a sense that what my partner told me is the opposite of what the doc shows. The doc describe that we have to "pause" the `parser` after we have send the command of `copy` and `init`. However, what my partner and I did is that we paused the `parser` before doing any of the command. It worked at the end, and the database was displayed, but I'm not sure if doing it the other way would've caused an issue.

I asked around in slack regarding this, and it seems that both ways are fine, and it doesn't cause any glaring issues in the program.

#### Learning Experience ####

I wouldn't say I had much to learn for setting up telescope, aside from learning a bit more of docker. It's hard to keep my head around having to work with a larger project, but I am working on that.
Are You Aware of XSS Attack?
Published: 2023-01-10 16:23:16

<p>#CyberlyAware - CyberPodYoruba</p>
<p>Cyber attacks are rampant these days, and one of the most effective ways of curbing them is through training of individuals so they can be aware of these attacks.</p>
<p>In this post, we will be talking about Cross-Site Scripting (XSS).</p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=y19VcmzM_p0"><em>You can watch CyberPodYoruba here.</em></a></p>
<h2 id="heading-cross-site-scripting-xss"><strong>Cross-Site Scripting (XSS)</strong></h2>
<p>Cross-site scripting (XSS) is a security attack usually a code injection that targets web applications that deliver malicious, client-side scripts to a victim’s web browser for execution. Web applications and vulnerable websites are used to carry out cross-site scripting attacks. Targets are not attacked directly; they are attacked only when they interact with these applications or websites.</p>
<p>For instance, an unsuspecting user will visit a website that is compromised, at this point the attacker’s malicious script is executed and loaded by the user’s browser. This can lead to session hijacking, theft of sensitive information and many more. Due to JavaScript’s wide support across many web browsers and platforms, it has been a popular choice for cross-site scripting (XSS) attack authors, but in the real sense, an attack can be done with any language that is supported by web browsers.</p>
<p><a target="_blank" href="https://rss.com/podcasts/rollademy"><em>Listen to CyberPodYoruba</em></a></p>
<h3 id="heading-real-world-xss-attack-example">Real-world XSS Attack Example</h3>
<p>UK British Airways, in <a target="_blank" href="https://www.wired.com/story/british-airways-hack-details/">2018</a> was a victim of a data breach affecting 380,000 booking transactions. The attackers sent customers' data back to a server they controlled by using XSS to exploit the site’s JavaScript.</p>
<p>Like we mentioned before, the best and most affordable countermeasure is adequate training of individuals about XSS attacks.</p>
<p>#2Articles1Week</p>
</br><p style="color:#757CF9;">This article is published w/ <a target="_blank" href="https://scattr.io?ref=dev">Scattr  ↗️</a></p>
Why Full-Stack Development Is The Best Course To Pursue In 2023?
Published: 2023-01-10 16:23:02

Have you ever wondered if we are all surrounded by software, be it our mobile phones or laptops or the applications and websites in them?In 2022 with everything going digital and our constant involvementin  applications like Facebook and Instagram,have you ever thought about how new content pops up every time you hit refresh? Well,that's where the Full Stack Developer's role comes into play.If you also want to be a successful Full Stack Developer then enroll yourself in a [Full Stack Developer Training course in Noida. ](https://www.uncodemy.com/course/full-stack-development/)
3 Ways To Remove Duplicates in an Array with JavaScript
Tags: javascript, tutorial, webdev
Published: 2023-01-10 16:19:19

---
title: 3 Ways To Remove Duplicates in an Array with JavaScript
published: true
description: Here are 3 ways you can easily remove duplicates in a data array in JavaScript
tags: javascript, tutorial, webdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yylmngtp8c6rukpp6x6s.png
canonical_url: https://www.jenniferbland.com/3-ways-to-remove-duplicates-in-an-array-with-javascript/
---

Sometimes you have an array of data and you want to remove all duplicates from the array. In this article, I will show you three ways in which you can do this.

## 1) Remove duplicates using forEach and includes

The Array `includes()` method determines whether an array includes a certain value among its entries, returning `true` or `false` as appropriate.

With this method, we will create a new empty array. All unique values from our array will be put into this array. We will loop over our array of data and check if the current item is in our new array. If it isn't then we put it in our new array. If it is in our new array then we do nothing.

```javascript
let myData = [1, 2, 2, 4, 5, 5, 5, 7, 'Hello','World', true, false];

let uniqueValues = [];
myData.forEach((item) => {
	if (!uniqueValues.includes(item)) {
		uniqueValues.push(item);
	}
});

console.log(uniqueValues); // [1, 2, 4, 5, 7, 'Hello', 'World', true, false]
```

## 2) Remove duplicates using filter and indexOf

The `indexOf()` method returns the first index at which a given element can be found in the array, or -1 if it is not present.

The `filter()` method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.

With this method, we do not have to initially define an empty array. The `filter()` method will return an array so we just assign this array to a value.

```javascript
let myData = [1, 2, 2, 4, 5, 5, 5, 7, 'Hello','World', true, false];

let duplicateValues = myData.filter((item, index) => {
    return myData.indexOf(item) == index;
});

console.log(duplicateValues); // [1, 2, 4, 5, 7, 'Hello', 'World', true, false]
```

## 3) Remove duplicates using a Set

The `Set` object lets you store unique values of any type, whether primitive values or object references.

This method requires us to convert our data array to a set. Duplicates will be automatically removed. Then we convert the set back to an array.

```javascript
let myData = [1, 2, 2, 4, 5, 5, 5, 7, 'Hello','World', true, false];
let uniqueValues = [...new Set(myData)];

console.log(uniqueValues) // [1, 2, 4, 5, 7, 'Hello', 'World', true, false]
```

## Let's Connect

Thanks for reading my article today. If you like my content, please consider [buying me a coffee](https://www.buymeacoffee.com/JenniferBland) ☕.
Mac Tips: How to Use KeyChain to Manage Your GitHub Credentials
Tags: github, mac, keychain
Published: 2023-01-10 16:12:52

---
title: Mac Tips: How to Use KeyChain to Manage Your GitHub Credentials
published: true
description: 
tags: GitHub, Mac, KeyChain
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4qktmf03jd2sg9792oj.png
# Use a ratio of 100:42 for best results.
# published_at: 2023-01-10 15:58 +0000
---

Are you tired of constantly being prompted for your GitHub password every time you want to push or pull a repo? Look no further than Mac's KeyChain feature.

When you clone a repository over HTTPS, Git may prompt you for your password each time you want to push or pull. But with Mac's KeyChain, you can easily store your GitHub credentials and never have to remember your password again.

First, make sure that you have the git credential-osxkeychain command installed. If not, simply install Git using the Homebrew package manager by running the command "brew install git" in your terminal.

Once you have that installed, tell Git to use KeyChain for storing your credentials by running the following command:
```
git config --global credential.helper osxkeychain
```
After running this command, the next time you clone a repo via HTTPS, you'll be prompted to grant access to KeyChain. Once you do that (**always allow**), any future authentication will be done transparently by Git reading the KeyChain record. No more remembering passwords, or repeatedly typing them in – it's that easy!

So, next time you are cloning a repo and prompted for a password, follow these simple steps and keychain will help you to store the credentials and you can easily pull or push the repos with out the need of providing password.
Liveness Probes in kubernetes
Tags: devops, kubernetes, tutorial, livenessprobe
Published: 2023-01-10 16:06:49

Suppose you’ve created a service and a deployment with the replica count as ‘n’, this means that there will be at least ‘n’ number of pods running which will be part of the service we create. Now you need to run your application on these pods, but are you sure if the pods and containers are healthy or not?
The answer is 	NO and to get sure for the same we use livenessprobe. Now this livenessprobe is defined inside the deployment.yml file.

Syntax:
```
livenessProbe:
httpGet: 
		path: /status
		port: 8080
	periodSeconds: 10
	initalDelaySeconds: 30
```

Example:
```
apiVersion: apps/v1
kind: Deployments
metadata:
      name: first-dep
      labels: 
           app: hello-world
spec:
	replicas: 3
	selector:
		matchLabels:
			app: hello-world
	template:
		metadata:
			name: first-pod
			labels: 
				app: hello-world
		spec:
			containers:
				-	name:
					image: 		                        
					livenessProbe:
						httpGet: 
							path: /status
							port: 8080
						periodSeconds: 10
						initalDelaySeconds: 30

```

**path**: it is used to check if the desired output is being received at defined path
**port**: it is the port number of the container i.e. port number at which container is exposedRunning.
**periodSeconds**: This is used to define how often the health check will be performed
**initialDelaySeconds**: this defined time is used as delay between the two simultaneous health checks.
100 Days of Code Challenge: Day 4
Tags: 100daysofcode, python, csharp
Published: 2023-01-10 16:00:49

For Day 4 of the 100 Days of Code challenge with Angela Yu's Python Pro bootcamp, I worked with the random module and was introduced to lists and indexes to create a rock paper scissors game that lets the user play against the computer (which takes a random number from 0 to 2) by inputting any number from 0 to 2 where 0 is rock, 1 is paper and 2 is scissors. 

Here is the Python code:

```
import random
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''
paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''
scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''
rps_art = [rock, paper, scissors] #rock is 0 showing rock art, paper is 1 showing  and scissors is 2
player_choice = int(input("What do you choose? Type 0 for rock, 1 for paper and 2 for scissors \n"))
print(rps_art[player_choice]) #
computer_choice = random.randint(0, 2)
print("Computer chose: ")
print(rps_art[computer_choice])
if player_choice >= 3 or player_choice < 0:
    print("Invalid choice. You lose.")
elif player_choice == 0 and computer_choice == 2: #Player chooses rock and computer chooses scissors
    print("Rock beats scissors. You win!")
elif computer_choice > player_choice:
    print("You lose!")
elif computer_choice < player_choice:
    print("You win!")
elif computer_choice == player_choice:
    print("It's a draw!")
```
I also did the exercise in C# and learnt about the Random class and how it is used. Here is the C# code:

```
string rock = "Rock";
string paper = "Paper";
string scissors = "Scissors";
string[] rps_art = { rock, paper, scissors };
Console.WriteLine("What do you choose? Type 0 for rock, type 1 for paper or type 2 for scissors");
int player_choice = Convert.ToInt16(Console.ReadLine());
Console.WriteLine(rps_art[player_choice]);
Random random = new Random();
int computer_choice = random.Next(0, 2);
Console.WriteLine("Computer chose: ");
Console.WriteLine(rps_art[computer_choice]);
if (player_choice >= 3 || computer_choice < 0)
{
    Console.WriteLine("Invalid choice. You lose");
} else if (player_choice == 0 && computer_choice == 2)
{
    Console.WriteLine("Rock beats scissors. You win!");
} else if (computer_choice > player_choice)
{
    Console.WriteLine("You lose!");
} else if (computer_choice < player_choice)
{
    Console.WriteLine("You win!");
} else if (computer_choice == player_choice)
{
    Console.WriteLine("It's a draw");
}
```
I really enjoyed doing this project and learning about how modules work in Python. Tomorrow, I will do day 5 of the project where I will learn about for loops and develop a project around it.
Small but mighty Bugs(greatest solidity bug)
Published: 2023-01-10 15:56:26

**What are the small but mighty bug?**


  What are the small but mighty bugs are bugs that you have solved multiple times but keep up showing and any time you face this bug you tend to always go to stack overflow flow for an answer. They always make to keep tampering with your code **

```
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.
```
**

I encountered this Bug when i was working a multi-sender smart contract for a client, so the smart contract is a kinda ERC20 contract but with a simple multi-send functionalities , so it during the period of me testing the multi-send function on the smart contract that i came accross this SMALL BUT MIGHTY BUGS.

**

## How i solved it
**

Stack Overflow...Yes Stack overflow the cheat engine for programmers where we copy and paste code from and basically just copied and pasted the error to google and stack overflow showed the right answer which was for me to make some variables and the whole functions in it self payable. This was what i did and it worked.


https://stackoverflow.com/questions/61388743/solidity-transaction-error-the-called-function-should-be-payable-if-you-send-va


   After this bug wasted my time i learnt never to proud again as a developer but to copy the damn small but mighty bugs to google to solve. Let us be humble guys to our code.