teleren/devto huggingface dataset:
The Importance of Clean Code in JavaScript/TypeScript
Tags: webdev, javascript, programming, cleancode
Published: 2023-03-13 07:30:00

Writing clean code is an important aspect of software development, as it makes the code more maintainable, readable, and scalable. However, it is not uncommon to see code written in a way that does not follow the best practices of clean coding.

Here is an example of a code in JavaScript/TypeScript that contains **10** common mistakes that violate clean code principles:

```javascript
function x(a,b){
    var c=a+b;
    return c;
}
function y(x,z){
    return x*z;
}
function z(x,y){
    var p=x(y);
    return p;
}
```
The same code, rewritten with clean code principles in mind, would look like this:

```typescript
function addNumbers(a: number, b: number): number {
    const result = a + b;
    return result;
}
function multiplyNumbers(x: number, z: number): number {
    return x * z;
}
function processNumbers(processFunction: (num: number) => number, x: number): number {
    const result = processFunction(x);
    return result;
}
```
Here are the benefits of using clean code principles in the rewritten code:

1. **Improved readability**: The code is much easier to read, understand, and follow.

2. **Increased maintainability**: The code is more maintainable, as it is less prone to bugs and easier to update.

3. **Better organization**: The code is organized in a logical way, making it easier to navigate and maintain.

4. **Enhanced scalability**: The code is scalable, as it can easily be extended and integrated with other parts of the application.

5. **Better code reusability**: The code is reusable, as it can be used in other parts of the application without modification.

6. **Enhanced debugging**: The code is easier to debug, as errors and bugs can be easily traced and fixed.

7. **Improved performance**: The code is more performant, as it is optimized for efficiency.

8. **Better collaboration**: The code is easier to collaborate on, as multiple developers can understand and work with it more easily.

9. **Improved documentation**: The code is easier to document, as it is clear and self-explanatory.

10. **Better overall quality**: The code is of higher quality, as it adheres to best practices and standards.

And that's it ! See U next level Doobs !
Working with Databases -Configuring Remote Connection
Tags: opengauss, database
Published: 2023-03-13 07:06:55

Before the remote connection, you need to enable the client to access the database and configure the remote connection on the server where the database primary node is deployed.

**Procedure**

Perform the following steps on the host where openGauss resides.

1. Log in as the OS user omm to the primary node of the database.

2. Configure the client authentication mode. For details, see Configuring Client Access Authentication.

3. Configure listen_addresses. listen_addresses indicates the IP address or host name of the database primary node used for remote client connection.

3.1 Run the following command to check the listen_addresses value of the primary database node:

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

Information similar to the following is displayed:

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

3.2 Run the following command to append the IP addresses to be added to listen_addresses. Use commas (,) to separate multiple IP addresses. For example, add the IP address 10.11.12.13.

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

4. Configure pg_hba.conf and add the IP address of the primary database node and the IP address of the client. For details about the parameters in pg_hba.conf, see Configuring Client Access Authentication.

4.1 Run the following command to add the IP address of the primary database node to pg_hba.conf. In the command, initial_user indicates the initial user name of the database, and 10.11.12.13 is the IP address of the host where the database resides.

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

4.2 Run the following command to add the IP address of the client to pg_hba.conf. If the IP address is 10.11.12.34, the authentication mode is SHA-256.

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

5. Run the following command to restart openGauss:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwzvubzuelkmvkfe6bd2.png)
How to use VSCode for coding on Unity
Published: 2023-03-12 04:18:06

TL;DR
- Install C# Plugin for VS Code
- Install .NET Core and .NET Framework
- Generate project files (.csproj) by Unity preference menu

# Background & Overview
Always I start using new PC, I get stuck with setting up VSCode for Unity programming. This is a quick note for people who are willing to set up VS Code for Unity. In the following sections, I explain how to enable intellisense on VSCode. Please note that I do not explain how to set up debugging (inserting breakpoint etc.).

# Prerequisite
I assume that you have Unity and VSCode on your PC. I'm using Unity 2021 now but the steps may not change event for different Unity versions.

# Step 1: Install C# VS Code plugin. 
In your extensions search on VS Code or you can find the plugin on [this page](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp).

# Step 2: Install .NET Core / .NET Framework
At this moment, we can download the SDK from on [this page](https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=msbuild-developerpacks
). The URL may change in the future.
I installed `.NET Core 7`. We need `.NET Framework 4.7.1` for that core. I installed `.NET Framework 4.8.1` first but it did not work and error messages told me I need `ver 4.7.1`. You may use another version of .NET Core, 

# Step 3: Generate C# project files.
On Unity editor, go to preference of editor `[Edit] --> [Preferences] --> [External Tools]`. Set `External Script Editor` as `Visual Studio Code`, check all checkboxes in `Generate .csproj files for:` section and then click `Regenerate project files` button.

# Wrap-up
That's it! Hope this make your life easier.
What Are the Best Time Management Tools for Coders & Developers?
Tags: discuss, beginners, codenewbie
Published: 2023-03-13 07:00:00

It’s Monday! And what better day of the week to talk about time management? There are a ton of time management tools out there — some general, and some more specific to the needs of coders and developers. 

There's the good ol’ Pomodoro Technique, a time management method that involves breaking work into 25-minute intervals that are separated by quick breaks. But there are also so many time-tracking and task management apps, project management software, calendar apps, and note-taking tools. Not to mention code editors like Visual Studio Code and Sublime Text.

Using these tools (the ***right*** tools for you…and ***if*** you use them) can help you manage your time more effectively and be more productive as a coder or developer. Which do you use? 

Which tools and technique do you use? And what would you suggest for newbies who are just getting started and need a way to stay focused?
Transform objects using array methods
Tags: javascript, tutorial
Published: 2023-03-13 06:56:54

Array methods are widely known and used by every JS developer. They are used on daily basis and their usage is really intuitive. Things are getting much worse when it comes to do similar operations with objects. Javascript objects are complex structures and they don't have corresponding methods for those from arrays.

### Object.keys(obj)

Returns array of object keys

```jsx
const job = {
    level: "senior",
    salary: 15000
};

Object.keys(job); // [ 'level', 'salary' ]
```

How to check if an object is empty?

```jsx
const isObjectEmpty = Object.keys(job).length === 0;

const emptyObj = {};
const nonEmptyObj = {level: "senior"};

Object.keys(emptyObj).length === 0; // true
Object.keys(nonEmptyObj).length === 0; // false
```

### Object.values(obj)

Returns array of object's values

```jsx
const job = {
	level: "senior",
	salary: 15000
};

Object.values(job); // [[ 'senior', 15000 ]
```

How to sum values of object's entries

```jsx
const shoppingList = {
	"🫐": 9.00,
	"🍓": 4.50,
	"🍋": 2.90
}

const prices = Object.values(shoppingList); // [ 9, 4.5, 2.9 ]

const total = prices.reduce((sum, price) => sum + price); // 16.4
```

### Object.entries(obj)

Returns array of pairs `[key, value]`

```jsx
const job = {
	level: "senior",
	salary: 15000
};

Object.entries(job); // [ [ 'level', 'senior' ], [ 'salary', 15000 ] ]
```

Iterating through an object

```jsx
const shoppingList = {
	"🫐": 9.00,
	"🍓": 4.50,
	"🍋": 2.90
}

Object
    .entries(shoppingList)
    .forEach(([key, value]) => console.log(`${key}: ${value}`))
    // '🫐: 9', '🍓: 4.5', '🍋: 2.9'
```

How to check if the price is greater than 5?

```jsx
for (const [fruit, price] of Object.entries(shoppingList)) {
  if (price > 5) {
    console.log(fruit); // '🫐'
  }
}
```

### .map for objects

Objects don't have corresponding methods for `array.map` or `array.filter`. Fortunately we can achieve the same result using other methods:

- `Object.entries(obj)` to get key-value pairs,
- use needed array method,
- transforming array back to the object using `Object.fromEntries(arr)`

```jsx
const shoppingList = {
	"🫐": 9.00,
	"🍓": 4.50,
	"🍋": 2.90
}

const doublePrices = Object.fromEntries(
  Object
    .entries(shoppingList)
    .map(([key, value]) => [key, value * 2])
);

console.log(doublePrices) // { '🫐': 18, '🍓': 9, '🍋': 5.8 }
```

### Summary

Using these object methods solves many problems with an object manipulation. We obtain the ease of working with arrays but with much more complex data structures.
The Power of Debugging: How to Become a Better Developer
Published: 2023-03-13 06:53:26

As a developer, debugging is an essential skill that can make the difference between a mediocre product and a great one. In this post, we'll explore the power of debugging and how it can help you become a better developer.

First, let's define what debugging is. Debugging is the process of finding and fixing errors, or bugs, in your code. It involves analyzing your code, identifying problems, and correcting them. Debugging can be a time-consuming process, but it's an essential part of software development.

Here are some tips to help you become a better debugger:

Start with the basics: Before you start debugging, make sure you understand the basics of your code. Understand the logic behind it, what it's supposed to do, and how it's supposed to do it. This will help you identify the cause of the problem more quickly.
Use a debugger tool: A debugger tool can be a developer's best friend. It allows you to step through your code line by line, set breakpoints, and examine variables and data structures. Debugging tools can help you pinpoint the exact location of a problem, making it easier to fix.
Use logging: Logging is another powerful tool for debugging. By logging the state of your program at different points, you can track the flow of data and identify where problems are occurring. Logging can also help you reproduce bugs, which is essential for fixing them.
Don't rely on assumptions: When debugging, it's easy to make assumptions about what's causing the problem. However, these assumptions can be wrong, leading you down the wrong path. Instead, rely on data and evidence to guide your debugging efforts.
Collaborate with others: Debugging can be a collaborative effort. If you're stuck on a problem, don't be afraid to ask for help. Sometimes, a fresh pair of eyes can spot something you missed.
By following these tips, you can become a better debugger and, ultimately, a better developer. Debugging is an essential part of software development, and mastering it can make all the difference in the quality of your code. So next time you're faced with a bug, don't be intimidated. Embrace the challenge and use it as an opportunity to grow your skills.
JS features to master
Published: 2023-03-13 06:42:15

```javascript
/* 
- map()
- filter()
- reduce()
- some() / every()
- find() / findIndex()
- forEach()

Plus:

- slice()
- concat()
- includes()
- array spread operator
*/

const numbers = [1, 2, 3, 4, 5];
// instead of this
for (let i = 0; i < numbers.length; i++) {
  console.log(numbers[i]);
}
//  use this
numbers.forEach(number => {
  console.log(number);  
});

```
How 'this' keyword's value is determined in Javascript
Tags: webdev, javascript, beginners, react
Published: 2023-03-13 06:39:15

In JavaScript, the **this** keyword refers to the current execution context. In other words, it represents the object that the currently executing code belongs to.

The value of **this** is determined based on how a function is called, and can have different values depending on the context in which it is used.

Here are some general rules for determining the value of **this**:

1. If a function is called as a method of an object, **this** refers to the object itself.

For example:

```javascript
const myObj = {
  name: "John",
  greet: function() {
    console.log("Hello, " + this.name + "!");
  }
};

myObj.greet(); // Output: "Hello, John!"
```
In this example, when the **greet()** method is called on **myObj**, **this** refers to **myObj**, so this.name returns the value of the **name** property of **myObj**.

2. If a function is called as a standalone function, **this** refers to the global object (in the browser, this is typically the **window** object).

For example:

```javascript
function sayHello() {
  console.log("Hello, " + this.name + "!");
}

sayHello(); // Output: "Hello, undefined!"
```
In this example, this refers to the global object, so **this.name** returns **undefined**.

3. If a function is called using the **new** keyword, **this** refers to the newly created object.

For example:

```javascript
function Person(name, age) {
  this.name = name;
  this.age = age;
}

const john = new Person("John", 30);
console.log(john.name); // Output: "John"
```
In this example, **this** refers to the newly created object **john**, so **this.name** and **this.age** set the properties of **john**.

4. If a function is called using **call()** or **apply()**, **this** refers to the object passed as the first argument.

For example:

```javascript
const person1 = {
  name: "John",
  age: 30
};

const person2 = {
  name: "Jane",
  age: 25
};

function greet() {
  console.log("Hello, " + this.name + "!");
}

greet.call(person1); // Output: "Hello, John!"
greet.apply(person2); // Output: "Hello, Jane!"
```
In these examples, **this** refers to **person1** when **greet()** is called using **call()**, and **person2** when it is called using  **apply()**, so **this.name** returns the value of the name property of the respective objects.

These are just a few examples of how the value of **this** is determined in JavaScript.
Animation -2 : Pure CSS 1 elem moon loader
Tags: css, design, animation, webdev
Published: 2023-03-13 06:33:00

Are you looking for animations to enhance your website? We've got you covered with our wide selection of creative and engaging #animations. Say goodbye to endless searching and hello to seamless integration on your website!

#### We're excited to introduce our latest YouTube series, which features diverse creative and inspiring website animations.

---

In our short videos, you'll find a variety of #animations that can be easily implemented on your website to enhance user experience.


---

### Pure CSS 1 elem moon loader

---

{% youtube msynswTdugo %}

 ---
### [Source code](https://codepen.io/thebabydino/pen/GRqKwqX)


---
## For more information

1. Check my GitHub profile
[https://github.com/amitSharma7741](https://github.com/amitSharma7741)

2. Check out my Fiver profile if you need any freelancing work
[https://www.fiverr.com/amit_sharma77](https://www.fiverr.com/amit_sharma77)

3. Check out my Instagram
[https://www.instagram.com/fromgoodthings/](https://www.instagram.com/fromgoodthings/)

4. Linktree
[https://linktr.ee/jonSnow77](https://linktr.ee/jonSnow77)

5. Check my project

- EVSTART: Electric Vehicle is the Future
[https://evstart.netlify.app/](https://evstart.netlify.app/)
-  News Website in react
 [https://newsmon.netlify.app/](https://newsmon.netlify.app/)
-  Hindi jokes API
 [https://hindi-jokes-api.onrender.com/](https://hindi-jokes-api.onrender.com/)
- Sudoku Game And API
[https://sudoku-game-and-api.netlify.app/](https://sudoku-game-and-api.netlify.app/)

---
---
Using .set to get get unique values in an array
Published: 2023-03-13 06:29:26

```javascript
const customerDishes = [
  "Chicken Wings",
  "Fish Sandwich",
  "Beef Stroganoff",
  "Grilled Cheese",
  "Blue Cheese Salad",
  "Chicken Wings",
  "Reuben Sandwich",
  "Grilled Cheese",
  "Fish Sandwich",
  "Chicken Pot Pie",
  "Fish Sandwich",
  "Beef Stroganoff"
];

const uniqueDishes = [...new Set(customerDishes)];
console.log(uniqueDishes)

// const numbers = new Set([[1], [2], [3]]);

// for (const num of numbers) {
//   console.log(num);  
// }
```
When you put the values in the .set array in [] to form an object, the .set method can't recognize this as unique anymore (as in above comment)
AI Future
Published: 2023-03-13 06:27:39

# The Future of AI and Chat GPT

Artificial Intelligence (AI) has come a long way in recent years, and the future of AI promises to be even more exciting. In this article, we'll explore some potential developments in AI, including the role of conversational AI with Chat GPT.

## Advancements in Machine Learning

Machine learning is the backbone of AI, and it's what enables computers to learn from data without being explicitly programmed. One of the most significant advancements in machine learning is the development of deep learning algorithms. These algorithms allow computers to learn from vast amounts of data, making machine learning models more accurate and powerful.

## Conversational AI and Chat GPT

Conversational AI refers to the use of AI in natural language conversations. One of the most exciting developments in conversational AI is the creation of chatbots that can carry out natural language conversations with humans. Chat GPT (Generative Pre-trained Transformer) is an advanced form of AI that can generate human-like text. Chat GPT uses machine learning algorithms to learn from vast amounts of data, including text from the internet, books, and other sources.

## The Future of Conversational AI

In the coming years, we can expect conversational AI to become even more sophisticated. Chat GPT and other conversational AI systems will become better at understanding human language and carrying out natural language conversations. This could have a significant impact on industries such as customer service, where chatbots could provide fast and efficient customer support.

## AI and Healthcare

AI also has the potential to revolutionize healthcare. Machine learning algorithms can be used to analyze vast amounts of medical data, helping doctors to make more accurate diagnoses and develop more effective treatment plans. Additionally, AI-powered robots can perform surgeries with greater precision, and virtual nurses can provide round-the-clock care for patients.

## Ethical Concerns

As with any transformative technology, there are ethical considerations that need to be addressed. One concern is the potential impact of AI on jobs, as automation becomes more prevalent. Additionally, there are concerns about privacy and data security, as AI relies on vast amounts of personal data to function.

## Conclusion

The future of AI is incredibly exciting, and conversational AI with Chat GPT is just one of the many promising developments on the horizon. As we move forward, it's essential to balance the benefits of AI with the potential risks and ensure that this technology is used for the betterment of humanity.
Is there a way to reslove the build issue while deploying server(nodejs and mongodb) application to heroku
Published: 2023-03-13 05:12:39

{% stackoverflow 75718199 %}

Here it's index.js
<!-- language: lang-js -->

    // index.js (server)
    const express = require('express')
    const bodyParser = require('body-parser')
    const cors = require('cors')
    const app = express()
    const path = require('path')
    const apiPort = 3001
    const userRouter = require('./route/user')
    const recipesRouter = require('./route/recipes')
    require('dotenv').config()

    const mongoose = require('mongoose')
    const db = mongoose.connection

    mongoose.connect("mongodb+srv://venkat:<>@recipecluster1.txqo0vw.mongodb.net/recipes?retryWrites=true&w=majority")

    app.use(bodyParser.urlencoded({ extended: true }))
    app.use(cors())
    app.use(bodyParser.json())
    app.use("/auth", userRouter)
    app.use("/recipes", recipesRouter)

    // app.use(express.static(path.join(__dirname, "../../client/build")))

    // app.get("*", (res, req) => {
    //     res.sendFile(path.join(__dirname, "../../client/build/index.html"))
    // })

    app.get('/', (req, res) => {
        res.send('Server Started!')
    })

    //app.listen(apiPort, () => console.log(`Server running on port ${apiPort}`))

    app.listen(process.env.PORT || 3001, () => {
        console.log("Server running on port")
    })

<!-- end snippet -->
Empowering Your Ruby Projects with the “openai_chatgpt” gem
Tags: openai, chatgpt, ruby, rails
Published: 2023-03-13 05:00:00

As developers, we constantly seek ways to improve and enhance our projects. That's why I'm thrilled to introduce you to `openai_chatgpt`, a new Ruby gem enabling you to leverage GPT-3.5 Turbo and GPT-3.5 Turbo-0301 in your Ruby projects.

GPT-3.5 Turbo and GPT-3.5 Turbo-0301 are OpenAI's latest language models, capable of producing human-like text with remarkable accuracy. Integrating these models into your Ruby projects can elevate your applications, delivering an unparalleled user experience.

Designed with simplicity, `openai_chatgpt` is easy to use and integrate into your Ruby projects. It provides a straightforward interface for generating text, allowing you to concentrate on building your application without the complexities of GPT-3.5 Turbo and GPT-3.5 Turbo-0301.

To start with `openai_chatgpt`, install the gem and authenticate your OpenAI API key. Once you've completed these steps, you can generate text by invoking the ‘completions’ method and providing the prompt you want the model to complete.

The complete documentation of the gem can be found at: [https://github.com/sulmanweb/openai\_chatgpt](https://github.com/sulmanweb/openai_chatgpt)

For instance, here's a simple example of using `openai_chatgpt` in Ruby:

```ruby
require 'openai_chatgpt'
client = OpenaiChatgpt::Client.new(api_key: "your-api-key")
resp = client.completions(messages: [{role: "user", content: "Hello World"}])
p resp.results[0].content
```

This gem enables all options available in OpenAI's official chatgpt documentation. The gem returns excellent OpenStruct results that can be accessed using simple dot notation.

Furthermore, the gem includes a `usage` object that details your API token usage after each call.

Please don't hesitate to submit PRs and issues to the open-source gem.

---- 

Happy Coding!
You can contact me at [sulman@hey.com](mailto:sulman@hey.com)
Thiết kế thi công đài phun nước
Tags: tdvfountain, beginners, productivity, discuss
Published: 2023-03-13 04:55:59

Thiết kế thi công [đài phun nước](https://tdvfountain.com/dai-phun-nuoc/). Lập trình [nhạc nước](https://tdvfountain.com/thiet-ke-thi-cong-nhac-nuoc/)