teleren/devto huggingface dataset:
Practical ECS scaling: an introduction
Tags: aws, containers, cdk, scaling
Published: 2023-12-17 15:35:35

How effective is it to vertically scale an application that has a memory leak? Can a CPU-heavy application perform better with more CPU resources? Should you horizontally scale your application based on response times?

To show the answers to these questions in practice, I built and load tested a mock application in order to achieve results that are the same or very similar to those shown in Nathan Peck's great article on [Amazon ECS Scalability Best Practices](https://containersonaws.com/presentations/amazon-ecs-scaling-best-practices/).

## Meet the app

![Application architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alorl6q020694a03cj3w.png)

The application itself is built in Flask and its infrastructure is managed with AWS CDK for Python. The app has several REST API endpoints:

* `/cpu_intensive`, simulating a CPU-intensive task. Calculates the square root of `64 * 64 * 64 * 64 * 64 * 64 ** 64` on each request.
* `/memory_leak`, simulating a [memory leak](https://en.wikipedia.org/wiki/Memory_leak). Adds 1MB of memory on each request.
* `/long_response_time`, simulating increasingly longer responses from a busy downstream system (e.g. a database). Sleeps for 2ms for each request received since the app was started.

All source code is available in [this repository](https://github.com/ivica-k/practical-ecs-scaling/tree/main).

## The performance envelope

Vertically scaling a container means giving the container more hardware resources.

> When you vertically scale an application the first step is to identify what resources the application container actually needs in order to function.

> There are different dimensions of resources that an application needs. For example: CPU, memory, storage, and network bandwidth. Some machine learning workloads may actually require GPU as well. [Source](https://containersonaws.com/presentations/amazon-ecs-scaling-best-practices/#vertical-scaling)

These resources form the _performance envelope_; a set of hardware constraints for the container.

![Performance envelope](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb0u4vhcqkgmgre4irst.png)

***

The first article in the series deals with an application that exceeds the "CPU" dimension of the performance envelope.

Have a look at how [changing the performance envelope for a CPU-heavy application](https://dev.to/ivicak/practical-ecs-scaling-vertically-scaling-a-cpu-heavy-application-105c) affects its performance.
C# - Simplify Event Handling with Lambda Improvements
Tags: csharp, programming, beginners, tutorial
Published: 2023-12-17 15:30:00

C# has progressively enhanced its lambda expressions, making them more powerful and versatile for a variety of uses, including event handling. Recent versions of C# allow you to write more concise and expressive event handlers using lambda expressions, which can greatly simplify your code, especially for UI events or asynchronous callbacks.

Here's how to use lambda expressions for event handling:

1. **Inline Lambda Expressions for Event Handlers:**
   Instead of defining a separate method for an event handler, you can use an inline lambda expression directly in the event subscription. This is particularly useful for simple event-handling logic.

2. **Leverage Local Functions When Needed:**
   For more complex event handling that requires multiple lines of code, consider using local functions within your method. This keeps your event-handling code close to where it's being used.

Example:

```csharp
public class MyForm : Form
{
    private Button myButton;

    public MyForm()
    {
        myButton = new Button();
        myButton.Click += (sender, e) => MessageBox.Show("Button clicked!");
        
        // For more complex event handling
        myButton.Click += HandleButtonClick;

        void HandleButtonClick(object? sender, EventArgs e)
        {
            // Complex event handling logic here
            MessageBox.Show("Handling button click with more complex logic.");
        }
    }
}
```

In this example, a simple lambda expression is used for a quick MessageBox display on a button click, and a local function is used for more complex logic associated with the same event. This approach results in more organized and readable code, especially in GUI applications or when dealing with asynchronous programming patterns.

Using lambda expressions for event handling not only simplifies your code but also makes it more expressive and maintainable, particularly in scenarios where the event-handling logic is short and straightforward.
How to quickly setup NodeJS with NVM
Tags: node, nvm, howto, beginners
Published: 2023-12-17 15:29:49


If you'd like to see the video version [Click here](https://bit.ly/mattveraldi-setup-nodejs-yt).

I had to re-install my WSL2 Ubuntu distro for Web Development, so I decided to document how I setup things starting from NodeJS.
These steps are meant to be executed on a Debian based Linux distribution, but they are valid also for Mac OSX.

## NodeJS

I often switch from one project to another and each project requires a different version of NodeJS. I am too lazy to manually install and change my `PATH` variables to perform the switch so I always install NodeJS through `nvm`.

### What is NVM?

`NVM` is a Node Version Manager, a `CLI` tool for NodeJS that provides utilities to install and switch from one version of `Node` to another in a matter of seconds.

### Install NVM

Open a new terminal and paste this command:

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
```

> Please note: If this post is too old, please make sure to replace `v0.39.7` with the latest version of `nvm`.

# Install NodeJS via NVM

Open a new terminal and paste this command:

```bash
nvm ls-remote
```

from the list that will appear, select the version you'd like to install. If you are not sure, install the latest Long Term Support (LTS) version with this command:

```bash
nvm install --lts
```

### Add .nvmrc to your project

One of the best features of `nvm` is the `.nvmrc`. It is a file that you can add inside the root directory of your NodeJS project to allow `nvm` users to `install` and `use` the correct NodeJS version without having to think about it. It is very good for `CI/CD` too!

To create a `.nvmrc`, open a new terminal on the root directory of your project and paste this command:

```bash
node -v > .nvmrc
```

To test if it works, paste this command:

```bash
nvm install && nvm use
```

You may create a `bash` script inside your `.bashrc` that automatically looks for an `.nvmrc` file in your directory and performs the `install` and `use` for you. [Click here to learn how](https://github.com/nvm-sh/nvm?tab=readme-ov-file#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file).

## Conclusions

This was a very quick introduction to how I setup NodeJS on my environment using `nvm`. If you have any questions please refer to the [official documentation](https://github.com/nvm-sh/nvm) or contact me via my [Social Links](https://mattveraldi.github.io/).
Build your first custom AI-powered application with LangChain
Tags: webdev, javascript, tutorial, opensource
Published: 2023-12-17 15:16:49

# About LangChain

Using language models like ChatGPT and Bard is simple, but making full AI applications often means combining different tools, which can be hard. That's where LangChain helps. It's like a toolbox that makes building powerful AI apps easier. You don't have to do a lot of complicated coding or set up complex stuff. LangChain makes it simpler by handling the integration part for you. You can build amazing things like [chatbots](https://python.langchain.com/docs/use_cases/chatbots), [document summarization tools](https://python.langchain.com/docs/use_cases/summarization), and [automated web Research](https://blog.langchain.dev/automating-web-research/).


## What is LangChain?<a id="what-is-langchain"></a>

It is an open-source framework that enables developers to combine large language models, such as GPT-4, with external sources of computation and data. Offered as a Python or JavaScript package.

## Capabilities of the applications built ?<a id="capabilities-of-the-applications-built-"></a>

_It is a framework for Python and JavaScript that simplifies the development of applications powered by generative AI and large language models._

These applications are:

**Aware of the context**:This means that applications can connect to different sources of information, for example, prompts or content, giving them a way to understand what is going on around them.

**Capable of reasoning**:The application can be connected to a large language model like [OpenAI](https://platform.openai.com/docs/introduction), [Cohere](https://docs.cohere.com/docs/llmu), or [Hugging Face](https://huggingface.co/models?other=LLM). This enables the application to answer based on the context it is given.

Applications created with LangChain, [explore](https://mirror-feeling-d80.notion.site/a-gallery-of-our-favorite-applications-built-with-LangChain-681b9d92998742818abaaf19d80d779b)

# LangChain Framework Overview<a id="langchain-framework-overview"></a>

It has six components that help to build the application for a specific use case.

### Model I/O (Input/Output):<a id="model-io-inputoutput"></a>

This works as the communication link between the LangChain and the selected language model. It helps in managing the instructions, asking questions, and getting answers.

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


Continue reading the full article to learn how to get started with in [building an AI Agent](https://journal.hexmos.com/langchain/).
Zod - TypeScript-first schema declaration and validation library #tips
Tags: programming, javascript, typescript, zod
Published: 2023-12-17 15:00:00

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

⭐ **Exporting a value and a type with the SAME NAME.** ⭐

This is great when your app has runtime things that feel like types, like Zod schemas.

👉 **Example:**

We have:

➖ User value defined by [Zod .object()](**url**):

```ts
// Path: user.schema.ts
export const User = zod.object({
  id: zod.number(),
  name: zod.string(),
  email: zod.string().email(),
})
```

➖ User type defined by [Zod .infer()](https://zod.dev/?id=type-inference):
```ts
// Path: user.schema.ts
export type User = zod.infer<typeof User>
```

In another place, we can use both User value and User type:

```ts
// Path: sample.ts
const user: User = {
  id: 1,
  name: 'John Doe',
  email: 'john@sample.com',
}
```

or:

```ts
// Path: sample.ts
const user = User.parse({
  id: 1,
  name: 'John Doe',
  email: 'john@sample.com',
})
```

or:

```ts
// Path: sample.ts
const user: User = User.parse({
  id: 1,
  name: 'John Doe',
  email: 'john@sample.com',
})

```

---

I hope you found it useful. Thanks for reading. 🙏
Let's get connected! You can find me on:
- **Medium:** https://medium.com/@nhannguyendevjs/
- **Dev**: https://dev.to/nhannguyendevjs/
- **Hashnode**: [https://nhannguyen.hashnode.dev](https://nhannguyen.hashnode.dev/)/
- **Linkedin:** https://www.linkedin.com/in/nhannguyendevjs/
- **X (formerly Twitter)**: https://twitter.com/nhannguyendevjs/
I Quit DEV and Moved to Substack
Tags: substack, content
Published: 2023-12-17 14:58:05

Dear awesome reader, I’ve got some thrilling news to share with you.

I’ve got some thrilling news to share—we shaken things up and made the jump from DEV to [Substack](http://datagibberish.com/)!

_Are you wondering why I made that move?_

Well, let me break it down for you.

## It’s all About You

When you hit that “Follow” button on Medium, you’re not just crossing your fingers and hoping to stumble upon my latest piece.

**Nope!**

With Substack, you don’t have to play the alghoritm game. You receive the full text in your inbox every time I drop some knowledge.

> It’s like having a VIP pass to the data analytics party, and you’re on the guest list!

No more missed articles. No more scrolling through endless feeds.

## Substack is More Interactive

Picture this: You’re sipping your morning coffee, and ding! There it is—the latest post from yours truly.

But wait, there’s more! With Substack, you can hit reply and shoot me a message.

_Got questions? Curious about my sources? Want to share your own insights?_

**Boom, we’re chatting!**

Substack is not your typical read-and-scroll platform. You can shoot me a message faster than you can say “data-driven decisions.”

I love replying to nice and curious people. So don’t be shy—drop me a line, share your thoughts, or throw your burning questions my way.

Let’s make this a conversation, not just a monologue!

![Two friends talking](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk3cyqtzz6ubfgx6gnx2.jpg)

## Accessibility Matters

So far, we have talked about the power of email.

_But what if you don’t want to share personal information just to read some text online?_

**No problem, I’ve got your back!**

Substack keeps it simple. You can devour my content without the hassle of creating an account. You don’t even need to enter your email address.

So whether you’re in your PJs or rocking a three-piece suit, dive right in. It’s data insights at your fingertips, hassle-free.

## So, what’s next?

So, are you ready to elevate our data journey together?

1. **Click that Follow Link**: Seriously, it’s like giving me a virtual hug. [Hit that link](http://datagibberish.com/), and let’s make this Substack journey official ([link](http://datagibberish.com/)).
2. **Spread the word**: Tell your friends, your neighbor’s cat, and that fella who always hogs the office microwave. Share the love, and let’s build a community that thrives on curiosity and camaraderie.
3. **Stay Tuned**: Brace yourself for mind-bending insights, quirky anecdotes, and the occasional dad joke. It’s going to be a wild ride.

_Hint_: There’s a lot of new content waiting for you there!

Remember, dear reader, this isn’t just about platforms—it's about us. So grab your favourite beverage (mine’s cappuchino, in case you were wondering) and let’s dive into the Substack Sea together.

http://datagibberish.com/

See you on the other side!
HOW TO CREATE A STORAGE ACCOUNT IN AZURE
Tags: beginners, programming, tutorial, cloud
Published: 2023-12-17 14:47:19

Azure Portal, Azure PowerShell, Azure CLI, or an Azure Resource Manager (ARM) template can all be used to create an Azure storage account. Here, I will walk you through the procedure via the Azure Portal, which is the easiest way for novices to follow:

1.**Open the Azure Portal.**
Use your Azure account to log in.

2.**Go to the Storage accounts page**.

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

Click the "Create" or Search for an already created resource group in the field. then enter set up the storage account's parameters:

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

3.**Enter the necessary data in the "Basics" tab:**
Select the Azure subscription that you want.
Resource Group: Choose an already-existing group, or establish a new one.

-Name of storage account: For your storage account, enter a globally unique name (lowercase characters and numbers only).
-Location: Select the area in which the storage account is to be created.
-Performance: Select the Standard or Premium performance tier.
-Account type: Select the kind of storage account (most scenarios recommend StorageV2).

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

4.**Set up advanced options (if desired):**

Most settings can be left at their default levels, but depending on your needs, you might want to change things like replication, access tier, and network settings.
Examine and produce:

5.**Go through your setup on the "Review + create" tab.**
Press "Review + create" to confirm your configuration.
To create the storage account, click "Create" if the validation is successful.

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

6.**Hold off until the deployment is finished.** On the "Deployment" page or in the notification section, you may keep an eye on the deployment process.

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

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

7.**Get into your storage account:**

Go to the storage account overview page to access and manage it after the deployment is finished.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d04betr61kx73e1u8071.png)
And that's it! You've been successful in setting up an Azure storage account. This storage account can now be used to store other kinds of data, including files, queues, blobs, and tables.
Configuring StyleX in React application
Tags: stylex, react, javascript, babel
Published: 2023-12-17 14:20:01

To make **[StyleX](https://github.com/facebook/stylex)** working in React applications we need a babel plugin called `@stylexjs/babel-plugin`. 
This babel plugin will be transforming **StyleX** code to _CSS_ classes.

In order to use babel plugins in apps made by `create-react-app` we either need to _eject_ or use `react-app-rewired`.
In this article we are gonna cover the second approach in 3 simple steps:

1. Install `react-app-rewired `
```bash
yarn add -D react-app-rewired customize-cra
```

2. Create `config-overrides.js` with the following content
```javascript
const { useBabelRc, override } = require("customize-cra");
module.exports = override(useBabelRc());
```

3. Create `.babelrc`
```javascript
{
    "plugins": [
      [
        "@stylexjs/babel-plugin",
        {
          "dev": true
        }
      ]
    ]
  }
```

Let's install **StyleX** packages:
```bash
yarn add -D @stylexjs/stylex @stylexjs/babel-plugin
```

Finally we can use **StyleX**:
```javascript
import React from 'react'
import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
  root: {
    width: '100%',
    color: 'red',
  },
  highlighted: {
    backgroundColor: 'green',
  },
});

function App() {
  return (
    <div {...stylex.props(styles.root, styles.highlighted)}>Content</div>
  );
}

export default App;
```
🤔 Python Quiz: The `yield` Keyword
Tags: programming, beginners, tutorial, python
Published: 2023-12-17 14:00:00

> [Follow me to learn 🐍 Python](https://dev.to/vladignatyev) in 5-minute a day fun quizzes!

You mastered `iterables`, didn't you? Then it's time for `generators` and the spell `yield`!

# Quiz
Which code sample correctly uses the `yield` keyword in Python to make a count-down?

# Sample 1
```python
def count_down(number):
    while number > 0:
        yield number
        number -= 1

for count in count_down(5):
    print(count)
```

# Sample 2
```python
def count_down(number):
    for i in range(number):
        return i

for count in count_down(5):
    print(count)
```

Post your answer in the comments – is it 0 for the first sample or 1 for the second! As usually, the correct answer will be explained in the comments.
UNDERSTANDING AZURE STORAGE
Tags: webdev, programming, cloudcomputing, cloudstorage
Published: 2023-12-17 13:18:43


Microsoft Azure offers a cloud storage option called Azure Storage. It provides a range of cloud storage and data retrieval services. Azure Storage offers the following primary storage service types:

**Blob Holding:**

The goal of blob storage is to handle and store unstructured data, including logs, documents, and multimedia.
Access Tiers: Depending on the consumption patterns of the data, you can select from a variety of access tiers, including Hot, Cool, and Archive.

**Storage of Files:**

Goal: File Storage is a cloud-based, fully managed file sharing that is accessible using the Server Message Block (SMB) protocol. It works well with business applications that need a shared file system.
Use cases include general-purpose file sharing, virtual machine (VM) storage, and file shares for applications.

**Storage in Queues:**

The goal of queue storage is to provide a message service that enables asynchronous communication between various application components. It's frequently applied to increase scalability and decouple components.
Use Cases: Message queues to facilitate inter-application communication.

**Table Storage Organization:**

Goal: Large volumes of structured data can be stored in Table Storage, a NoSQL data storage. Applications that need quick and flexible access to data can use it.
Use Cases: storing and retrieving logs, device information, and user profiles, among other non-relational data.

**Managed disk storage (disk storage):**

Goal: Managed Disks give Azure Virtual Machines high-performance, scalable block storage.
Use Cases: Preserving virtual machine data and operating system drives.
You can use a number of tools and libraries to communicate with Azure Storage, including:


**Azure Portal:** The web-based resource management tool for Azure.
Azure Storage Explorer is a stand-alone application that makes interacting and managing Azure Storage simple.
**Azure PowerShell:** PowerShell scripts can be used to manage Azure resources through command-line tools.
**Azure CLI:** Tools for controlling Azure resources with a command-line interface.
Software development kits (SDKs) for Azure Storage are available for a number of programming languages, and they let you incorporate Azure Storage into your apps.

To guarantee the highest performance and security of your stored data, it's critical to comprehend the security features, best practices, and access controls of Azure Storage.