teleren/devto huggingface dataset:
Hey Mongo!!
Tags: beginners, mongodb, tutorial, opensource
Published: 2021-10-18 06:02:38

MongoDB is an open-source document-oriented database. Here data is stored in a document within a collection as a set of name-value pairs. It does not have a fixed structure defined at the collection level. As data is stored across multiple machines, it is horizontally scalable. It has rich query language that supports CRUD operations, aggregation, text search, and so on.


The basic building blocks are:
1. Database: It contains all the data generated by the system as collections.
2. Collection (Similar to Table in RDBMS): It single entity that contains all the data related to a particular aspect.
3. Document (Similar to rows in RDBMS):  Set of fields with associated values of corresponding datatypes.



##### CRUD Operations


###### Creating Database
use db_name is used to create the database. The command will create a new database if it doesn't exist, otherwise, it will return the existing database.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ljkndk2w35ajz8j5i1j.png)


###### Creating Collection
db.createCollection(name) command is used to create collection.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utnmhka13p00t7pjitku.png)


###### Insert Operation
To insert data into MongoDB collection, you need to use MongoDB's insert() or save() method, db.CollectionName.insert(document)

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ia8o60bdyft3r0s42m37.png)
 

###### Read Operation
find() method will display all the documents in a non-structured way, db.CollectionName.find()
To display the results in a formatted way, you can use pretty() method, db.CollectionName.find().pretty()

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ctilmwa5rry8w4f2t2ib.png)

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gfjv8nyjqnnyae679v0.png)


###### RDBMS Where clause equivalents 
To query the document on the basis of some conditions, you can use the following operations.
Equality - {key:{$eq:value}}
Not Equal - {key:{$ne:value}}
Less than - {key:{$lt:value}} 
Less than Equals - {key:{$lte:value}}
Greater than - {key:{$gt:value}} 
Greater than Equals - {key:{$gte:value}}

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg8s322fywkhqemonihn.png)
 

###### Update Operation
The update() method updates the values in the existing document while the save() method replaces the existing document with the document passed in the save() method.
db.CollectionName.update(selection_criteria, updated_data)

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61vmdmo39eqbvr9692vg.png)
 

###### Delete Operation 
MongoDB's remove() method is used to remove a document from the collection.
db.CollectionName.remove(deletion_criteria)

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xmpib2pp9hod9wharkx.png)
 


Thank you!! Feel free to comment on any type of feedback or error you have 😄✌
What is the Python priority queue?
Tags: python, priorityqueue, datastructure, heap
Published: 2021-10-18 05:53:24

The priority queue is an advanced type of the queue data structure. Instead of dequeuing the oldest element, a priority queue sorts and dequeues elements based on their priorities.

Priority queues are used to handle scheduling problems where some tasks are prioritized over others.

The queue.PriorityQueue Class
Python provides a built-in implementation of the priority queue data structure.

Since the queue.PriorityQueue class needs to maintain the order of its elements, a sorting mechanism is required every time a new element is enqueued.

Python solves this by using a binary heap to implement the priority queue.

The Python priority queue is built on the heapq module, which is basically a binary heap.

For insertion, the priority queue uses the put function in the following way:
  pQueue.put(value)

The get command dequeues the highest priority elements from the queue.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzcbe0ikrtlrz285apl0.png)

Priority-object pairs can also be inserted into the queue. This way every task can be associated with a priority.

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

Time Complexity

Operation:                        Work-case Time complexity:
Insertion                         O(logn)
Deletion                          O(logn)
How to launch an EC2 Instance with Terraform
Tags: terraform, aws
Published: 2021-10-18 05:32:10

---
title: How to launch an EC2 Instance with Terraform
published: true
description: Launching an ec2 instance in AWS using terraform
tags: terraform,aws
canonical_url: https://citizix.com/how-to-use-terraform-to-launch-an-aws-ec2-instance/
//cover_image: https://direct_url_to_image.jpg
---

Terraform is an open-source infrastructure as code software tool created by HashiCorp. To use terraform, you define the resources you want to create using a declarative configuration language created by Hashicorp known as HashiCorp Configuration Language (HCL), or optionally JSON.

AWS is a popular cloud provider similar to Azure and GCP.


In this guide, we will see how to:
- Define a provider
- Define Terraform Version to use
- Define variables
- Create a Key Pair
- Create an EC2 instance
- Define a Security Group
- Define outputs

Checkout the full guide [here](https://citizix.com/how-to-use-terraform-to-launch-an-aws-ec2-instance/)
AI-powered text2speech.dev
Tags: text2speech, ai, cloud, machinelearning
Published: 2021-10-18 05:19:57

I always wonder if there would be a simple app which could simplify text-to-speech and convert bunch of stories, text, podcasts and audios to speech. I found some websites which could help you do just that:

First on the list is: 
[text2speech.dev](https://text2speech.dev/)

I find text2speech.dev to be really nice as they allow to Try out live demo without logging in, or login to enjoy all SSML (Speech Synthesis Markup Language) features. SSML IS XML-based marketup language, more info here https://en.wikipedia.org/wiki/Speech_Synthesis_Markup_Language

Of course, other alternatives are also good

[voicemaker.in](https://voicemaker.in/)
[text2speech.org](https://www.text2speech.org/)
[text2speech.us](https://text2speech.us/)
[ttsreader.com](https://ttsreader.com/)

I hope you found this post useful and feel free to try text2speech if you are in need for online converters.
API automation using Python and open-source framework
Tags: softwaretestingcompany
Published: 2021-10-18 04:27:47

python-project.html

Writing test case
As now you already have setup your python project with Pycharm, let’s create a new python file where we will add our test cases.

Please create a new python file in your project. Let’s name it “test_apitest.py”. Notice the “test_” in your file name. This is as per the rules for PyTest. We will be running our tests using Python’s inbuilt testing framework called PyTest. PyTest picks all those python files in your project which start with “test_” for test execution.

In “test_apitest.py” file, our first statement would be :

import requests
“requests” is python’s inbuilt module which is used to send http requests to a server. We will be using this module to send requests to our API and record the response.

Now, for this tutorial we will be using a sample test API available online : https://reqres.in/api
We will be sending requests to the endpoints defined in this API.

Read more on
https://www.fleekitsolutions.com/api-automation-using-python/
Continuous pointerdown event does'nt work in iOS15 Google Chrome and Safari
Tags: codepen, javascript, ios15, safari
Published: 2021-10-18 04:25:24

---
title: Continuous pointerdown event does'nt work in iOS15 Google Chrome and Safari
published: true
tags: codepen, javascript, iOS15, safari
---

Continuous pointerdown event responded to all tap.
But the second time is not reacted when tap in iOS15.

{% codepen https://codepen.io/akicho8/pen/BadKQyZ %}
Simple Hello World Program in Javascript
Tags: javascript, beginners, webdev, programming
Published: 2021-10-18 04:22:54

Hello world!!

This would be a very basic tutorial on how to write your very first javascript program. 

This tutorial is geared towards beginners and anyone who ones to start learning Javascript. 

Now, to keep things really simple, we're not going to be installing any code editor or IDEs.

All you need for this to work is your good old web browser.

Let's begin..

### *Step 1:*  
Open your preferred browser.
### *Step 2:*
Press either CTRL + SHIFT + I or F12 to open the Developer Tools.
### *Step 3:*
Click on the console tab to enter into the developer console.
### *Step 4:*
Write the following code in the developer's console.

    console.log("Hello World");
Then press Enter.

Congratulations! You have written your very first javascript program.

Now, to have a little fun, you can try out other variations of this code like:

    console.log(6 + 4);

or

    console.log("Programming is hard but really fun");

or

    alert("hello world");

or

    alert(6 + 6);

You get the idea. Happy coding!!
Simplest way to compare two numbers array in JS
Tags: javascript, webdev, beginners, programming
Published: 2021-10-18 04:12:10

In case of string we can simply use **==** or **===** to see if they are same but we can't use those to see in two arrays are similar or in other words they have same elements.
So this wont work.
```js
const array1 = [1, 2, 3, 4, 5]
const array2 = [1, 2, 3, 4, 5]
console.log(array1 == array2) //false
```
But what if we convert our array to string? Then you can use the comparison operator. This makes the task very easy. We can sort an array using **toString** method eg. `array1.toString()` or we can use this hack
```js
console.log([1, 2, 3, 4, 5] + "")
//logs 1,2,3,4,5
console.log(typeof ([1, 2, 3, 4, 5] + ""))
//logs string
```
So basically if we try to concatenate string(empty string in this case) to an array the array will be converted to a string.
so now we can simply use the arrays as strings and compare them
```js
const array1 = [1, 2, 3, 4, 5]
const array2 = [1, 2, 3, 4, 5]
console.log(array1 + "" == array2 + "") //true
```

Also if you want it to work with arrays where the elements are not in order you can first sort them. Let's create a utility function for that
```js
function compareArr(arr1, arr2){
    arr1.sort()
    arr2.sort()
    return arr1 + "" == arr2 + ""
}
const array1 = [1, 2, 3, 4, 5]
const array2 = [1, 5, 2, 4, 3]
console.log(compareArr(array1, array2)) // returns true
```
Divtober Day 17: Stack
Tags: codepen, divtober, css, art
Published: 2021-10-18 03:59:59

---
title: Divtober Day 17: Stack
description: A haystack.
published: true
tags: codepen,divtober,css,art
series: divtober
---

Divtober's 17th word is "stack". I didn't have many ideas today, so I just did a haystack:

{% codepen https://codepen.io/alvaromontoro/pen/LYjNREg %}

I tried to do something fancier (and likely a no-no for divtober): having a custom cursor in SVG –just an empty SVG tag with styles– with a `backdrop-filter`. The idea was to have a needle with not much contrast and show it when hovering over... but it didn't work.
Execution Context✨
Tags: code, javascript
Published: 2021-10-18 03:23:04

✏ In JavaScript, Execution Context is like a container. And it has 
   two components.
✏ They are, memory component or variable environment and code 
   component or thread of execution.
✏ In variable environment or memory component, it contains 
   variables, functions, and key-value pairs.
✏ But In thread of execution, it's a place where code is executed 
   at one line at a time. Because, JavaScript is a synchronous 
   single-threaded language i.e. JavaScript can only execute one 
   command at a time and in a specific order. It only go to the 
   next line once the current line has been finished execution.
Muting Noisy XHR Logs in Cypress
Tags: testing, javascript, cypress, testdev
Published: 2021-10-18 03:03:29

(This guide has been updated multiple times, especially since the release of Cypress 10)

For a while now, our Cypress runner has been quite noisy, generating lots of XHR requests in the log as our tests run. A bug was introduced into Cypress in the last few versions that has made it quite difficult to mute these. Fortunately, I found a solution that [Simen Brekken](https://github.com/simenbrekken) helpfully posted [here](https://gist.github.com/simenbrekken-visma/e804c86fd6a23cc59b89913eabbf1d82) and I felt like I'd share it with the Dev audience in case it was helpful to someone else.

For the fix, we add a flag to our `cypress.config.ts` to allow us to enable or disable rich logging as needed.
```typescript
e2e: {
  hideXHRInCommandLog: true
}
```
In our `/cypress/support/e2e.ts` file, we have:
```typescript
// Hide fetch/XHR requests from command log
if (Cypress.config("hideXHRInCommandLog")) {
  const app = window.top;

  if (
    app &&
    !app.document.head.querySelector("[data-hide-command-log-request]")
  ) {
    const style = app.document.createElement("style");
    style.innerHTML =
      ".command-name-request, .command-name-xhr { display: none }";
    style.setAttribute("data-hide-command-log-request", "");

    app.document.head.appendChild(style);
  }
}
```

And then lastly, in `/support/cypress.d.ts`, we add:
```typescript
declare namespace Cypress {
  interface ResolvedConfigOptions {
    hideXHRInCommandLog?: boolean;
  }
}
```

This solution uses CSS to prevent the XHR requests from being picked up in the DOM and thereby reported to the Cypress runner. It's not the most elegant solution, but it'll work for now until we get a better fix from Cypress. Thanks, Simen!
Tunnel services that support access Grpc Server (HTTP/2)
Tags: csharp
Published: 2021-10-18 03:02:55

I am looking for a tunnel service that allow client to access a Grpc Server via Http/2 protocol. I need to host a C# .NET Grpc Server on my Raspberry Pi, the app will communicate with Raspberry Pi's GPIO pins. And the Grpc Client - an ASP.NET Core API is hosted on Azure App Services. Can you give me a suggestion?
Understanding Constructor Functions in JavaScript 
Published: 2021-10-18 03:00:32

#**What is a constructor ?**

In Javascript, a **constructor** is a special function which creates an instance of a class which is typically called an "object". They are technically regular functions, but What makes them special is that they are always invoked with a powerful operator in JavaScript called the **new** operator. Constructors provide the means to create as many objects as needed, whilst attaching properties and behaviors to them as required. As convention, the constructor function name usually starts with a capital letter, to be easily recognizable in code. 

##**What happens when a constructor gets called ?**

###When a Constructor is invoked:
   * A new empty object is created. 
   * The Javascript keyword  **this**  starts to refer to the newly created object.
   * The value of the newly created object **this** is then returned.

##**Example**##

here is an example of a Bird constructor, which will allow us to create new objects:
     
         function Bird() {
           this.name = "Tweety";
           this.color = "blue";
         }      

      let blueBird = new Bird();
      

   
**this** `inside the constructor always refers to the object being created.`

When calling a constructor, the **new** operator is used to   tell Javascript to create a new instance of the Bird constructor that is called blueBird. `Note that the constructor function is not changed, the newly created new context is changed!` Without the new operator, **this** inside the constructor would not point to the newly created object, giving unexpected results. when a constructor is invoked without the new operator it is invoked as a regular JavaScript function. 

##**Summary**##

Note the main purpose of constructors are to implement reusable object creation code. 

* Constructor functions are regular functions but with a common agreement to defined them with the first letter capitalized.

* Constructors use the keyword **this** to set properties of the object they will create. 

* Constructor functions can be used to create multiple similar objects.

Thank you for reading this article, I hope you found it useful. Happy Coding 😀
Mocking classes in Jest / Typescript
Tags: typescript, jest, tutorial, mock
Published: 2021-10-18 02:09:27

_Cross posted on my website [mitchinson.dev](https://mitchinson.dev/jest-typescript-mocks)_

### TL;DR

[Example Test](https://github.com/bmitchinson/ts-node-starter/blob/main/src/GetANumber.test.ts)

GetANumber.test.ts mocks a class, and further customizes a class method on that mocked class for a single test.

### Purpose

It was surprisingly hard to find a recently written article about the fastest way to setup Jest with some simple class mocks in Typescript. The following example demonstrates mocking a class and modifying methods of that mocked class within a single test.

Libraries like jest-ts-auto-mock are not used, cause I was unable to find a way to get them to work. Could have just been using them wrong but who knows.

I used the following methods to mock classes in an Express app while coding in test driven development.

### Explanation

Comments are all over in this [Example Repo] (https://github.com/bmitchinson/ts-node-starter), but some highlights are:

- `jest.mock` ends up at the top of the file when it's transpiled.
  - Even if you put it under other things, it gets pulled to the top.

```typescript
///////////////////
jest.mock("./Class", mockOne);

it("does a thing", () => {
  expect(class).toBe(one)
})

it("does another thing", () => {
  jest.mock("./Class", mockTwo);
  expect(class).toBe(two)
})
///////////////////

// is really

///////////////////
jest.mock("./Class", mockOne); // this mock is useless
jest.mock("./Class", mockTwo); // as it's immediately replaced

it("does a thing", () => {
  expect(class).toBe(one)
})

it("does another thing", () => {
  expect(class).toBe(two)
})
///////////////////

// You might as well always write `.mock` calls at the top of your file.
```

- The example mocks a class that's a default export. Named exports can also be mocked by nesting the class mockImplementation one layer deeper.
- `jest.mock('{path_to_custom_class}')` will replace that paths default export in the runtime with the defined mock in `__mocks__` dir defined at the same level.
- If you'd like to modify a mock / assert things that happened to a mock, you need to import them from the "real" class.
  - Never manually import from `__mocks__`, get the exports of `__mocks__` "through" a normal import.

```typescript
import * as MockNumberGen from "./__mocks__/NumberGen";
import * as NumberGen from "./NumberGen"; // __mocks__/CVEPathData

// Give me the mock class i've defined in __mocks__/{classname} and let me
//    name it mock{ClassName}Constructor
// Give me the mock function i've defined in __mocks__/{classname}
const { default: mockNumberGenConstructor, mockGetOne } =
  // Get these things from the NumberGen class, because I know that jest
  //     has secretly replaced it with the contents of MockNumberGen
  NumberGen as unknown as typeof MockNumberGen;
// Tell typescript that these things are really coming from MockNumberGen,
//     so it should type them as such
```

The full test is [available here](https://github.com/bmitchinson/ts-node-starter/blob/main/src/GetANumber.test.ts)
JavaScript tutorial - Explaining Array.prototype.sort()
Published: 2021-10-18 02:08:11

So what is Array.prototype.sort()? As the name suggests, we are using an array and we'll be sorting it. There are also other neat functionalies like converting elements into strings. But for this example, we'll be taking a look on how we can rank our array from the greatest to least.

Let's start with an array. Let's use a simple number integers. For this example we'll use an array of numbers that we want to sort.

`Generating numbers...`

```
let nums = [7, 41, 48, 9, 11, 12]
```

Okay we have our arrary. The next step is to define a variable. Let's name it sortedNums.

```
let sortedNums
```

The next step would be adding a `spread operator.` This neat syntax will allow us to add a copy so that we are able to compare them when we're done.

> A spread operator in this example, creates a new array, then extracts all the elements we need from the original array, then plugs it in inside the new one. Essentially cloning the array.

```
let sortedNums = [...nums]
```

Next we'll have to add a `callback function`, so it understands what the logic we want going on. We also need to define two parameters as it requires. So lets name the parameters as A and B.

```
sortedNums.sort((a, b => {})
```

Inside the empty brackets, it'll spit out three posible things. `A positive number, negative number, and a zero.`

> Positive and neagive numbers will each sort very differely. Pos numbers may sort from greatest to least and vice versa. Howevever, if it spits out zero, then no changes were made!

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

And now onto how it computes the results. If you take a look at the crude diagram, `theres a recurring pattern.` It's shifting those pairs for comparison one index position at a time on each iteration of the loop.

Don't forget to add `console.log(sortedNums)` at the end to get results.
```
'use strict'

let nums = [7, 41, 48, 9, 11, 12]
let sortedNums = [...nums]
sortedNums.sort((a, b => b - a)
console.log(sortedNums)
console.log(nums)
```
```
node sort.js
[ 48, 41, 12, 11, 9, 7]
```

The end result should look something like this.

<h2> Conclusion <h2>

The logic in this tutorial is very rudimentary and it only serves to introduce sort() with simple numbers integers. You can take it a step further by adding more complex logic.

For a more complex logic, we may say... If A minus B, is greater than zero then return one. Et cetera.

Numbers can also be substituted for months, fruits, or even days of the week. Depending on what suits your needs.
How to make Relational model from ER Diagram
Tags: database, ermodel, relationaldatabase, erdiagram
Published: 2021-10-18 01:58:02

n today’s post, we will learn how to make a Relational model from ER Diagram. ER diagram is just a conceptual picture of a database (Definition of ER Diagram HERE). It is one of the important tasks of the programmer to convert that diagram into tables while coding a database.

Let’s say we have to the ER Diagram of a company. The diagram has 3 strong entity sets, Employee, Department and Project with one-week entity Dependent.

To read more visit https://hecodesit.com/how-to-make-relational-model-from-er-diagram/