teleren/devto huggingface dataset:
Add HealthCheck to ASP.Net Core API
Published: 2022-03-20 08:21:11

1. Install package  
```
dotnet add package Microsoft.Extensions.Diagnostics.HealthChecks
```
2. Create HealthCheck class
```C#
public class SqlConnectionHealthCheck : IHealthCheck
{
    private const string DefaultTestQuery = "Select 1"; public string ConnectionString { get; }
    public string TestQuery { get; }
    public SqlConnectionHealthCheck(string connectionString) : this(connectionString, testQuery: DefaultTestQuery)
    { }
    public SqlConnectionHealthCheck(string connectionString, string testQuery)
    {
        ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
        TestQuery = testQuery;
    }
    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken))
    {
        using (var connection = new SqlConnection(ConnectionString))
        {
            try
            {
                await connection.OpenAsync(cancellationToken);
                if (TestQuery != null)
                {
                    var command = connection.CreateCommand();
                    command.CommandText = TestQuery;
                    await command.ExecuteNonQueryAsync(cancellationToken);
                }
            }
            catch (DbException ex)
            {
                return new HealthCheckResult(status: context.Registration.FailureStatus, exception: ex);
            }
        }
        return HealthCheckResult.Healthy();
    }
}
```
2. Configure startup.cs service
```c#
public void ConfigureServices(IServiceCollection services)
{
    services.AddHealthChecks()
            .AddCheck(
            "OrderingDB-check",
            new SqlConnectionHealthCheck(Configuration["ConnectionString"]), HealthStatus.Unhealthy,
            new string[] { "orderingdb" });
}

```
3. Map HealthCheck path 
```c#
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapHealthChecks("/hc");
    });
}
```
### reference
- https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-6.0
- https://docs.microsoft.com/en-us/dotnet/architecture/microservices/
Print vs Return in Python
Tags: python, beginners, programming, devjournal
Published: 2022-03-20 04:47:32

![print vs return.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647713583456/YZCTM1WKu.jpg)

I pondered on what my first post will be, like the luck of the genie, someone asked the below question and I jumped on it.

**"Please, what's the difference in using return or print in a function for python?"**

Let me paint a really "long in a short story" here:


1. Return - Come back
2. Print - Shout or do something
3. Function_name - Your errand boy

So, you sent your guy to buy something for you. Let us say, Chicken Republic's burger (my fav ❤) with the Monster drink and gave him your ATM card and PIN (hope you trust this friend though - *I won't be held accountable. Lol* 😁).
You told him on getting to the location, he should drop a flash on your mobile phone number.
When he's done with the purchase and paid successfully, he should bring the items to you.

Now, when he brings the items, you have unlimited options of things to do with them.
You can either:
- eat it
- drink it
- give to a friend
- keep it
- throw it away ...et al

Using the above, the **print** in a function is like the dropped-flash that you asked your friend to give to you when he's at the location. When you call a function, you should do something.
However, when you **return** a value, just like when you asked your guy to come back with the items, you are instructing the function to **come back** with something. 
This something can be used in any way that you like. Store in a variable, do nothing, used in an expression, et al.

Now, let me add the samples:
```
def say_name():
    name = 'alvicci'
    print("My name is {:s}".format(name))
```
If you call the function, it will print the next line:
```
say_name()
My name is alvicci
```
However, let us use the same function, but this time instead of using print, let us use the return keyword.
```
def say_name():
    name = 'alvicci'
    return("My name is {:s}".format(name))
```
If you call the above function, nothing happens. You didn't tell it to do something but to return something.
What do we do to things that we receive? Lord and master, over to you, lordship. 😎
Let me use what was returned to do something:
```
print("What is your name? ")
print(say_name())
```
We called the function in the print function. So, it will evaluate the function, **say_name()** first and give the return value to the print function.
Now, you have given the print function something. And the print function always displays to the console what it was given.
The output will look like this:
```
What is your name? 
My name is alvicci
```

This is my first attempt ✍ and I hope you find this helpful. However, I'm still learning and growing!
My Five weeks in Taskforce 5.0 at Awesomity Lab and Code of Africa.
Tags: awesomity, codeofafrica, taskforce
Published: 2022-03-20 07:47:15

> Great things happen to those who don’t stop believing, trying, learning, and being grateful.
**Roy Bennett**

This week was fantastic and enjoyable. In particular, for technical skills where we go deeper into react native, it was taught for me in the previous days because we began to use a programming language I had never used before and at times I felt like giving up, but because of the communication and team spirit session we had, I realized that giving up was not an option, so I sought assistance from my teammates, who assisted me in overcoming the situation. Now, I thank God that I am at a good level and can complete the task in the same manner as others, and I appreciate all of my teammates' encouragement, especially @Elvis, who took the time to assist me.
Again, I'd like to thank **#CoA** and **#Awesomity** for the courses they provide that have taught me to never give up and how to manage myself, such as the communication lesson, which has taught me how to communicate and collaborate with others, time management, which has taught me how to manage time so that I can use extra time without negative consequences, and self-organization, which has taught me how to overcome my challenges.

![Learn to code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74qs2jsurkqt2pv0gp3l.jpg)

To summarize, we only have one week left to finish our Bootcamp. Over the last five weeks, we've learned a lot of interesting things, and I'm excited to put what I've learned in the Bootcamp to good use by solving societal problems.

Thank you for taking the time to read my post; I'll see you again next week to give you an update on my final week of Bootcamp.
Creating a React App with Typescript + Tailwind Support
Tags: react, tailwindcss, typescript, beginners
Published: 2022-03-20 07:34:38

## Introduction

Hello! Here I will try to explain how to set up a React app with both Typescript and Tailwind.

---

## Creating the React app with Typescript

This part is really simple, all you need to do is add the template option to create-react-app command.
Feel free to reaplace "app" with anything else.

Once installed simple cd into the directory.

```bash
npx create-react-app app --template typescript

cd app
```

---

## Adding Tailwind

Finally we need to add tailwind. First we need to install the needed modules

```bash
npm install -D tailwindcss postcss autoprefixer 
```

Next we need to create the config files which can easily be done via the following command:

```bash
npx tailwindcss init -p
```

Next open up the created "tailwind.config.js" file and add the following to "content":

```javascript
content: [
	'./src/**/*.{js,jsx,ts,tsx}',
],
```

Next we need to add the Tailwind directives to the "src/index.css" file, add the following to the top of the file:

```css
@tailwind base;
@tailwind components;
@tailwind utilities;
```

---

## Checking that it works

Now that we have set up Typescript and Tailwind we need to check to see if it works.
Open up "src/App.tsx" and change it to the following: 

```typescript
import React from 'react';
import './App.css';

function App() {
  return (
    <h1 className="text-3xl font-bold underline text-red-600">
      Simple React Typescript Tailwind Sample
    </h1>
  );  
}

export default App;
```

Done, now let's start the application.

```bash
npm start
```

The browser should automatically open and display the index page. If all is okay the header should be bold, underlined and red. 😀

The source for this example can be found here:
https://github.com/ethand91/react-typescript-tailwind


---

Like me work? I post about a variety of topics, if you would like to see more please like and follow me.
Also I love coffee. 

[![“Buy Me A Coffee”](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ethand9999)
#Day 1 of solving 450 questions.
Tags: python, programming, algorithms
Published: 2022-03-20 07:24:39

🗓 DAY 1 : March 20, 2022
PROBLEMS SOLVED TODAY:
[1](https://practice.geeksforgeeks.org/problems/kth-smallest-element5635/1)||[2](https://leetcode.com/problems/sort-colors)||[3](https://practice.geeksforgeeks.org/problems/union-of-two-arrays3538/1)||[4](https://practice.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1#)||[5](https://practice.geeksforgeeks.org/problems/cyclically-rotate-an-array-by-one2614/1#)

Thinks I learned :

- Why we use if__name__ = '__ main __'
- Dutch national Flag Algorithm(2nd Problem)
- Kadane's Algorithm

[GITHUB REPO](https://github.com/hesoyamm/450questions)
Selection SORT in JS
Published: 2022-03-20 07:24:08

So as we all know selection sort has the following logic

_From i=0 to < array length
Assume the element at i is the least in the array, assign i to indexOfMin
for J from i+1 to end of array
see if there is an element with lower value
if there is , record its index
if the endex of the current element and the index of the 'lowest' element is
is not the same swap em_

I tried implementing this as follows (which was actually didnt work)

`function selectionSort(array){
    for(let i=0;i<array.length;i++){ //i= 0 , i< 3 i++,// processing when i =1,
        let indexOfMin = i // assume indexofMin = 0, // indexOfmin = 1
        let newIndexOfMin; //undef
        console.log("iteration number in i " + i)//1
        for(let j=i+1;j<array.length;j++){ ////j=1, j<3, ++2
            console.log("iteration number in j " + j)
            if (array[j]<array[indexOfMin]){ //2 <3 ,1<3
                newIndexOfMin=j // j = 0
                console.log("newIndexOfMin inside; " + newIndexOfMin)
            }
        }
        console.log("newIndexOfMin; " + newIndexOfMin+ "\n")
        if(newIndexOfMin!==indexOfMin){// 0 !=1
          let  newMinValue =array[newIndexOfMin]// 
          array[newIndexOfMin] = array[indexOfMin]
          array[indexOfMin] = newMinValue;
          console.log("print array here "  + array )
        }
    }
return array;
}`

And Iam still figuring this out, however meanwhile the correct answer is as below

`function selectionSort(array){
    for(i=0;i<array.length;i++){
         let indexOfMin = i;
        for(let j =i+1; j<array.length;j++){
            if (array[j]<array[indexOfMin])
            {  indexOfMin = j   }
            if(indexOfMin !=i){
                let least= array[indexOfMin] ;
                array[indexOfMin] = array[i];
                array[i]= least;
            }           
        }    
    }
    return array;
}`
HackerTab - Everything a DEV needs, in one tab ✨
Tags: programming, productivity
Published: 2022-03-20 07:15:23

Yesterday, I came across this product (I think on producthunt, but i honestly don't remember)

It's really really good - combines all the important stuff in one tab - trending Github, Dev.to feed, hackernews, product hunt, and (you can turn on) reddit, events, etc.

I personally don't use it as my new tab page, but I have a shortcut to https://now.hackertab.dev and always go there now (instead of dev.to for reading)

You can configure stuff too
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i81tkrymry1dapx8xnv1.png)
 
It's really cool, check it out!
Nenhum projeto essa semana
Tags: brasil
Published: 2022-03-20 07:13:09

Bom dia, boa tarde ou, quem sabe, boa noite...
Hoje não vai ter um post muito elaborado porque esta semana me bateu uma bad muito grande devido a algo que aconteceu no sábado da semana passada. Mas relaxem não foi nada grave ou que me machuquei, físicamente estou muito bem, mas mentalmente abalado.

Só foi algo que falaram e me machucou muito, e nem foi pra mim, mas pra alguém muito próximo. E aí desde então não estou animado pra nada, e minha vontade desde então é ficar em casa e se possível dormindo.

Eu poderia pedir conselhos ou perguntar o que vocês fazem quando isso acontece, mas como nada adianta pra mim não irei fazer isso kkkk (ou melhor rsrsrsrs).

## Mas é isso, nada fiz essa semana.

Então, devido a isso, não fiz nada. Nenhum projeto novo, nem incrementei meus projetos. Nem o de angular, nem o de Blog, não estudei as aulas direito essa semana (consegui estudar uma matéria só) e as coisas não rendem.

É isso, se quiserem comentar algo, podem usar aqui ou qualquer uma das minhas redes sociais. Eu poderia colocar elas aqui mas...

Ps.: Sei que não deveria postar isso aqui, mas sei lá só estou justificando o porque de não ter um post mais bem elaborado essa semana.
My fifth week experience while in the taskforce at CodeofAfrica and Awesomity lab.
Tags: reactnative, awesomitylab, codeofafrica
Published: 2022-03-20 07:04:42

**what experience and challenges, did you face in the fifth week at the taskforce?**

My experience at the tasks force in a duration of a month and one week, was a reflection of an establishment of a team work atmosphere, and gaining more interesting skills  and knowledge, that is a reliability to making a difference in the tech world in lack. I gained more experiences both soft and technical skills that l found to be enlightening.

Further more, we learnt about design thinking and self organization as soft skills that are relevant to a person's daily life skills that are used. We learnt as well in continuation of the technical skills react native subtopics, specifically in different terms which are context API which used whenever there is a need to change an app in light or dark mode, Database management that mostly deals with the how to storage data and Axios, which is used to fetch data. The new topic of programming language is new to me and a bit challenging to grasp however, with persistence and dedication to the course, positive results shall be given.


In my fifth week at the tasks force was full of new skills to study and learn about, as well as the team members partaking along while brainstorming and sharing moments together.
Journal CLI - Write Journal in Notion using CLI
Tags: javascript, opensource, showdev, bash
Published: 2022-03-20 07:03:22

Hello folks, today I tried to play around with Notion API and NodeJS to create a CLI which can write Journal for you and store it in a Notion Database.

These days, there is a lot of stuff going on in our lives and we want to focus on the ones which matter most to us. One way to solve this is by writing a journal and sorting this chaotic mess. 

Using [Notion](https://notion.so), we can create beautiful interactive notes and much more. Using the power of notion and efficiency of CLI, I developed this quick way, you can start journaling, by answering just 5 questions at the end of the day and the Journal will be saved in a database in Notion.!

NPM Link - [https://www.npmjs.com/package/journal-notion-cli](https://www.npmjs.com/package/journal-notion-cli)

### Duplicate Template
To Get Started Duplicate this [Notion Template](https://amit-wani.notion.site/amit-wani/Journal-a19377f6b17d47768e03d4ffe62a030d)

### Installation
Then Install Journal CLI from NPM using
`npm i -g journal-notion-cli`

### Connect to Notion
Connect to the notion by running `journal connect`

### Write Journal
Write a journal every day using `journal write` and answer a few questions.

### Demo

![Demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5qe9ss6lze48a2yz5ko.gif)

### Source Code
If you like it and want to know more, do check out the GitHub repo at 

{% embed https://github.com/mtwn105/journal-cli/ %}

If you like this tool, do support me by using the "Buy me a coffee" button, and keep reading my content by subscribing to newsletters. Till next time, peace.

### Buy me a coffee
[https://www.buymeacoffee.com/mtwn105](https://www.buymeacoffee.com/mtwn105)
How to Install Ubuntu 20.04 WL2 on Windows 11
Tags: ubuntu, wsl
Published: 2022-03-20 07:02:33


WSL allows us to run Ubuntu commands inside Windows without virtual machine etc.

**Follow below steps for installation**
 
1. Open Microsoft Store to install Ubuntu20 inside Windows11.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfmhlgf7x97cgeijqxyv.png)
2. Search for "Ubuntu". ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ek12gen3v7dh5af9qc1q.png)
3. Install Ubuntu 20.04.4 LTS(Or any version which you need). It will take a while to download and install.![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emnejwtgakpk7wbchua8.png)
4. After downloading and installing, open the terminal. This is the place where we will do most of our work.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojc5t1eayfy3eu7f80pc.png)
5. When you open the Ubuntu terminal first time, then it will ask you for the username and password. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngo8rz4mnsbmveu860gh.png)
6. Now you have a working Ubuntu operating system inside your Windows operating system.

> Here is more detailed article: [https://www.how2shout.com/how-to/how-to-install-ubuntu-20-04-wl2-on-windows-11.html](https://www.how2shout.com/how-to/how-to-install-ubuntu-20-04-wl2-on-windows-11.html)

Thanks
Simple Dictionary Program in GO
Tags: go
Published: 2022-03-20 07:02:13

Hello Friends, As a beginner in GO I have written a simple Dictionary program. This program uses Map to store word and meaning. This program also allows user to update, delete, search and list all words. Feel free to comment and let me know how can i improve this program. Thanks.

Please follow this link to see program.

[Dictionary Program](https://github.com/mithunkumarc/learning-golang/blob/master/examples/dictionary_program.go)
Angular Architecture for rest API
Published: 2022-03-20 06:52:21

Hello, I am working on a angular application and your Input would really be helpful.

My Scenarios is that I  Have a dashboard Page.  Which contains 3 Multi select filters and Date range filter.  The page also contains a table.

On Page load I call rest API and load data in filters and in the Table to show data on first load.  If i make any changes in the filter it should also trigger the change in table. Depending on what i set my filters I need to update my table.

My Structure:
Page (Parent)
-- Filters-
  - Multi select Drop down 
  - Date Range Filter
-- Table component

I have a data Service in which I have create update data in
private _data = new BehaviorSubject<object>({});
I subscribe to it in table component and pass data in table component.
I am not sure how do I re trigger the http service when filters are changed or updated. Any suggestion on how to achieve it.
Recipe Finder - CSS JavaScript
Tags: javascript, webdev, beginners, css
Published: 2022-03-20 06:40:37

Explained creating Recipe Finder application using html,css & JavaScript. 
API: https://developer.edamam.com/edamam-recipe-api

🍕🍕🍕🍕🍕🍕🍕
Timeline :
-----------------------------
00:00 Tease of application
00:52 Create Markup
03:00 Style using CSS
03:32 CSS variables
08:07 Calculate height using calc
08:40 Style Recipe element
13:02 API Details
15:14 Render Recipes dynamically JavaScript
15:40 Fetch API
18:38 Object Destructruing 
20:24 IntersetAdjacentHtml
24:00 Add Google Fonts
25:15 Search functionality
28:17 Set Scroll position
29:10 Loading image

{%youtube qS0n3j73ARQ%}
I made Wordle with a twist
Tags: wordle, wordgame, ionic, mobilegame
Published: 2022-03-20 06:02:20

## The Main Game

I kept hearing about this popular game called Wordle earlier in the year. A web game where you have to guess the word of the day in 6 tries. Safe to say a lot of people really love it. So much so, The New York Times decided to buy it from the solo developer that made it. Nice! Isn't that a developer's dream?

## The Idea

That is the dream. And what's even more crazy is that it's a simple game not only in terms of how it is played, but how easy it is to make it. I thought about how I could come with a simple and popular game as well. But then I realised, Wordle itself is not quite "original" per se. It is a word game like many others. So that's where I thought I could make something like Wordle but with a twist!

This game would be time based, can be played as much as the user wants and run as a mobile app. I did some research in the app stores and found that there were many games available that were exactly like Wordle. No particular twist other than being able to play without limit. So based on this, I decided to go ahead with my idea.

## Tech Stack

Since this game became popular, many templates and tutorials were done to model it. I wanted to get my idea out quickly, so I decided to make use of a template instead of making the game from scratch. It just saves time. Once I got my hand on a template made with pure HTML, CSS and JavaScript, I was able to focus my time on the planned twists.

I wanted it to be a mobile app, so I used Ionic which obviously is the best fit for my use case. All I had to do was copy over the files, add some extra logic in typescript and compiled my project to run for mobile devices.

After two weeks, my game was ready. Basically, how it works: The player gets 5 minutes to guess the 5 letter word in 6 tries. The faster the player guesses the word and with less tries, the more points they gain. Sounds fun? Well you can try it out for Android here: [Fast 5 Letters Word Game](https://play.google.com/store/apps/details?id=com.wimeki.fastletters)

Unfortunately, it is only out for Android. I could not get it out for iOS because Apple doesn't like copycats :)

_Follow me on Twitter [joey_the_dev](https://twitter.com/joey_the_dev)_
How to make Next.JS starter template.
Tags: nextjs, tailwindcss, react, javascript
Published: 2022-03-20 05:58:12



Who 🥱likes boilerplate code?
no one, we in our inner 🤯mind want to automate 🤖boring, repetitive task👷.
Like writing config files📂. install packages📦, and all.
if you want to automate your next.js setup you can start making your own template for Next.js.
That's too easy🙋.

Initially start you nextjs project and set it up,
install the package n' all which you would have in your template.

then after doing this stuff,
😺🐙GitHub comes to play▶️.
make a GitHub repo, write the name for the repo, remember that the name which you will set now will be used to make the clone so, set the name properly.

after setting the repo, push the code💪.

after doing this stuff. got to
the setting of specific repo and find ☑️template checkbox,
make sure you ✅ check that, after doing this.
now your repo is ready 👟to be used as a template. and nothing else.

```bash
npx create-next-app <githuburl> <appname>
```

🙌
you have to build your first template/

checkout 🙈 my template i have build Next.JS TailwindCSS+MongoDb+Typescript

![Next starter Screen Shot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5xaft936f4scvdymljw0.png)

✅ [`Next.js-TailwindCSS-MongoD Starter Template`](https://github.com/theabhayprajapati/Next.js-TailwindCSS-MongoDB-TS#simple-hack) 

🙌
Keep 🧑‍💻