teleren/devto huggingface dataset:
Why['1','5','11'].map(parseInt) returns [1, NaN, 3] in Javascript
Tags: webdev, javascript, beginners, programming
Published: 2024-07-16 14:44:58

In JavaScript, the behavior of **['1', '5', '11'].map(parseInt)** can be perplexing. To understand this, let's dive into how **map **and **parseInt **interact.

## The map Function
The **map** function creates a new array by applying a provided function to each element in the array. It passes three arguments to the callback function: the element, the index, and the entire array.

## The parseInt Function
The **parseInt** function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems). Its signature is **parseInt(string, radix)**.

## The Interaction
When using parseInt within map, the map function inadvertently passes the index of the element as the second argument to parseInt. This causes unexpected behavior:


![parseInt broken](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjefmgwxrnri7xsjddn9.png)

- For the first element '1' (index 0), parseInt('1', 0) is called. The 0 radix means the base is guessed based on the string's format, defaulting to 10. Result: 1.

- For the second element '5' (index 1), parseInt('5', 1) is called. But 1 is not a valid radix, so the result is NaN.

- For the third element '11' (index 2), parseInt('11', 2) is called. Here, 2 means binary. The valid binary digits are 1, resulting in 3 (since 1*2^1 + 1*2^0 = 3).

## The Solution
To ensure **parseInt** only receives the element, you can use an arrow function or another method to explicitly handle the conversion:

```
console.log(['1', '5', '11'].map(num => parseInt(num))); // [1, 5, 11]
```
Or use the **Number** constructor:

```
console.log(['1', '5', '11'].map(Number)); // [1, 5, 11]
```
Understanding this interaction highlights the importance of knowing how JavaScript functions interact and ensuring the correct parameters are passed to avoid unexpected results.

That's all for today.

And also, share your favourite web dev resources to help the beginners here!

Connect with me:@ [LinkedIn ](https://www.linkedin.com/in/safdarali25/)and checkout my [Portfolio](https://safdarali.vercel.app/).

Explore my [YouTube ](https://www.youtube.com/@safdarali_?sub_confirmation=1)Channel! If you find it useful.

Please give my [GitHub ](https://github.com/Safdar-Ali-India) Projects a star ⭐️

Thanks for 25659! 🤗
Spring Security Oauth2 Password JPA Implementation
Tags: springsecurity, springboot, security
Published: 2024-07-16 14:54:57

https://github.com/patternknife/spring-security-oauth2-password-jpa-implementation

- Complete separation of the library (API) and the client for testing it
<dependency>
    <groupId>io.github.patternknife.securityhelper.oauth2.api</groupId>
    <artifactId>spring-security-oauth2-password-jpa-implementation</artifactId>
    <version>2.4.0</version>
</dependency>

- Set up the same access & refresh token APIs on both /oauth2/token and on our controller layer such as /api/v1/traditional-oauth/token, both of which function same and have the same request & response payloads for success and errors.
  - As you are aware, the API /oauth2/token is what "spring-authorization-server" provides.
  - /api/v1/traditional-oauth/token is what this library implemented manually.

Success Payload
 {
     "access_token" : "Vd4x8D4lDg7VBFh...",
     "token_type" : "Bearer",
     "refresh_token" : "m3UgLrvPtXKdy7jiD...",
     "expires_in" : 3469,
     "scope" : "read write"
  }
Error Payload
  {
      "timestamp": 1719470948370,
      "message": "Couldn't find the client ID : client_admin", // Sensitive info such as being thrown from StackTraces
      "details": "uri=/oauth2/token",
      "userMessage": "Authentication failed. Please check your credentials.",
      "userValidationMessage": null
  }

- In the following error payload, the 'message' shouldn't be exposed to clients; instead, the 'userMessage' should be.
Authentication management based on a combination of username, client ID, and App-Token
  - What is an App-Token? An App-Token is a new access token generated each time the same account logs in. If the token values are the same, the same access token is shared.

- Separated UserDetails implementation for Admin and Customer roles as an example. (This can be extended as desired by implementing UserDetailsServiceFactory)

- Provide MySQL DDL, which consists of oauth_access_token, oauth_refresh_token and oauth_client_details, which is tables in Security 5. As I mean to migrate current security system to Security 6, I haven't changed them to the authorization table indicated in https://github.com/spring-projects/spring-authorization-server.

- Application of Spring Rest Docs
User Account Verification Via Email - FastAPI Beyond CRUD (Part 18)
Tags: fastapi, python, api, programming
Published: 2024-07-16 15:00:23

In this video, we explore integrating email support into our application using FastAPI-Mail. We start by implementing email sending capabilities and proceed to verify user accounts. We also look at how we can securely pass data in URLs using the itsdangerous Python library.


{%youtube nodSaVS4BMY%}
JAVASCRIPT
Tags: beginners, javascript, learning
Published: 2024-07-16 15:08:09

**JavaScript (JS) is a programming language used to make web pages interactive. It works alongside HTML and CSS to enhance the user experience on websites.**

## 
How JavaScript Differs from Other Languages

- **Runs in the Browser: **JavaScript runs directly in the web browser, unlike many other languages that run on a server.
- **Responds to User Actions:** It's designed to respond to events like clicks and key presses, making web pages interactive.
- **Asynchronous Operations:** JavaScript can perform tasks in the background without interrupting the main program.

##  Key Features:

- **Interactivity:** Adds dynamic elements to web pages.
- ** Versatility:** Used for both front-end and back-end development.
-  **Wide Support:** Works in all modern web browsers.
-  **Large Ecosystem:** Includes many libraries and frameworks like React, Angular, and Node.js.
- **Easy to Learn:** Has a simple syntax, making it accessible for beginners.


## Why Learn JavaScript?

- **High Demand: Many **job opportunities for JavaScript developers.
- **Community Support:** Lots of resources and help available.
- **Career Opportunities:** Essential for web development roles.
Clone any Git URL directly to VS Code with a single click!
Tags: devops, extensions, vscode
Published: 2024-07-16 15:11:02

## 🚀 Features

One-click cloning from any Git repository URL
Seamless integration with VS Code
Works with GitHub, GitLab, Bitbucket, and more
Lightning-fast setup and minimal configuration

## 🎭 Why AnyClown?
Because only a clown would waste time manually copying URLs and switching between browsers and terminals! AnyClown brings the circus to your development workflow, juggling Git repositories with ease.

## 🛠️ Installation

Visit the Chrome Web Store
Search for "AnyClown"
Click "Add to Chrome"
Embrace your inner code clown 🎈
[Chrome Web Store](https://chromewebstore.google.com/search/anyClown)

## 🎪 How to Use

Navigate to any Git repository URL
Click the AnyClown icon in your Chrome toolbar
Watch in amazement as the repo opens in VS Code

## 🧑‍💻 Requirements

Google Chrome browser
Visual Studio Code
A sense of humor (optional, but recommended)

## 🐛 Found a Bug?
If you've caught a pesky bug in our clowning around, please open an issue. We promise to juggle it into our priority queue!

## 🤝 Contributing
We welcome all clowns, jesters, and code acrobats to contribute! Check out our contributing guidelines to join the circus.

## 📜 License
See the LICENSE file for more details.

## TargetTeam 
Made with ❤️ and a lot of 🤡 energy by the AnyClown team.
Remember: Keep calm and clone on! 🎭🚀
Join the NBA YoungBoy Merch Community on Reddit!
Tags: nbayoungboymerch, reddit
Published: 2024-07-16 15:56:14

Subscribe to our subreddit to join the discussion and stay updated on NBA YoungBoy Merch. Share your thoughts, post your collections, and connect with other dedicated fans. Reddit is the perfect platform for in-depth discussions and exclusive insights.
https://www.reddit.com/user/nbayoungboymerchshop/

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ap64u15wds1whswxogg.jpg)
Follow NBA YoungBoy Merch on Quora!
Tags: nbayoungboymerch, quora
Published: 2024-07-16 15:57:12

Get your questions answered and follow NBA YoungBoy Merch on Quora. Engage in insightful discussions and learn more about the latest merch trends and releases. Quora is the perfect platform for deep dives and fan engagement.
https://nbayoungboymerchshop.quora.com/

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90srfzv9su5sloeq1xgs.jpg)
Explore NBA YoungBoy Merch on Sketchfab!
Tags: nbayoungboymerch, sketchfab
Published: 2024-07-16 15:58:16

Check out our 3D models and visualizations of NBA YoungBoy Merch on Sketchfab. Get a closer look at the details and craftsmanship of your favorite pieces. Sketchfab is the ideal platform for a detailed and immersive merch experience.
https://sketchfab.com/nbayoungboymerchshop

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ktnkqofpc88c8qjc7ea.jpg)
Stay Updated with NBA YoungBoy Merch on Band!
Tags: nbayoungboymerch, band
Published: 2024-07-16 15:59:35

Join our Band group to stay in the loop with the latest NBA YoungBoy Merch updates. Get exclusive access to announcements, events, and special offers. Band is your go-to platform for community engagement and real-time updates.
https://band.us/@nbayoungboymerchshop


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sfw0sekbsh5dnkuv10ep.jpg)
What are Azure's Deployment Models?
Tags: cloud, azure, microsoft
Published: 2024-07-16 16:02:06

Firstly, Let's find out Azure's deployment models, Then we will discuss The Cons and Pros of each cloud type.

---------

1.**Public Cloud** : built on the cloud provider also known as : Cloud-Native.
You don't have to use any external tools.

![Public cloud](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvtkyzat7ievt1yoj7zc.png)


2.**Private Cloud** : everything built on company's datacenters.
Also known as : On-Premise

![Private Cloud](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lp2lma0rijqucl9mw05.png)


3.**Hybrid Cloud** : using both On-Premise and CSP

![Hybrid](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp51cpnh5sh91obfizwx.png)


4.Cross-Cloud : using multiple Cloud Providers Aka multi-cloud, hybrid-cloud.

For example : using Azure ARC and Amazon EKS and GCP Kubernetes Engine.

-----------

Ok, now it's the time to show up the Cons and Pros.

1.**Cost-Effective** :
=> Public Cloud is the Most Cost-Effective
=> Private Cloud is the Most expensive
=> Hybrid Cloud is more Cost-Effective, It depends what you are offloads to the cloud.

2.**Security** :
=> Public Cloud may not meet the security requirements
=> Private Cloud Can meet any security requirements, but you have to put in the work.
=> Hybrid CLoud Can also meet all the security requirements, but you have to secure your connection to the cloud!

So, at the end the choice of what cloud you should use depends on what your business requires. Feel free to reach me at hamzamrbek@gmail.com and can tell you clearly what cloud fits your business.

See you in the next post 📯 .
Confused on +layout.js and +layout.svelte props passed in load() function...
Tags: sveltekit
Published: 2024-07-16 16:11:29

I have a load function in my root +layout.js file that is:

`export async function load() {
// and all it returns is 
return {
  prop1: true,
  prop2: false,
  prop3: "value 3"
};
`
For the life of me, I cannot do anything in the +layout.svelte file to make these values show up. 

`export let prop1;
export let prop2;
export let prop3;
console.log("prop1 = " + prop1);`

gives me "prop1 undefined" in the console every time!
I have tried deconstructing the export like

`let { prop1 } = data;
// and
let { prop1 } = props;
`
and nothing works... no matter what I do!

Is it because the load function is async? I need it to be async so I can fetch some external api's when it's done, but I was just testing the bare bones to try and understand how things worked.

Any ideas on the load order of 

+page.js vs +layout.js
+page.svelte vs +layout.svelte

etc?
Help. I'm losing it.
Tags: beginners, productivity, programming, help
Published: 2024-07-16 16:11:32

Hello Everyone. 


I am Joey, and I really love Programming. It amazed me when I started  2 years ago that I could be paid to do what I love. However there is a big problem. 


I've been working the past month and a half of the summer break at a major government company here in my country and I seem to have just been losing the spark I once had. I used to sit for hours messing around in python instead of doing my homework and now the moment I get home, I don't have the moral to get to work. 


I am reaching out to my fellows and senoirs here in the DEV community, What should I do ? Should I just assume I wasn't meant to program and pursue something else ? Everytime I ask myself this, it leaves a spine-chilling horror etched into my mind. The horror of not being able to program. 


Any and all advice would be greatly appreciated. I am in quite the dilema.
Engineer Explains: What is DevRel, and why developers should care?
Tags: video, devrel, engineerexplains, marythengvall
Published: 2024-07-17 13:04:28

---
title: Engineer Explains: What is DevRel, and why developers should care?
published: true
date: 2024-07-16 14:07:46 UTC
tags: Video,DeveloperRelations,EngineerExplains,MaryThengvall
canonical_url: https://shiftmag.dev/developer-relations-explained-3757/
---

![](https://shiftmag.dev/wp-content/uploads/2024/07/mary_thumb-1.jpg?x43006)

_For more content like this **[subscribe to the ShiftMag newsletter](https://shiftmag.dev/newsletter/)**._

There’s probably no better person to ask to explain Developer Relations than Mary Thengvall, the author of the first book on the matter, “The Business Value of Developer Relations.”  
  
As Mary has already [said for ShiftMag](https://shiftmag.dev/mary-thengvall-developer-relations-3094/) – DevRel is not something that people naturally understand. It’s part of the job for people who work in DevRel to explain to developers and their other colleagues the value of their job and that they’re not just “people who travel to a lot of conferences.”  
  
Watch the video to hear how Thengvall explained the value of DevRel at three levels, from a junior developer to a CTO:

<iframe title="Developer Relations Explained by Mary Thengvall" width="500" height="281" src="https://www.youtube.com/embed/1tqWJwZQnkM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

This video is a part of ShiftMag’s **video series, [Engineer Explains](https://www.youtube.com/@ShiftMag/videos).**

We’ve asked experienced engineers to share how they would explain some basic and some less basic tech terminology to different tech job titles or at three levels of experience —  **from junior developer to CTO.**  
  
**More:**  
How would you explain [APIs](https://www.youtube.com/watch?v=qtxHm09FH_M), [internal developer platforms](https://www.youtube.com/watch?v=Rxi3fHEY48c), [software architecture](https://www.youtube.com/watch?v=BqsTQWhyngg&t=9s), [software testing](https://www.youtube.com/watch?v=5aRuyTIoMys), [scaling infrastructure ](https://www.youtube.com/watch?v=s_Igmd5GpDg&t=5s)without breaking the bank,  [low-code as a dev tool](https://www.youtube.com/watch?v=VhhkK0zCY7I&t=42s), [what is a database](https://www.youtube.com/watch?v=WgysaqzYMU0&t=21s) or [Network APIs](https://www.youtube.com/watch?v=v2-wsawNurI) at three levels of experience?

The post [Engineer Explains: What is DevRel, and why developers should care?](https://shiftmag.dev/developer-relations-explained-3757/) appeared first on [ShiftMag](https://shiftmag.dev).
Recursion or Loop?
Tags: javascript, beginners
Published: 2024-07-16 16:25:08

When should you use a _recursive function_ instead of a _loop statement_? Likewise, when should you use a _loop statement_ instead of _recursion_?

Oftentimes I find myself a bit unsure of how to answer this question, and I find myself reminiscing of a toy problem from the past. The problem was this: 

> Write a set of code that will evaluate whether or not the provided String variable is a palindrome. Your code should determine a boolean value reflecting this condition.

It took me a while to solve the code, given some of the constraints and edge conditions. However, eventually I was able to solve this problem through the use of a recursive function.

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

After a while I wondered, would this be possible with a For Loop? And so, I set out to find an answer and began experimenting. What I found is that, sure enough, this can be done with a Loop statement as well.


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

As I reflected upon the two sets of code, I found myself somewhat frustrated because it felt like I still had not grasped why you would prefer a recursive statement over a Loop. I came across a discussion on StackExchange that shed some light on the topic. A developer by the name of Scant Roger stated the following:

> "Ultimately, there's nothing recursion can compute that looping can't, but looping takes a lot more plumbing. Therefore, the one thing recursion can do that loops can't is make some tasks super easy...Often the recursive solution to a problem is prettier." 
 
 It became apparent to me that Roger was absolutely right; I found that it was much easier for me to write the recursive solution than it was to develop the same solution with a Loop statement. If it is easier to create a recursive solution, and to later redesign it as a Loop (to reduce code complexity) I think that is fine. 
 
What are your thoughts? I am still new to coding, and I would love to hear from everyone else!
🚀 Embarking on My DevOps Journey! 🚀
Tags: devops, linux
Published: 2024-07-16 16:24:09

Hello everyone,

I'm excited to announce that I'm starting my journey into the world of DevOps! 🌟 Each week, I will be sharing my progress, insights, and learnings with you all. This not only helps me stay accountable but also allows me to connect with and learn from those of you who are already on this path or interested in it.

**Week 1: Linux Basics 🐧**

For my first week, I'll be diving into Linux. As the backbone of many DevOps tools and practices, having a solid understanding of Linux is crucial. 

I’m looking forward to sharing what I learn and would love to hear any tips or resources you might have! Let’s connect and grow together in this journey.
Decorator design pattern in React
Tags: react, designpatterns, typescript, tutorial
Published: 2024-07-16 17:22:04

Greetings, in this article we will be discussing the implementation of the decorator design pattern in React. The decorator design pattern involves wrapping objects and adding new functionalities to them. For instance, if you are working on a store management system within your React application, you can utilize this design pattern to interact with the store manager and access data.

We will proceed to the implementation stage, starting with creating a `Wrapper` function that serves as the decorator.

``` typescript
import { FC } from "react";

function Wrapper<T>(ReactComponent: FC<T>) {
    function ComponentWrapper(props: T & JSX.IntrinsicAttributes) {
        return <ReactComponent {...props} />
    }
    return ComponentWrapper;
}

export default Wrapper;
```
In the code provided, the `Wrapper` function acts as a decorator for the `ReactComponent`, which is a functional component in React. The `ComponentWrapper` serves as the parent component that interacts with the `ReactComponent` as its child. You can use any hooks within the `ComponentWrapper`. Let's now use the `Wrapper`.

``` typescript
import { FC } from 'react';
import Wrapper from './Wrapper';

type props = { title: string; }

const Header: FC<props> = ({ title }) => {
    return (
        <div>
            {title}
        </div>
    );
}

export const HeaderComponent = Wrapper<props>(Header);
export default HeaderComponent;
```
The code above demonstrates the utilization of the decorator that was created earlier. The `Header` is a basic react component that is enclosed within the `Wrapper` component. This component can be utilized just like any other component.

``` javascript
import HeaderComponent from './Header'

function App() {

  return (
    <>
      <HeaderComponent title='Hello DEV.to' />
    </>)
}

export default App


```
The example above demonstrates how the `HeaderComponent` is utilized. 

Decorator is a robust design pattern commonly found in various JavaScript frameworks such as `Angular` or `NestJS`. By implementing this straightforward approach, decorators can also be incorporated into React.

Thank you for taking the time to read this. I hope you found this post useful. Please feel free to share your thoughts in the comments section.
Emoji Favorite Icon
Published: 2024-07-16 17:01:52

I would like to improve the post from [CSS Tricks](https://css-tricks.com/emoji-as-a-favicon/). In this post the author demonstrated how to use an emoji as a favorite icon. This is a neat trick, but It doesn't feel right to me. So I will show how to convert it to a `data-uri`. 

# Steps
1 Create a new file `create-data-uri.ts`.
2 Save the following code snippet as `icon.svg`.
```
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <text y=".9em" font-size="90">🎯</text>
</svg>
```
3 Add an import to `create-data-uri.ts` from the "fs" module `import {readFile} from 'fs'`.
4 Create a function to create the `data-uri` as follows.
```
const asDataUri = (image: string) => `data:image/svg+xml;base64,${image}`
```
4 The function to encode the file would be as follows.
  1 use 'base64' as the encoding parameter.
  2 omit the 'base64' encoding parameter and use the `toString` method on the buffer with a value of "base64"
```
readFile(filename, 'base64', (readError, text)=> {
 if (readError) return readError
 return asDataUri(text)
})

or
readFile(filename, (readError, buffer)=>{
  if (readError) return readError
  return asDataUri(buffer.toString('base64'))
})
```

Now just copy that value and use it in the place `<img src="string from function"`.

Reference: 
https://css-tricks.com/emoji-as-a-favicon/
T-shirt Tuesday!
Tags: jokes, watercooler, discuss
Published: 2024-07-16 16:50:07

Welcome back to T-Shirt Tuesday, our weekly post inspired by the brilliant minds in our Discord Community.

Every week (that we don't miss the boat), we showcase fun and unique phrases that you'd love to see on a t-shirt.

This week's highlight features a piece of code spotted by @anmolbaranwal that resonates with many developers:

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

Now, it's your turn:

**What witty or inspirational phrase would you proudly wear on a t-shirt?**

Drop your suggestions in the comments below!

[And join our ⭐ Discord if you haven't yet!](https://discord.com/invite/ZCj5hFv8xV)
Weje | WEB3 DeFi Gaming
Tags: blockchain, web3
Published: 2024-07-16 17:12:41

If (weje() == true) {
   sad().stop();
   playPoker();
   beAwesome();
}

[weje.com](url) is a cutting-edge platform specializing in DeFi gaming. Offering an exciting opportunity to play poker and other games using Cryptocurrency wallets.

Join WEJE for the ultimate DeFi gaming experience with MATIC tokens. Play poker, enjoy live video chat, and engage in seamless, secure P2P transactions.