teleren/devto huggingface dataset:
Memory Location Behavior in JavaScript
Tags: webdev, javascript, programming, frontend
Published: 2024-07-01 15:30:17


👍 **Primitive Types**
Primitive types in JavaScript include Number, String, Boolean, Null, Undefined, Symbol, and BigInt. These types are immutable and are stored directly in the variable's memory location.

👉 **Memory Behavior :**
- When a primitive value is assigned to a variable, the value itself is stored in the variable's memory location.
- When the variable is assigned to another variable, the value is copied. Changes to one variable do not affect the other.
- When the variable is Re-assigned , the value is stored in the new memory location.

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

_**Explanation , of Above Example**_ : 👇

The variable "a" is declared and initialized with the value 10. This means a directly stores the value 10 in its memory location.

The variable "b" is declared and initialized with the value of "a". Since "a" holds a primitive value, "b" gets a copy of that value. At this point, "b" also stores the value 10 in its own memory location. Now, both "a" and "b" have the value 10, but they are stored in separate memory locations.

Now variable "b" is reassigned with the value 20. This changes the value stored in b's memory location to 20. The variable "a" remains unchanged and still holds the value 10 because hey are stored in separate memory locations.

👍 **Reference Types**
Reference types include Object, Array, Function, and other objects created using the new keyword. These types are mutable and are stored as references to their memory locations.

👉 **Memory Behavior :**
- When a reference type value is assigned to a variable, the variable stores a reference (or pointer) to the location in memory where the value is actually stored.

- When the variable is assigned to another variable, only the reference is copied, not the value itself. Changes to one variable affect the other because they both reference the same object.

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

_**Explanation , of Above Example**_  : 👇

Here "obj1" is a object . In JavaScript Object is Reference Data Types , meaning they are stored in memory, and variables store references (or pointers) to those objects. "obj1" is assigned a reference to an object with a property name set to "Alice".

"obj2" is assigned the same reference as "obj1". Now, both "obj1" and "obj2" point to the same object in memory.

Changing the name property of the object through "obj2" also affects "obj1" because both variables reference the same object.

_This distinction between primitive values and objects/references is crucial for understanding how variables interact with memory in JavaScript, particularly when using let for variable declarations._
When has rolling your own auth gone wrong?
Tags: discuss, security, authentication
Published: 2024-07-01 15:20:45

This week we're thinking about what happens when rolling your own auth snowballs into a giant headache. Tell us your own story in the comments!

For a lot of us, this probably feels familiar: everything starts out simple. Add a little home-grown password-based authentication into your app and it seems great - everything just _works!_ But then your app grows, your userbase grows, and your needs get more complicated: suddenly that simple DIY auth solution doesn't do everything you need. Where do you go from there? Do you keep building on top on your existing auth, or do you have to start from scratch with a third-party solution? Are the sunk costs too high to change course, or is the trade-off worth it? And what do you do with all those existing users?

As devs we've been there ourselves. Check out this cautionary tale from Steve Cattaneo, Userfront's Head of Engineering:

---
_Once upon a time, Steve worked at a company that was a Rails shop._ Their first product leveraged out-of-the-box Rails password authentication. When they built their second product, for speed to market reasons, much of the boilerplate from the first product was copied into the second product—including the authentication. There was a lot to do and not much time to do it.

Fast forward a few years and Steve’s team built their third product. That, too, included the boilerplate password auth. It was, after all, a simple, straightforward solution that worked.

...then a customer asked for Google authentication, and that's when things started to get complicated.

Steve's team assigned the work to one of the engineers: create an OAuth 2 module. Then migrate users: transition the username-password user to the username backed by a Google identity. He figured it out. He wired it up. And they rolled it out.

Two or three weeks later, that engineer went on a much-deserved vacation. On that Friday — of course — the customer reported issues. Users were unable to log in. Without the engineer who had built the system, they spent the day looking at the code, looking at the database... but couldn't figure it out. The core data pipeline product was fine, but users couldn’t access their dashboard for three days—not counting the weekend.

Eventually they gave their customer a status update: **“We’ll have to get back to you.”**

_(read the rest of the story & find out what happened to Steve's team [here!](https://userfront.com/blog/steve-cattaneo-knows-what-its-like-to-roll-your-own-iam))_
Bash Scripting: User Management, Password Generation, and Log Handling Simplified
Published: 2024-07-01 15:18:54

## Overview

Description This bash script automates the process of creating multiple users and groups on a Linux system. It reads user data from an input file (either .txt or .csv), creates users with their personal groups, assigns additional groups, sets random passwords, and logs all actions. This is a project from HNG  [https://hng.tech/internship] or [https://hng.tech.hire] I was able to learn and relearn many concepts form bash scripting

## Features

- Reads user data from .txt (semicolon-delimited) or .csv files
- Creates users with personal groups
- Assigns users to additional groups
- Generates random passwords for each user
- Logs all actions for auditing purposes
- Stores generated passwords securely

## Prerequisites

- Linux system with bash shell
- Root or sudo access
- useradd, groupadd, and usermod commands available
- openssl for generating random passwords

## Usage

1. Save the script as <your_name.sh>
2. Make the script executable: chmod +x <your_name.sh>
3. Prepare an input file (e.g., users.txt or users.csv) with user data: For users.txt (semicolon-delimited): username;group1,group2,group3 For users.csv (comma-delimited): username,group1,group2,group3
4. Run the script with sudo, providing the input file: sudo ./create_users.sh users.txt or sudo ./create_users.sh users.csv

## Output

- Users are created with their personal groups
- Additional groups are created if they don't exist
- Users are added to specified groups
- Random passwords are generated for each user
- All actions are logged in /var/log/user_management.log
- Passwords are stored in /var/secure/user_passwords.csv

## Security Notes

- The script must be run with root privileges
- Generated passwords are stored in a secure location (/var/secure/user_passwords.csv)
- It's recommended to change the generated passwords upon first login

## Customization

- Log file location can be modified by changing the LOG_FILE variable
- Password file location can be modified by changing the PASSWORD_FILE variable
- Password generation method can be customized by modifying the openssl rand -base64 12 command

## Troubleshooting

- Ensure the input file exists and is readable.
- Check /var/log/user_management.log for detailed information on each action.
- Verify that you have the necessary permissions to create users and groups.

Disclaimer This script is provided as-is, without any warranties. Always test in a safe environment before using in production.

I tested the above script in an AWS EC2 instance to avoid adding the users on my personal laptop, I will also be testing the above in AWS EKS cluster. 

Contributing Feel free to fork this project and submit pull requests with improvements or bug fixes.Link to code [https://github.com/alvo254/kwel]
Checking Armstrong Numbers in C
Tags: programming
Published: 2024-07-01 08:52:07

We're excited to share our latest blog post, **"Checking Armstrong Numbers in C"** with all of you passionate programmers out there! Whether you're just starting your coding journey or you're a seasoned developer, this tutorial is designed to boost your C programming skills.

### What's Inside? 🌟

In this comprehensive guide, you'll learn how to write a program to identify Armstrong numbers. These unique numbers are fascinating because the sum of the cubes of their digits equals the number itself. Here's a sneak peek of what you'll find:

- **Step-by-Step Instructions:** Detailed steps to help you understand the logic and flow of the program.
- **Sample Code:** Ready-to-use code snippets that you can try out and modify.
- **Optimization Tips:** Techniques to make your program more efficient and performant.
- **Critical Thinking Development:** Practical, problem-solving approach to enhance your coding and analytical skills.

### Why Read This Post? 🤔

Armstrong numbers are a classic problem that every programmer should tackle at least once. By understanding and implementing this algorithm, you'll not only learn about these numbers but also sharpen your critical thinking and problem-solving abilities. This tutorial ensures that you get a hands-on learning experience, making complex concepts easier to grasp.

So, what are you waiting for? Dive into our latest post and take your C programming skills to the next level!

👉 Read the full post here:https://mokshelearning.blogspot.com/2023/06/15-checking-armstrong-numbers-in-c.html

Don't forget to leave your feedback and share your thoughts in the comments! Let's learn and grow together. 💪

Happy coding! 😊
How has knowvation learnings helped more than 10000+ students?
Tags: webdev, javascript, programming, tutorial
Published: 2024-07-01 15:00:30

HOW HAS KNOWVATION LEARNINGS HELPED MORE THAN 10,000+ STUDENTS HOW IT IMPACTED THEIR CAREER AND WHAT EXACTLY DOES KNOWVATION LEARNINGS DO?


1) Unleashing the Power of Knowvation: Transforming Learning for 10,000+ Students.
Hello! Welcome to knowvation learnings,today let's dive into the world of knowvation learnings and know how as knowvation learnings as a platform has helped and transformed more than 10,000+ students with great mentorship guidance and logic building with real time project based learning

Courses we offer:
Tech Titans (Grades 5-6)
Code Ninjas (Grades 7-8)
Hi-Tech Warriors (Grades 9-10)
Tech Geniuses (Grades 11-12)
Code Combats (Grade 12 and Beyond)
The courses we offer are thoughtfully created for every student who is interested in learning tech and also we offer many offline and online workshops to help students learn easily and efficiently the online and online workshops include,
Workshops:
Career guidance
Resume building
Entrepreneurship
Technologies
These workshops not only helps students but to any person who is interested in learning technology,one of the most striking aspects of knowvation learnings is we emphasis on logic learning and help students understand better,we dont just stick to the traditional mode of learning where students struggle to connect the dots between subjects and topics.However,we fill this gap by fostering a holistic understanding of concepts through logical reasoning. By encouraging students to think critically and analytically, Knowvation equips them with the skills necessary to tackle complex problems with confidence.
But what truly sets us apart from the fellow competitors is its project-based learning approach. Instead of passively consuming information, students actively engage with the material by working on hands-on projects. Whether it's building a robot, designing a website, or conducting a scientific experiment, these projects not only reinforce theoretical knowledge but also cultivate essential skills such as teamwork, communication, and adaptability.Of course, none of this would be possible without the guidance of qualified mentors. Knowvation recognizes the importance of having knowledgeable and experienced individuals to support and mentor students along their learning journey. These mentors serve as role models, offering valuable insights, feedback, and encouragement to help students navigate challenges and reach their full potential.

Conclusion
In conclusion, Knowvation is not just a learning platform; it's a catalyst for transformation. With its focus on logical and project-based learning, guided by qualified mentors, Knowvation is empowering thousands of students to unleash their full potential and become the innovators, problem solvers, and leaders of tomorrow. So, if you're ready to embark on a journey of discovery and growth, why not join the Knowvation community today? After all, the future belongs to those who dare to know!
Best Motivational Speaker in India
Tags: motivation, speaker
Published: 2024-07-01 14:50:31

Shiv Khera is an Indian author, activist and **[motivational speaker](https://shivkhera.com/)**, best known for his book, You Can Win. He launched a movement against caste-based reservation in India, founded an organization called Country First Foundation. A Transformative educator, Motivational guide, business coach and An international; acclaimed best selling author of you can win 9Million+ copies sold worldwide.
Laravel 11: Vite in Twig (rcrowe/TwigBridge)
Published: 2024-07-01 14:45:31

This registers `vite` tag to Twig that allows to dynamically link css and js (works for dev and prod):

```twig
{{ vite('resources/css/app.scss')|raw }}
{{ vite('resources/css/app.js')|raw }}
```

### 1. Create new Twig extension:

app/Twig/TwigExtension.php:
```php
<?php
namespace App\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\Markup;
use Illuminate\Foundation\Vite;

class TwigExtension extends AbstractExtension
{
    public function getFunctions(): array
    {
        return [
            new TwigFunction('vite', [$this, 'vite']),
        ];
    }

    public function vite(string $resource): string
    {
        return new Markup((new Vite)->__invoke($resource),'UTF-8');
    }
}
```

### 2. Generate config:

```bash
php artisan vendor:publish --provider="TwigBridge\ServiceProvider"
```

### 3. Add extension to config:

app/config/twigbridge.php:
```php
        'enabled' => [
            ... 
            'App\Twig\TwigExtension',
        ],
```
Top CRM Consultant & Software Developer in Texas
Tags: crmconsultant, softwaredevelopers
Published: 2024-07-01 14:33:04

TechnBrains is recognized as the #2 Top CRM Consultant and Top Software Developer in Texas by Clutch! Our expertise in CRM consulting and software development has earned us this prestigious recognition. Discover how our innovative solutions can empower your business by enhancing customer relationships, streamlining processes, and driving growth. Partner with TechnBrains to leverage cutting-edge technology and propel your business to new heights. Learn more about our award-winning services and how we can help you achieve your business goals.

Read Full News Letter: [https://www.technbrains.com/blog/top-crm-consultant-and-software-developer/](https://www.technbrains.com/blog/top-crm-consultant-and-software-developer/ )
The best way to debug slow web pages
Tags: webdev, performance, tracing, sentry
Published: 2024-07-01 14:31:29

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications. 

This is why you need [tracing from Sentry](https://sentry.io/for/tracing/?utm_source=devto&utm_medium=paid-community&utm_campaign=tracing-fy25q2-debuggingtracing&utm_content=video-ad-salma-learnmore).
🧩Feature-Sliced Design Review
Tags: webdev, frontend, react, nextjs
Published: 2024-07-01 14:27:12


Here, I reconsider the pros and cons of feature-sliced design. Many new devs considering this new architecture, but this one surely has **upsides and downsides**. If you're working with a team, you should reconsider your decision thoroughly.

## Pros

### Uni-Direction Dependency Flow Prevents Circular Dependencies

Import/export dependency flow becomes uni-direction.
Here is the hierarchy: shared < entities < features < widgets < pages < app. Modules and components in `shared` can only be exported by files in the higher layer. (`entities`, `features`, `widgets`, `pages`, and `app`). Modules and components in `entities` can only be exported by files in `features`, `widgets`, `pages`, and `app`. Since we can set the hierarchy, circular dependencies rarely take place.

### The Depth of The Directory Is Limited

There are three levels of a directory: layers, slices, and segments. By restricting the depth of the directory, we can prevent the directory structure from becoming too **complicated**. However, this might not be a serious concern since auto import is supported.

### Single Responsibility Follows the Principle 

It becomes clear which file you need to navigate when you want to modify the code. FSD simplifies the process since the three criteria can **filter** most modules.

- Layers: Which abstraction level does the component/module belong to: widgets  render entities composited with features
- Slices: Which feature is the component/module related to: log-in, feed, profile, and so on
- Segments: What kind of logic does the component/module contain: data fetching, business logic, helper functions, and so on

## Cons

### At First, it feels tricky

I didn't know how to name slices especially, even though I looked at many examples on the official docs. Plus it was very confusing whether I should put some module in `lib` or `model`. Your team might lose **productivity**.


### Next.js doesn't support barrel support
[This is a known issue](https://github.com/vercel/next.js/issues/63441).
To implement public API, FSD uses barrel exports. However, if server components and client components are exported by a single file, the server components are marked as client components.

```ts 
import ServerComopnent from './ui';
import ClientComponent from './ui';

export { ServerComponent as Server } from './ui';
export { ClientComponent as Client } from './ui';
```

## Ending comment

Please leave a comment if you have an opinion about FSD.
Goodbye IP Addresses, Say Hello to the Magic of Network Aliases
Published: 2024-07-01 14:26:57

### Network Management Made Easy: My Go-To Alias Trick

Hey there, fellow tech enthusiasts! Today, I'm sharing my favorite hack for simplifying network management: using aliases instead of IP addresses. Trust me, this little trick has saved me countless headaches. Let's dive in!

#### Why Bother with Aliases?

Before we get to the how-to, let me tell you why this is so awesome:

1. **Easy to remember**: "printer" is way easier to recall than 192.168.1.101
2. **Fewer typos**: Less chance of mistyping a long IP address
3. **Quicker commands**: Type `ssh user@webserver` instead of `ssh user@192.168.1.100`
4. **Consistency**: Even if IP addresses change, your aliases stay the same

#### Setting Up Aliases on Linux/Mac

1. Open Terminal and type:
   ```
   sudo nano /etc/hosts
   ```

2. Add your aliases like this:
   ```
   192.168.1.1    router
   192.168.1.100  webserver
   192.168.1.101  staging-server
   192.168.1.102  printer
   ```

3. Save with Ctrl+X, then Y, then Enter.

4. Test it out:
   ```
   ping webserver
   ```

Pro tip: I like to add comments to my hosts file for future reference:
```
# Home Network Devices
192.168.1.1    router
192.168.1.100  webserver
192.168.1.101  staging-server
192.168.1.102  printer
```

#### Setting Up Aliases on Windows

1. Run Notepad as administrator (right-click, "Run as administrator")
2. Open `C:\Windows\System32\drivers\etc\hosts`
3. Add your aliases just like in the Linux example
4. Save and exit

Quick Tip: If you can't save the file, try moving it to your desktop, edit it there, then move it back.

#### Practical Uses

Now that you've set this up, here are some cool ways I use it:

1. **Quick SSH**: 
   ```
   ssh username@webserver
   ```

2. **Fast file transfers**: 
   ```
   scp myfile.txt username@staging-server:/path/to/destination/
   ```

3. **Easy networking troubleshooting**:
   ```
   traceroute printer
   ```

4. **Hassle-free web development**:
   In your browser, just type `http://webserver` instead of the IP

#### Bonus Tips

1. **Use meaningful names**: Choose aliases that make sense to you.

2. **Keep it updated**: Whenever you add a new device to your network, make it a habit to add an alias for it.

3. **Backup your hosts file**: I keep a copy of my hosts file in my cloud storage. It's a lifesaver when setting up a new machine.

4. **Use it for remote servers too**: I add aliases for my cloud servers as well. It's super handy when managing multiple environments.

### Wrapping Up

This simple trick has genuinely made my day-to-day tech life so much smoother. Give it a shot, and I bet you'll wonder how you ever managed without it. Got any cool networking tricks of your own? Drop them in the comments – I'm always eager to learn more!

Remember, networking doesn't have to be a pain. With a little setup, you can make your digital life a whole lot easier. Happy networking, folks!
Multiple OAuth2 Schemes FastAPI
Tags: fastapi, backend, restapi, oauth
Published: 2024-07-01 14:16:40

## Introduction
How do you create multiple OAuth2 token schemes in FastAPI and make sure they are usable in the SwaggerUI auto documentation?

I am building a REST API for a SaaS Loan Management System (LMS) to be used internally by company personnel. I have two kinds of users: 

1. **System users** - LMS software administrators.
2. **Company users** - personnel using the software. 

System users can create companies and the first company users. Assign admin role, to allow them to register other company users linked to the same company. 

I created two OAuth2 token schemes; `admin_oauth2` for system users and `user_oauth2` for company users. Separating the authentication models it made it easy to manage. I can create tokens for admins with a simple payload of expiration date and admin ID. And add extra data in the company users' token like the company ID and the user roles for easy role-based access control and authorization.

## Creating Multiple OAuth2 Schemes in FastAPI
To create multiple OAuth2 schemes, create two token dependencies; one for the admins, and another for users.

```python
...
user_oauth2 = OAuth2PasswordBearer(
    tokenUrl="/api/v1/login/access-token",
    scheme_name="user_oauth2",
)
UserTokenDep = Annotated[str, Depends(user_oauth2)]

admin_oauth2 = OAuth2PasswordBearer(
    tokenUrl="/api/v1/admin/login/access-token",
    scheme_name="admin_oauth2",
)
AdminTokenDep = Annotated[str, Depends(admin_oauth2)]
```
That will allow an API to have two OAuth2 authentications depending on the endpoint accessed. Notice the `scheme_name` argument in the scheme definition. That's an important detail when you have multiple OAuth2 schemes in the same API - that is, if you don't define the scheme name, the authentication token depends on the last endpoint you defined regardless of whether the operation depends on that token or the other token. I spent hours trying to figure out that simple detail. That's all there is to it, the rest are skill issues.

## Read Me
Hi there! I am Paul John, a recent software engineering graduate. I recently joined a backend, DevOps and Product Testing internship at [HNG Internship](https://hng.tech/internship) to put my learned skills to work and broaden my horizons in Software engineering. My goal is to be able to create a software product from scratch to the maintenance stage (the whole SDLC).

If anything, check out [HNG Premium](https://hng.tech/premium), it delivers added value to the Internship.

Adios!