teleren/devto huggingface dataset:
Handling our API errors
Tags: rest, go, errors
Published: 2022-12-26 21:12:15

**All the codes that you will see in this post you can check [here](https://github.com/MAAARKIN/hero-api-golang/tree/step-5)**

In the last post, we build a DealWith() method to handle our API errors, but we do nothing at the moment. In this post we will build how to deliver a user-friendly way to show the user our problem. In case the problem is not a registered error (an error that we build and is a part of our application), we will centralize our error stack to share with the developer's team where the problem is (file, method name, and line) to the team solve the possible problem.

To represent our registered errors we will create a error map (errorHandlerMap)  to store an error as a key and a http code as a value.


```go
//cmd/http/helper/error.go
//...

var (
	errorHandlerMap = make(map[error]int)
)
//...

func DealWith(err error) HttpError {
	if errCode, ok := errorHandlerMap[err]; ok {
		return HttpError{Status: errCode, Description: err.Error()}
	} else {
		return HttpError{
			Status:      http.StatusInternalServerError,
			Description: "Internal error, please report to admin",
		}
	}
}

```

Now you can see our DealWith method checks if our errorHandlerMap has an error key registered in our map. If the error that we want to deal with is registered, we will represent a specific Http Code with a specific message. Anything else will be designated as an unregistered error or an error that we don't know how to deal with at the moment.

This map will increase while we creating this app. Not every application error needs to be in this map, but if your error should be delivered with a user friendly message, then this error needs to be registered in this map with a specific http code.

If you see our code probably thinking that our map don't have any error registered, and you right. We will start to register some validations errors in the next post.
Why javascript is So Popular with good points and example.....
Tags: webdev, javascript, beginners, programming
Published: 2022-12-26 21:10:19

JavaScript is a popular programming language because it is easy to learn and use, and it is supported by all modern web browsers. It is a versatile language that can be used to build web and mobile applications, as well as to add interactive features to websites. JavaScript is also widely used because it is a client-side language, which means that the code is executed by the user's web browser, rather than on the web server. This makes it easy for developers to create web-based applications that can run on any device with a web browser, without having to worry about server-side processing or compatibility issues. Additionally, there are many libraries and frameworks available for JavaScript that make it easier for developers to build complex applications quickly.

**There are several reasons why JavaScript is so popular:**

1. **Easy to learn and use**: JavaScript is a high-level programming language that is easy to read and write, even for people who are new to programming. It is also a dynamically-typed language, which means that you don't have to specify the data type of a variable when you declare it. This makes it easier to write code quickly and iterate on ideas.

2. **Supported by all modern web browsers:** JavaScript is supported by all modern web browsers, which means that you can use it to build web applications that will run on any device with a web browser. This makes it a great choice for building cross-platform applications that can be accessed from any device.

3. **Versatility**: JavaScript can be used to build a wide range of applications, including web and mobile applications, as well as to add interactive features to websites. For example, you can use JavaScript to create animations, build games, or create interactive forms and maps.

4. **Large developer community:** There is a large and active developer community around JavaScript, which means that there are many resources available for learning the language and getting help when you need it. There are also many libraries and frameworks available for JavaScript, which make it easier to build complex applications quickly.

5. **Widely used :** JavaScript is one of the most widely used programming languages in the world, which means that there are many job opportunities for developers who are proficient in the language. It is also a great language to learn if you want to build your own projects or start a career in software development.




-
Oracle commerce cloud or salesforce Commerce cloud?
Published: 2022-12-26 21:10:07

I am trying to decide which commerce cloud solutions to use for B2B & B2C.

The goal is that the portal should be able to sync with our partnered manufacturers supply chain in real time so we can provide real time inventory updates to our customers in our website. Also, we should be able to sync all of the product details, specs, product images from our partnered manufacturers. Lastly, we should be able to sync our products with real time inventory with resellers or distributors that are interested in offering our products in their websites.

What is better Oracle commerce cloud or salesforce Commerce cloud?
Exploring XRPL's Advantages: A Guide for Developers
Tags: xrpl, xrp, blockchain, web3
Published: 2022-12-26 20:19:38

Blockchain technology's rapid advancements have revolutionized the tech industry. At the heart of these innovations, the **XRP Ledger (XRPL)** stands out as a robust platform that offers a myriad of benefits to developers. This decentralized, open-source ledger fuses security, efficiency, and adaptability, setting a new benchmark for digital assets management. Let's dive into the key advantages XRPL offers:

## **Ultra-Low Transaction Costs**

The XRPL boasts an intelligent consensus-based transaction fee system that outperforms many other platforms in terms of cost-effectiveness. With an average transaction cost of just **0.00001 XRP**, developers can create applications with minimum overheads, making it a budget-friendly choice for startups and established businesses alike.

## **Unparalleled Scalability**

In the world of blockchain, speed matters. XRPL's impressive capacity to handle up to **1,500 transactions per second** dwarfs most competitors, offering developers the high throughput they need for building large-scale applications.

## **Fortified Security**

XRPL employs an intricate network of validators, where every transaction is cryptographically signed and validated by multiple independent validators. This rigorous security protocol renders any potential manipulation by malicious actors virtually impossible.

## **Exceptional Interoperability**

Interoperability is a cornerstone of XRPL. Designed to interface smoothly with other blockchains and networks, XRPL allows developers to create applications that can seamlessly interact across various platforms, breaking down technological barriers and opening up new possibilities.

## **Dependable Performance**

XRPL's reliability cannot be overstated. It processes transactions swiftly and efficiently, offering consistent performance that developers can bank on for creating applications with stringent performance requirements.

In conclusion, the XRPL stands as a **game-changer** in the blockchain technology landscape. Its combination of low transaction costs, unparalleled scalability, fortified security, exceptional interoperability, and dependable performance makes it an irresistible choice for developers looking to leverage the power of blockchain technology. This is not just about developing applications - it's about shaping the future of digital transactions.
Create Virtual Environment in Python Using Conda
Tags: python, virtualenvironment, conda, programming
Published: 2022-12-26 19:54:47

In this article, we’ll discuss about setting up virtual environments in python projects using conda.

While Anaconda Navigator is a nice tool to use to get an overview, being able to run your code from the command line can be convenient, too. With the conda command, which is luckily extremely easy.

First, you need to open the conda shell. You can do this from Anaconda Navigator if you wish, but you can also run it straight away.

## How to Create Conda environment
On Windows, you can open Anaconda Prompt or Anaconda PowerShell Prompt from the start menu.

For Linux and OS X, the most convenient method is to initialize the shell integration. For zsh, you can use:

```
`$ conda init zsh`
```


....Please visit below link for complete article.
[https://the-tech-monk.medium.com/create-share-python-virtual-environment-using-conda-6dd9112a34f6?source=friends_link&sk=de6321c3e7500a4aad0209158423fdf1](url)
Using Token with next-auth
Published: 2022-12-26 19:35:10

I am building a website by next js and I choose next-auth to handle login and protecting the routes, I managed to do the login in logic, but in order to be able to use post method to my api I need to send the token to my backend which I handled the related route (Backend done by NodeJS). The issue is that I can't reach the token and use it in the header in my requests.
Python swapcase without using Swapcase()
Tags: python, programming, beginners, tutorial
Published: 2022-12-26 19:24:45

We can easily swap the cases of characters in string using the python inbuilt _**swapcase()**_ function.
Casing swapping is simply changing upper case character to lower case character and lower case character to upper case character.
For example:
If we swap case the string "helloWorld" we will get "HELLOwORLD".
###Example of using python _**swapcase()**_
Swap the cases in the string "Welcome to Tano Space".

```
string = "python IS A PROGRAMMING language"
new_string = swapcase(string)
print(new_string)
//it will return "PYTHON is a programming LANGUAGE"
```

It's simple right? Yes. But assuming you are in a technical interview for a python developer role, and the interviewer asked you to write a python thats swap the cases of characters in a string. You can't use the swapcase() function. How then will you be able to achieve such ?
The code below depict one of the ways to write the code.

Let me show you how



```
string = "python IS A PROGRAMMING language"
 new_string = []

for i in string:
    #check if the character is a upper case letter
    if i.isupper():
        #if the character is upper case the change it to lower 
        #case 
        i.lower()
        # add the converted character to the list
        new_string.append(i)
    else:
        i.upper()
        new_string.append(i)

#use the join() to combine the items of the list
print("".join(new_string)
```

###**You are Welcome**###
Install python tkinter on MacOS
Tags: python
Published: 2022-12-26 19:19:14

---
title: Install python tkinter on MacOS
published: true
description: Surprise, it is not explicitly installed on mac with homebrew
tags: python 
# published_at: 2022-12-26 19:09 +0000
---
It is easy pisy when you know how it installs.
The problem with google is a lot of wrong recipes on how to install on a Mac

```bash
brew install python-tk
```
Of course if you install python with homebrew.
Check out these developers background
Tags: developer, background, desktop
Published: 2022-12-26 19:00:45

[Front-end developer Amazing Desktop Background](https://ahmedonour.gumroad.com/l/AmazingDesktopBackground) is a high-quality desktop background designed specifically for front-end developers. This background features a stunning, modern design that is sure to impress and inspire.

With Front-end developer Amazing Desktop Background, you'll get a sleek, professional look that is perfect for boosting your productivity and creativity. The clean, minimalistic design is easy on the eyes and allows you to focus on your work without distractions.

Whether you're a beginner or a seasoned pro, Front-end developer Amazing Desktop Background is the perfect choice for any front-end developer looking to take their desktop to the next level. So why wait? Get your copy today and start enjoying the benefits of a beautiful, inspiring desktop background!

## [Check it out](https://ahmedonour.gumroad.com/l/AmazingDesktopBackground)
how to prevent memory leak in programming with an example
Tags: programming, cpp, cleancode, tutorial
Published: 2022-12-26 18:44:19

Memory leaks can occur in programs when the program dynamically allocates memory for certain tasks, but fails to properly deallocate that memory when it is no longer needed. This can result in memory being consumed unnecessarily, leading to reduced performance and stability issues.

An example of how a memory leak might occur in a program

**Example:**

If we have a program that reads data from a file and stores it in a dynamic array. The program repeatedly reads data from the file and appends it to the array until the end of the file is reached. However, the program does not properly deallocate the memory used by the array after it is no longer needed. As a result, the program will continue to consume more and more memory as it processes the file, leading to a memory leak.

**Code example (C++):**

```
int main() {

int* data = new int[1]; // Dynamically allocate array to hold data

int size = 1;

// Read data from file and store it in array
while (data_available()) {

data[size - 1] = read_data();

size++;

int* temp = new int[size]; // Allocate new array with larger size

std::copy(data, data + size - 1, temp); // Copy data from old array to new array

delete[] data; // Deallocate memory used by old array

data = temp; // Update pointer to new array
}

// Forget to deallocate memory used by array

return 0;
}
```

To prevent this memory leak, we can simply add a line of code to deallocate the memory used by the array after it is no longer needed:

**Code example (C++):**

```
int main() {

int* data = new int[1]; // Dynamically allocate array to hold data

int size = 1;

// Read data from file and store it in array
while (data_available()) {

data[size - 1] = read_data();

size++;

int* temp = new int[size]; // Allocate new array with larger size

std::copy(data, data + size - 1, temp); // Copy data from old array to new array

delete[] data; // Deallocate memory used by old array

data = temp; // Update pointer to new array
}

delete[] data; // Deallocate memory used by array

return 0;

}
```


This will ensure that the program properly releases the memory used by the array when it is no longer needed, preventing a memory leak.

> It's important to note that memory leaks can be more complex than this simple example. In general, using techniques like smart pointers or garbage collection to automatically manage memory, or manually releasing memory using functions like "free()" or "delete".

> it's a good idea to carefully manage memory usage in your programs and to use tools like memory profilers to identify and fix potential memory leaks.

Hope it helps!
How to deploy laravel on shared hosting?
Tags: laravel, deploylaravel, beginners
Published: 2022-12-26 18:30:28

Hello Artisans.

This article details how to deploy the Laravel application on hostinger shared hosting. I’m going to show you How to deploy Laravel on shared hosting. In this article, I will show you how to upload the laravel project to hostinger.

In this article, we will use Hostinger shared hosting to deploy our Laravel application with easy steps. So let's get started.

First, we need to make some changes in our Laravel application, we need to change the public folder name to public_html because many shared hosting provider's domain directory structure is public_html and we can't change it, so we need to make changes to our application to run our application on a live server without writing public keyword next to the domain name and run artisan commands as well.

Don't know how to change the public folder into public_html don't worry let's look at this [article](https://dev.to/mahzaib_mirza/how-to-change-laravel-public-folder-name-5bkl).

I assumed you have changed your public folder name into public_html, So, let's forward.

## Step-1: Make zip file and upload on domain root directory
Make a zip file of your Laravel project and upload it to your domain's root directory then your root directory will look like this:
![Make Zip file of your project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7krv8c4dy6vhuafew7d.png)

## Step-2: Extract your zip file
Extract your zip file in the root directory then your directory will look like this after extracting your zip file.
![Extract your zip file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ea6pyixq9lu2mwycbfyp.png)
cut all files into your application public folder and paste them into the public_html folder then you can remove your public folder as well.

## Step-3: Create Database
Create a database for your uploaded Laravel project if you have any models in your applications.
![Create Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9vqiu2j58i065esq2dk.png)

## Step-4: Configure Database in .env file
Add credentials of a newly created database in your .env file in your project located in the root directory.
![Configure database in .env file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqrm1uc5z0hnk4sl09wl.png)

## Step-5: Run command php artisan migrate
Now it's time to run the essentials command to run the application properly.

Open your SSH terminal to run composer commands on the live server, if you don't know how to connect a live server with SSH, don't worry look at this article there it several ways to connect a live server with SSH access.

I hope, now you are connected with SSH, let's run this command to migrate your database

`php artisan migrate`

run this command if you have any seeders file

`php artisan migrate --seed`

Hooray, now you can run your application with your domain name your-domain-name.com.

I hope it can help you.

Happy Coding :)
What is Identity and Access Management(IAM) Service ?
Tags: cloud, security, aws, beginners
Published: 2022-12-26 18:28:58

# Definition
This sentence is devided into two sentences:

- Identity: is to define who you are, effectively presenting your identity, so for example your AWS username. This identification is a unique value within IAM for your account, so this means IAM would prevent you from having 2 identical user accounts with the same name within the same AWS account. the identity can be **users**, **federated_users**, **Application**, **Role**.
- Access Management: is to verify that you are who you say you are. This is achieved by supplying additional data, and when using our AWS usernames we can verify this by supplying a password.
Now, Access Management relates to authorization and access control. Authorization determines what an identity can access within your AWS account once it’s been authenticated to it. An example of this authorization would be the user’s list of permissions to access specific AWS resources, for example, they might have Full Access to EC2 or Read Only to RDS.

# IAM Features
- Shared access to the AWS account.
- Secure access to AWS resources for applications that run on AWS.
- Granular permissions.
- Multifactor authentication (MFA).
- Identity Federation.
- Identity information logs for audits and compliance purposes.
- Free to use.
- Integrated with many AWS Services.
- Eventually consistent.
- PCI compliance.
- Password policy.
- AWS STS.

<br>
**This service is for the administrators in the company**

<br>
[GitHub](https://github.com/a00ayad00)
[LinkedIn](https://www.linkedin.com/in/a00ayad00)
[Facebook](https://m.facebook.com/a00ayad00)
[Medium](https://a00ayad00.medium.com/)
How to create a VS Code code snippet
Tags: react, vscode, programming, productivity
Published: 2022-12-26 18:25:01

## Code snippets for the rescue

You know those repetitive tasks that you take a look and think about: it could be great to never write this again (or memorize).
Code snippets could be so powerful, you should learn this asap!

A code snippet is a block of predefined text that you can customize with some inputs.

## Creating a global code snippet
Today i will show you one of my new favorites code snippets: react context with typescript.
If you have to write some of those anytime, you know that could be a little bit confusing(to say the least).

First of all, let’s see a basic react context setup to understand the power of this code snippet:


![Image a piece of code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/728hefbem377ir1cc578.png)

Alright, now that we know how to write a basic(not so basic) react context with typescript, it could be nice to have an code snippet and never write all these lines again. Let’s do this!

To create a global code snippet, open VS Code and follow these steps:

- press ctrl+shift+p
- type: snippet
- select “Configure code snippet”
- select “new global snippets file”

Now you have a new global code snippet file! Cool!
A code snippet file is just a json with some informations about the snippet, like its name, the shortcut to use it and the body.
Here’s the react context code snippet, just paste it in the new file and save:

```
{
	"create react context": {
		"scope": "typescriptreact",
		"prefix": "tscontext",
		"body": [
			"import { createContext, useContext, PropsWithChildren } from 'react';",
			"",
			"type $1Type = {}",
			"",
			"export const $1 = createContext({} as $1Type)",
			"",
			"export const $1Provider = ({ children }: PropsWithChildren) => {",
			"  return (",
			"    <$1.Provider value={{}}>",
			"      {children}",
			"    </$1.Provider>",
			"  );",
			"}",
			"",
			"export const use$1 = () => useContext($1)"
		],
		"description": "create react context with hook"
	}
}
```

To use it, create a .tsx file, type `tscontext` than hit tab. Choose the context name (ie: BasicContext) and hit `esc`.
And that’s it, the snippet will fill all variables/types/function names according to the name that you choose.

## Snippet scope
On VS Code, snippets could be global or scoped to the project. You could select the scope after selecting “Configure code snippet” step.

## Extension

There’s an amazing [VS Code extension ](https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets) with a bunch of code snippets for React. Take a look, it is really great!

Thank you for the attention, bye.
AWS Cloud Quest: Cloud First Steps Study Note
Tags: aws, cloud
Published: 2022-12-26 18:22:20

This is the DIY challenge of the second task in AWS Cloud Quest.

### DIY Steps:

1. Launch another EC2 instance
2. Under **Network Settings**, select existing security group and choose Security-Group-Lab
3. Click **Edit** in **Network Settings**
4. Choose a **Subnet** with different **Availability Zone** than the first EC2 instance