teleren/devto huggingface dataset:
Circuit Breaker Pattern in C#
Tags: csharp
Published: 2023-12-16 21:00:27

The Circuit Breaker pattern is a useful tool in C# programming for handling failures and preventing cascading system failures. It is particularly useful when making remote service calls or executing potentially error-prone code.

In its simplest form, the Circuit Breaker pattern is implemented as a state machine with three states: Open, Closed, and Half-Open. Initially, the Circuit Breaker is in the Closed state, allowing requests to pass through to a remote service or code execution. If a predefined number of failures occur within a certain time frame, the Circuit Breaker enters the Open state.

When the Circuit Breaker is in the Open state, it immediately returns an error without making the actual call. This prevents the system from wasting resources on further requests that are likely to fail. After a specified period of time, the Circuit Breaker enters the Half-Open state, allowing a single request to pass through. If this request succeeds, the Circuit Breaker goes back to the Closed state, assuming the remote service or code is functioning properly. If the request fails, the Circuit Breaker returns to the Open state.

Implementing the Circuit Breaker pattern in C# is straightforward. There are several libraries available, such as Polly, that provide a convenient way to integrate the pattern into your code. These libraries offer configuration options to set the failure threshold, the time frame for measuring failures, and the timeout for switching to the Half-Open state.

To use the Circuit Breaker pattern, you can wrap your remote service calls or error-prone code inside a try-catch block. If an exception occurs, you can handle it accordingly. If multiple failures occur within the specified time frame, you can handle the circuit being open and adjust your code behavior as necessary, such as showing an error message to the user or switching to an alternative service.

Overall, the Circuit Breaker pattern is a valuable technique in C# programming for ensuring system resilience, preventing cascading failures, and improving the overall reliability of your applications.
Earn $3000 in a week free
Tags: earnmoney, makemoney, earn, earnfromhome
Published: 2023-12-16 20:18:04


"Unlock the potential for financial prosperity with our exclusive opportunity to 'Get $3000 in a Week.' Experience a game-changing system that empowers you to achieve impressive earnings in just seven days. Join a community of success-driven individuals who have discovered the secret to rapid financial growth. Our proven method combines innovative strategies with expert guidance to help you realize your financial goals quickly and efficiently. Don't miss out on this limited-time chance to transform your financial future. Seize the opportunity and start your journey to earning $3000 in a week today!"
**[earn now:](https://tinyurl.com/4k7bf6zp)**
Object manipulation technique.js
Tags: javascript, programming, beginners, productivity
Published: 2023-12-16 20:09:42

I am working on leveling up my javascript skills and like to learn by building things. So I was working on a simple javascript game as an experiment. When I figured out something weird you could do with object manipulation that kind of made my head screwy. You can reference one object within another and manipulate both of them simultaneously. Let's have a look at some code here.


## Can I get a reference

Below I declare 2 variables. however the value of one variable is the other variable.


```js

Let original = "unique string";

Let reference = original;

```

If you were to log out the value of these variables they would be identical. The same is also true for objects with nested properties.


```js

let theOriginal = {stuff :'unique string', another : ‘second unique string’}

let theReference = theOriginal 

```

Now if you log out `theReference` you will get the same key/values as `theOriginal`.

You can take this one step further and manipulate a value. 


```js

let theOriginal = {stuff :'unique string',

Another: ‘second unique string’}


let theReference = theOriginal


theReference.stuff = 'other string’


Console.log(theOriginal.stuff) 

// will now log ‘other string’

```


## Ok whats going on here?

When I first learned Manipulating one variable affects the other in this way it kind of made my head spin. I was thinking about each variable as being its own separate thing. This however is not true. The reason this works is because in the actual physical memory of the computer this is running on there is really only one object. This object is referenced by 2 different variables. Much like having 2 doors to the same cabinet. If you add something to the cabinet with 1 door when the other door opens there will be a new item there. 


## Why do this?

You can add many more references to the same object as you want. Though this adds a lot of unnecessary complexity to your code. There are few use cases where it really makes sense to do this. For me, my use case was a turn based game where each player object takes a turn being the active player.  Having the active variable just reference the player object meant any changes made to the active object during the turn would already be represented in the player object.


I think this is a cool tid bit of knowledge that really expanded my understanding of javascript as a whole. Below is a code pen where I experimented with this concept.
I want to thank you for reading this through and I hope you found this article helpful in some way. 


{% codepen https://codepen.io/techThatConnect/pen/qBLYwzg %}
How to reboot the Cisco Switch using PuTTY?
Tags: putty, puttygen, cisco, ssh
Published: 2023-12-16 20:05:47

Remotely rebooting Cisco switching devices typically takes place over SSH terminal connection, by using PuTTY. By enabling vty account access and confirming operational IP connectivity to target devices, PuTTY securely tunnels encrypted traffic to enact maintenance events. 

After authenticating as highly privileged users and entering Cisco configuration modes, the reload command issues system reboot requests cleanly and securely over the authenticated PuTTY channels.

To reboot a Cisco switch using PuTTY, follow these steps:

**Download and install PuTTY:**

Download and install PuTTY on your computer.

**Connect to the Cisco Switch:**

Open PuTTY configuration on your computer,

In the **HostName** section, enter the IP address or username of the Cisco switch.

Change the connection type to **SSH** and port to **22**.

Click on **Open** to make the connection to the Cisco switch.

When you connect, enter the username and password when prompted.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d6zkk06r2nwmag8rfmv.png)

**Access Privileged EXEC Mode:**

After logging in, you need to access privileged EXEC mode, run command:
**enable**

**Enter Global Configuration Mode:**

Enter global configuration mode by running command:
**configure terminal**

**Reboot the Switch:**

To start the reboot, use command:
**reload**

The switch will prompt you to confirm. Type yes and press Enter.

In conclusion, PuTTY remains flexible utility for Cisco devices by providing a secure IP vector for remotely performing maintenance events on essential switching tools. Cisco IOS native authentication and accessibility methods work consistently with PuTTY terminal prompter to provide smooth execution of privileged system restart sequence

You can also use use [SSH key authentication on Cisco device for secure connection by uisng PuTTY.
](https://dev.to/puttykeyinfo/how-to-use-ssh-key-authentication-on-cisco-device-by-using-putty-1dhn)
How to Resolve “Software caused connection abort” error when connecting Raspberry Pi from PuTTY?
Tags: putty, puttygen, raspberrypi, ssh
Published: 2023-12-16 19:59:51

When connecting to a Raspberry Pi, the "Software caused connection abort" error in PuTTY occurs. This error often indicates disturbance in the communication between your computer and the Raspberry Pi, leading to an unexpected termination of the connection.

We provide the common causes and provide other options to help you determine and solve the connection abort problem, ensuring an easy and stable connection to your Raspberry Pi.

The "Software caused connection abort" error in PuTTY when connecting to a Raspberry Pi can be caused by various factors. 

Also check using [cryptographic key for authentication on Cisco device.](https://dev.to/puttykeyinfo/how-to-use-ssh-key-authentication-on-cisco-device-by-using-putty-1dhn)

**Here are some common reasons and solutions:**

**Network Issues:**

Check your computer and the Raspberry Pi network connections. Make sure that both devices are on the same network and that there are no network disturbances.

**Firewall Configuration:**

Verify your computer and the Raspberry Pi firewall settings. Check that the SSH port is allowed through the firewall.

**Incorrect IP Address:**

Confirm that you are connecting to the Raspberry Pi using the correct IP address. Running the command hostname -I on the Raspberry Pi will display the IP address.

**Insufficient Raspberry Pi storage**

Check that the Raspberry Pi has enough storage to handle the SSH connection. Consider optimizing or upgrading the Raspberry Pi if its capacity is insufficient.

**PuTTY Configuration Issues:**

Review the PuTTY configuration. Check that the correct settings, such as the IP address, port, and connection type (SSH), are configured.

**Antivirus Safety:**

Some anti-virus and security applications can trigger SSH connections to be unsuccessful. Disable or modify the settings of any such program temporarily to see if it resolves the problem.

By checking all these issues, you can resolve the Software caused connection abort error when connecting to Raspberry Pi from PuTTY. Now you can successfully connect to Raspberry Pi to manage the function.
How to open QFitsView in PuTTY from Mac?
Tags: putty, puttygen, puttykeyinfo, puttyformac
Published: 2023-12-16 19:54:41

QFitsView is a strong and popular FITS file viewer for astronomy and astrophysics. FITS is a standard format used to store, transport, and interpret scientific data, particularly astronomical images and spectra. QFitsView is an effective tool for astronomers to examine and study FITS files, involving a variety of features to improve understanding of astronomical data.

When working with QFitsView on a Mac, there may be times when accessing it remotely on a server is required. This is done by combining PuTTY, an SSH client, and XQuartz, an X Window System for macOS. X11 forwarding is used to display the graphical interface of QFitsView on the local computer, improving the user ability to navigate.

Also check [how to implement SSH key authentication on Cisco device by using PuTTY](https://dev.to/puttykeyinfo/how-to-use-ssh-key-authentication-on-cisco-device-by-using-putty-1dhn).

If you want to use QFitsView on a remote server via PuTTY from your Mac include some steps:

**Prerequisite:**

**Download PuTTY:**

Download and install PuTTY on your computer.

**Install XQuartz:**

Make sure you have XQuartz installed on your Mac. XQuartz is a MacOS open-source version of the X Window System.

**Open XQuartz:**

By launching XQuartz, you are configuring your Mac to receive and show graphical output from remote servers.

**Open PuTTY:**

Launch PuTTY configuration windows, In the **hostname **section, Enter remote server IP address or hostname.

Set the connection to SSH and port to 22. 

On the left panel, go to **Connection > SSH > X11**, Select the Enable X11 forwarding.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwggg3lckgrah6huqabm.png)

Click on **Open** to make the connection.

**Run QfitsView:**

To open the qfitsview from your server from Mac, run command.
**path to/qfitsview**

remove **path to** with the exact path of the qfitsview.

The graphical interface of QFitsView should appear on your local machine.Additionally, ensure that XQuartz is running and active on your Mac during this process.
AppError middleware function create
Tags: webdev, javascript, programming, beginners
Published: 2023-12-16 19:40:02

```ts

//==> src/app/errors/AppError.ts
class AppError extends Error {
  public statusCode: number;

  constructor(statusCode: number, message: string, stack = '') {
    super(message);
    this.statusCode = statusCode;

    if (stack) {
      this.stack = stack;
    } else {
      Error.captureStackTrace(this, this.constructor);
    }
  }
}

export default AppError;

```

```ts
//=> src/app/modules/academicDepartment/academicDepartment.model.ts

  if (!isDepartmentExist) {
    throw new AppError(
      httpStatus.NOT_FOUND,
      'This department does not exist! ',
    );
  }
```
Implement transaction & rollback
Tags: typescript, mongoose, webdev, programming
Published: 2023-12-16 19:33:21

```ts
const session = await mongoose.startSession();
try {
  session.startTransaction();
  const newUser = await User.create([userData], { session }); // array
  await session.commitTransaction();
  await session.endSession();
} catch (err: any) {
  await session.abortTransaction();
  await session.endSession();
  throw new AppError(httpStatus.NOT_FOUND, err);
}
```
How to fix "PuTTY Fatal error: network is unreachable"?
Tags: putty, puttyerror, puttygen, secureaccess
Published: 2023-12-16 19:33:15

PuTTY popular SSH client allows user to connect to remote server securely. But sometimes PuTTY Fatal Error network is unreachable while trying to make the connection between devices.

This error indicates that PuTTY is unable to establish a network connection with the specified host, leading to a failed SSH session. This article provides steps to encounter this Fatal error to establish the smooth connection.

Explore how to [enable ssh authentication on Cisco device](https://dev.to/puttykeyinfo/how-to-use-ssh-key-authentication-on-cisco-device-by-using-putty-1dhn).

**Fix PuTTY Fatal error: network is unreachable**

**Verify Network Connection:**

Make sure your local system has a stable and active internet connection.

**Disable Firewall and Anti-virus temporarily:**

Temporarily disable the firewall on your local machine and try connecting again.

**Router/Network Issues:**

If you're connecting to a remote server on a different network, check for issues with routers, switches, or any network devices in between. 

**DNS Resolution:**

If you're using a hostname instead of an IP address, ensure DNS that resolution is working correctly. Try using the IP address directly to see if it makes a difference.

**Proxy Setting:**

If you are using a proxy, make sure your proxy settings in PuTTY are accurate. Check PuTTY Connection > Proxy settings to see if they are suitable for your network.
 
 
By performing these tasks this PuTTY fatal error is diagnose
How do I configure PuTTY settings when using a USB to connect to a Cisco device console port?
Tags: putty, cisco, puttygen, puttykey
Published: 2023-12-16 19:26:52

Configuring PuTTY for connecting to a Cisco device's console port involves going through many essential parts. These critical components, which include the USB-to-serial converter, COM port identification, and PuTTY settings adjustment, make up the foundation of a smooth connection process. In this guide, we will provide an understanding of the essential components needed to successfully interact with Cisco device using PuTTY.

**Prerequisite**:
Download and install PuTTY on your local computer.

Connect the USB-to-Serial Adapter

Insert the USB-to-serial adapter into the USB port on your computer.

**Install USB-to-Serial Adapter Drivers:**
Ensure that the USB-to-serial adapter drivers are installed on your computer.

**Identify the COM Port:**
On your computer, open the Device Manager.
Under the Ports section, look for the USB Serial Port.

Note down the COM port number assigned to your USB-to-serial adapter e.g. COM1, COM2.

**PuTTY configure connection:**

Open PuTTY on your computer.

On the left panel, go to the Serial category.

Enter the COM port number (for example, COM1) in the Serial line section.

Set the baud rate to match the device you're connected to e.g. 9600.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjfwxvjgj0s27m2o61ub.png) 

**Configure Other Serial Settings:**
Adjust the data bits, stop bits, and parity settings according to the requirements of your Cisco device. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih4iw30a76vyg99am0ae.png)


**Save Session Settings:**

You can also save these settings for later use by entering a session name in the Saved Sessions section and click on save to save the session.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xcu9qgasp3jj7w5k2606.png)

**Establish connection:**
Click on Open to make the connection. Enter the username and password when prompted.

You should now see the console interface of your Cisco device in the PuTTY window. Finally, you have successfully configured PuTTY to connect to the console port of the Cisco device via a USB. The connection has been formed by identifying the COM port, establishing the baud rate, and defining other critical settings. You are now connected to the Cisco device console prepared to do any necessary setup, management, or troubleshooting operations.

You can also use[ SSH key authectication to connect Cisco device by using PuTTY.](https://dev.to/puttykeyinfo/how-to-use-ssh-key-authentication-on-cisco-device-by-using-putty-1dhn)
How to use SSH Key Authentication on Cisco Device by using PuTTY?
Tags: putty, puttygen, puttykeygenerator, secureconnection
Published: 2023-12-16 19:11:09

The Secure Shell, or SSH, protocol plays an essential role in providing encrypted and secure communication between devices. In Cisco device, strong authentication is essential. This article uses SSH keys for authentication to Cisco devices using PuTTY as the interface in a Windows environment.

SSH key usually consist of a public and private pair, providing a more secure alternative to password-based authentication. PuTTY, a popular SSH client for Windows, includes PuTTYgen, a utility that simplifies the creation and maintenance of SSH keys.

**Prerequisite:**
Download PuTTY and PuTTYgen on your local Windows, if you don't have.


**Generating SSH Key Pair with PuTTYgen:**
Open PuTTYgen, to [generate public and private key for secure connection](https://puttykeyinfo.com/).
Move your mouse over the blank area to generate randomness.

**Select key type:**
Select the key size and key type.

**Save the Keys:**
Click on Save private key to save the private key. This file generally has a .ppk extension.
Click on Save public key to save the public key.

**Configure PuTTY connection:**
Open PuTTY on your Windows, enter your remote server public IP address or username in the Hostname section.

Set the connection to SSH and port to 22.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a3ry9vrw7w046esohqc.png)
On the left panel, navigate to the Connection>SSH>Auth category. 

Click on Browse and select the PuTTYgen-generated private key.

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

**Saving session:**
Enter a name in the Saved Session section and click on save to save the connection for later use.

Establish the connection:
Click on Open to make the connection.
Enter the username and password when prompted.

Using PuTTY for enabling SSH key authentication for Cisco devices provides a secure and efficient solution to access and manage network devices. By eliminating the need for password-based authentication, SSH keys improve security by lowering the risk of unauthorized access and potential security breaches.
How to create a hash for a STRING in Swift
Published: 2023-12-16 19:10:48

How to create an identifier for strings having same number of characters?

Use cases:
- Group anagram in a dictionary
- Check the number of characters in two strings are same

```swift
func createHash(_ s: String) -> String {
    var hash = Array(repeating: 0, count: 26)
    
    Array(s).forEach({ char in
        let index = char.asciiValue! - Character("a").asciiValue!
        hash[Int(index)] += 1
    })
    
    return hash
        .map({ String($0) })
        .joined(separator: ":")
}

```

input: abbca
output: a2:b2:c
Unlocking Growth: The Power of Headless CMS for Scalable Marketing Websites
Tags: webdev, frontend, wordpress, marketing
Published: 2023-12-16 18:39:48

> This could be a real-life story:

Okay, picture this: you're a business warrior, wielding the mighty WordPress sword on the war for customers. You've conquered content mountains, slayed SEO dragons, and built a website fortress your CEO admires. But here's the rub – your empire is starting to feel... clunky. Scaling your conquers? A nightmare. Dynamic landing page heroes, that can help win thousand more battles? More like static sighs. And Elementor, your once-trusty page builder companion, now feels like a rusty chainmail slowing you down.

Sound familiar? Yeah, I was there too. More than I need to learn the way out. But one of those times, I stumbled upon a whisper, a legend whispered by tech futurologists oracles: Headless CMS. At first, I scoffed. "Decoupling? Content freedom? Sounds like marketing mumbo-jumbo!" But curiosity, that insatiable developer beast, wouldn't let me rest. So, I dove in.

And whoa, mama, did the world explode! Headless wasn't just a new weapon; it was a whole new arsenal. Suddenly, I could:

Update content like a ninja from the East: No more crawling through page-by-page jungles. One change, bam! Reflected everywhere. Efficiency? My new middle name.

Scale like a plague, but a good one: Traffic surge? No sweat. Headless handled it with the grace of a mythical beast. My website, once a creaky castle, became a sprawling, scalable kingdom.

Craft SEO magic like a wizard: Dynamic landing pages? Child's play. Headless lets me and my SEO mages weave SEO spells with keywords and data, capturing leads like enchanted butterflies in a net.

But here's the best part, fellow warriors: I didn't have to burn my WordPress kingdom to the ground. Headless offered me an incremental revolution. I started small, building new pages like shiny outposts, testing the waters without flooding the old city. I experimented with programmatic SEO, watching leads pour in like magic potions. Data, my new war council, guided my migration step by step, minimizing risks and maximizing gains.

And now? My website's a soaring sky-ship, powered by Headless magic. Scalable, dynamic, SEO-charged – it's a testament to future-proof marketing. And believe me, the journey was exhilarating.

So, to the CEOs and marketing warlords out there, I say this: Don't let your WordPress castle hold you back. Embrace the Headless Revolution. It's not just about the tech; it's about unleashing your business potential in 2024. It's about conquering new markets and leaving your competitors in the dust.

Headless CMS isn't just a tool; it's a battle cry. Raise your digital swords, my friends, and let the Headless awakening begin!

P.S. Want to hear more about my epic migration saga? Hit me up! I've got war stories and dev secrets to share. Let's build a Headless empire together!