teleren/devto huggingface dataset:
Mongo and Node.js on local instance
Tags: mongodb, node, database, tutorial
Published: 2021-06-17 07:24:50

# Use MongoDB locally
## To do
For the MERN stack it can be great to use MongoDB locally. Mainly if your company proxy does not accept to run on cloud. To install MongoDB on local there is three main steps :
* Download the installer
* Install on local without services
* Create databases for test

## Download the installer
First step, the easiest one but it can be confusious. The server installer can be found at the following link https://www.mongodb.com/try/download/community. It will allow you to install mongo.exe (the mongo shell), mongod.exe (the mongo server), mongos.exe.

## Installation
This one can be various following your needed. I will explain you how to install on Windows without services.
Firstly we will execute the installer and decoche the "Install MongoDB as a Service"
<img src="https://docs.mongodb.com/manual/images/windows-installer-install-only.png" alt="Mongo DB installer windows decoche as services option">

Click next, and choose to install MongoDB Compass to have graphical tool for your databases.

## First use of MongoDB locally
### Create the database
For this step we will use MongoDB Compass. Open the service and connect it to your local server.
<img src="https://i2.wp.com/www.techomoro.com/wp-content/uploads/2020/10/compass.jpg?resize=640%2C341&ssl=1" alt="Connect to local instance of mongodb">

Once your are connected you can create your first database. Click on ```CREATE DATABASE``` name it as you want.
* Database Name : ```myDatabase```
* Collection Name : ```users```

> Note: all MongoDB collections needs a s at the end.

### Connect your Node.js server
> Note: For this step we will simplify the configuration to make it easy but that does not respect best pratices of express configuration.

On your index.js file you will need to create your express instance and your mongoose connection.

```JavaScript
const express = require('express')
const mongoose = require('mongoose')
const db = "mongodb://localhost:27017/myDatabase"

// Connection function
const connectDB = async () => {
    try{
        await mongoose.connect(db, {
            useNewUrlParser: true,
            useCreateIndex: true,
            useFindAndModify: false,
            useUnifiedTopology: true,
        })

        console.log('MongoDB successfully connected') 
    } catch (err) {
        console.error(err.message)
        process.exit(1)
    }
}

// Create server instance
const server = express()

// Creation of connection
connectDB()

// Import your routers
server.use('/api', require('./routes/root'))
```

That's done you know how to create an local instance of MongoDB and to make your Node.js server running on it.
What is a Vampire Attack in Crypto?
Tags: cardano, decentralizedexchang, sushiswap, defi
Published: 2021-06-23 14:21:26

---
title: What is a Vampire Attack in Crypto?
published: true
date: 2021-06-17 07:03:53 UTC
tags: cardano,decentralizedexchang,sushiswap,defi
canonical_url: https://medium.com/coinmonks/what-is-a-vampire-attack-in-crypto-fdfc5e1fc5fc
---

[![](https://cdn-images-1.medium.com/max/1463/1*tn-44RXcwTXXAnUkmvUCQg.png)](https://medium.com/coinmonks/what-is-a-vampire-attack-in-crypto-fdfc5e1fc5fc?source=rss----721b17443fd5---4)

Well, actually a Vampire Attack is a method in DeFi where one protocol offers better rates than another protocol, stealing their customers…

[Continue reading on Coinmonks »](https://medium.com/coinmonks/what-is-a-vampire-attack-in-crypto-fdfc5e1fc5fc?source=rss----721b17443fd5---4)
Add Snooze functionality to Notification channels.
Tags: laravel, programming, php, php8
Published: 2021-06-17 06:51:39

The simple way to add snooze functionality to your notification channels in your Laravel application. 

```php

use Carbon\Carbon;

class SnoozeData
{
    public Carbon $snooze_until;

    public function __construct(
        public int $duration,
        public string $type,
    ) {
        $this->getSnoozeUntilTime();
    }

    private function getSnoozeUntilTime(): void
    {
        $time = Carbon::now();

        $this->snooze_until = match ($this->type) {
            'minutes' => $time->addMinutes($this->duration),
            'hours' => $time->addHours($this->duration),
            'days' => $time->addDays($this->duration),
            'weeks' => $time->addWeeks($this->duration),
            default => $time,
        };
    }
}

```



```php
$details = new SnoozeData(...Request::validate([
   'duration' => ['required', 'integer', 'between:0,1000'],
   'type' => ['required', 'string'],
]));

       
$notifyUser->update([
  'snooze_until' => $details->snooze_until,
]);


```
How to learn Solidity in 30 days
Tags: solidity, coinmonks, ethereum, soliditytutorial
Published: 2021-06-23 14:21:34

---
title: How to learn Solidity in 30 days
published: true
date: 2021-06-17 06:42:58 UTC
tags: solidity,coinmonks,ethereum,soliditytutorial
canonical_url: https://medium.com/coinmonks/how-to-learn-solidity-in-30-days-78b02e503d23
---

[![](https://cdn-images-1.medium.com/max/957/0*v_YTkjqBhHqUm2Ae)](https://medium.com/coinmonks/how-to-learn-solidity-in-30-days-78b02e503d23?source=rss----721b17443fd5---4)

Over the past month, I spent my free time learning Solidity (Ethereum Smart Contract language). It was a great learning curve.

[Continue reading on Coinmonks »](https://medium.com/coinmonks/how-to-learn-solidity-in-30-days-78b02e503d23?source=rss----721b17443fd5---4)
LSP client for vim
Tags: vim
Published: 2021-06-17 06:34:14

[`coc.nvim`](https://github.com/neoclide/coc.nvim) is the best, because.. it is most user friendly - tells what it does and waits for user to read. 

![coc is best for vim](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/saxng33vzihy1uow7dtr.png)

This is important, because `vim` has too many things that contain text - windows, buffers, splits, stdout, messages - and new/occassional users are probably not aware how to inspect and leave them.

`vim` is truly a lifelong learning editor.
How to Customize the Numeric Axis in React Charts
Tags: reactnative, charts, component, webdev
Published: 2021-06-17 06:31:24

Learn how easily you customize the numeric axis of Syncfusion [React charts](https://www.syncfusion.com/react-ui-components/react-charts "React charts"). This video explains how to customize the minimum and maximum axis range, interval, label format, title, range padding, and grouping separator to the chart's numeric axis.
 
Download the example from GitHub: 
https://bit.ly/3ccKXPm

Refer to the following documentation for the numeric axis in the Syncfusion React Chart component: 
https://bit.ly/3pcGba1

Check out this online example of the numeric axis in the Syncfusion React Chart component: 
https://bit.ly/3g5Ti8Q

{% youtube D45CNL1Ibng %}
How to Work with Appointments in Blazor Scheduler
Tags: blazor, scheduler, webdev, appointments
Published: 2021-06-17 06:26:15

Learn how easily you can work with appointments in Syncfusion’s [Blazor Scheduler](https://www.syncfusion.com/blazor-components/blazor-scheduler). 

To learn how to add the [Blazor Scheduler](https://www.syncfusion.com/blazor-components/blazor-scheduler) to your application, watch this video: 
https://bit.ly/3uPalCi

In this video, you will learn how to make specific appointments all-day appointments and recurring events. You will also learn how to make appointments read-only, as well as how to block specific time slots. This video also covers additional items like how to enable tooltips for appointments, and how to change the titles of the field labels in the editor window.

{% youtube Vtl1Wyuwt-0 %}
The unused destructuring in Javascript
Tags: javascript, webdev, beginners
Published: 2021-06-17 06:22:41

I was just going through MDN and ECMA specs and trying out some cool little time saving tricks with destructuring in javascript.

### Destructuring array based on index

```js
let arr = [10, 20, 30, 40, 50];
let {0: first, 3: forth, ...rest} = arr;
console.log(first) // 10
console.log(forth) // 40
console.log(rest) // {1: 20, 2: 30, 4: 50}
```

### Ignore some values from array at a particular position

```js
const [a, , b] = [1, 2, 3];
console.log(a); // 1
console.log(b); // 3
```

### Using dynamic key in destructuring

```js
let ab = {
  a: 10,
  b: 20
};
let a = 'a';
let {[a]: aVal} = ab;
console.log(aVal) //10
```

> You can even use function call, string template etc in the dynamic key

```js
function getDynamicKey() {
    return "a";
}

let ab = {
  a: 10,
  b: 20
};
let {[getDynamicKey()]: aVal} = ab;
console.log(aVal) //10
```
Is there any way I can change a file header in Linux like how I'd change a file extension in Windows (10).
Tags: linux, windows, watercooler, help
Published: 2021-06-17 06:02:03

I know in Windows, "file extensions", the part of a file name after the final period in the file name, are more than just part of the file name, they also act as metadata to tell Windows what kind of file the document should be treated as, and what apps to open them in (i.e. what apps are associated with those file types).

However, I want to start moving to Linux (Ubuntu) which I installed on my PC a while back, so, I recently tried making a new file ("extensionless"), and I wanted to make it a different type, so I tested to see if that would work by testing by renaming it `.go`, so I could try to open it in VSCode like I normally would on WIndows.
Surprise, it doesn't work.

I look up multiple searches, involving how to change the file extension (only getting results using command line), and eventually coming over to a horrifying S.O. answer that horrified me, it gave me the info that "extensions" (file types) are determined by header.

There doesn't seem to be any way in the "Files" file manager for Ubuntu to change the header type.
There seems to be no concept of anything other than a plain "Text" file.
(Well, there is, but you just can't see or change it.)
<br/>
What I want is a program that can give me a simple GUI to edit the file type of a file so I can easily go between one or the other as needed/wanted.
(Even better, and more appreciated would be some kind of program that works with "Files" to add the option to change the filetype-header in context menu (when a certain file is selected). Though, either will do.)


Info:
```yaml
OS: Ubuntu 20.04.2 LTS
WindowingSystem: X11
GNOME: 3.36.8
```
Python's Collections Module: OrderdDict
Tags: python, codenewbie, collections
Published: 2021-06-17 04:54:12

## Why do we need OrderedDict anway?

Since dictionaries in python maintain their insertion order completely after **python 3.7+**, use case of `OrderedDict` is fading away slowly. But still there are some helper methods and functions that we can leverage while using OrderedDicts.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t806u5fbdsoy6mk0e8i4.png)
### Creating `OrderedDict`
Since, it is a `dict` sub-class. It can leverage all the functionalities of dictionary.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6x5t0qs1ym5tfk5myekm.png)Let's discuss some important methods pertaining to `OrderedDict` only.

## `popitem` method

The `popitem(last = True)` method for ordered dictionaries returns and removes a **(key, value)** pair. 

The pairs are returned in ,
1. *LastInFirstOut(LIFO)* order if last is **true**. That is to say, **last** pair is popped.(default)
2. *FirstInFirstOut(FIFO)* order if **false**. That is to say, **first** pair is popped.
```python
from collections import OrderedDict

ord_dict = OrderedDict({"fname": "The",
                        "lname": "CodeBlooded",
                        "founder": "A Geek",
                        "Ran by": "Geeks"})

last_pair = ord_dict.popitem()  # last=True by default
first_pair = ord_dict.popitem(last=False)

print(f'last pair: {last_pair}')
print(f'first pair: {first_pair}')

"""OUTPUT 
last pair: ('Ran by', 'Geeks')
first pair: ('fname', 'The')
"""
```
## `move_to_end` method

The `move_to_end(key, last=True)` moves an existing key to either end of an ordered dictionary. 

The item is moved to the right end if last is true (default) or to the beginning if last is false.
```python
from collections import OrderedDict

ord_dict = OrderedDict({"fname": "The",
                        "lname": "CodeBlooded",
                        "founder": "A Geek",
                        "Ran by": "Geeks"})

print(f'Before =>\n{ord_dict}')
# move to right-most end
ord_dict.move_to_end('founder')

# move to left-most end
ord_dict.move_to_end('Ran by', last=False)

print(f'After =>\n{ord_dict}')

"""OUTPUT 
Before =>
OrderedDict([('fname', 'The'), ('lname', 'CodeBlooded'), 
            ('founder', 'A Geek'), ('Ran by', 'Geeks')])
After =>
OrderedDict([('Ran by', 'Geeks'), ('fname', 'The'), 
            ('lname', 'CodeBlooded'), ('founder', 'A Geek')])

"""
```
💡 **KeyError** is raised if given key is not present in the dictionary.

And that wraps our discussion on `OrderedDict`! If you notice all of Collections classes we discussed till now are `dict` subclass, isn't it interesting ? It's testament to how much powerful dictionaries in python are 😎
Keeping up with... Discord Servers.
Published: 2021-06-17 04:44:20

Hi 👋 - I am basically new to Discord, been using it for a while and subscribed to some servers that I found really interesting.

What makes it interesting is all the info that the members share but this is at the same time an issue for me, how do you keep track of all the information shared? Trying to keep up with all the channels can turn to be overwhelming.

What's the best strategy to keep up to date with Discord? Going once a day through all of the channels reading and reviewing what's valuable?

Would love to read recommendations!

PD: Just read Tessa Mero's tips: https://dev.to/tessamero/discord-is-becoming-a-chore-how-to-categorize-and-organize-all-of-your-servers-3h7g Really useful.
Effective Java: Prefer Interfaces To Reflection
Tags: java, effective, interface, architecture
Published: 2021-06-17 04:08:15

---
title: Effective Java: Prefer Interfaces To Reflection
published: true
description: A dive into chapter 65 of Effective Java
tags: java, effective, interface, architecture
series: Effective Java Review
canonical_url: https://blog.scaledcode.com/blog/effective-java/prefer_interface_to_reflection/
---

Java provides a very powerful capability in its reflection system. Reflection allows us to have extreme flexibility when calling classes, their constructors, and methods. These classes that we are interacting with may not even exist at the time that our reflexive code is written. This flexibility is not free, however; there are downsides to its use. Some of these are the following:

* *You lose out on compile time checks.*  Issues that would be exposed at compile-time when coded in non-reflexive style turn into runtime issues when coded via the reflexive apis.
* Related to the above, static code analysis tools have trouble being helpful working with reflection code. 
* Reflexive code often is clumsy and hard to read.
* *Reflexive code has worse performance than non-reflexive code.* In one benchmark, reflexive code proved to be 11x slower than a non-reflexive access. 

There can be specific applications where reflexive coding practices can be preferred. Examples such as code analysis tools and dependency injection frameworks. Even that said, recently these types of tools have been switching away from using reflection to avoid the above downfalls. 

Many of the times that we are reaching for reflection to solve a problem, what we are really after is the use of interfaces. By coding against an interface we still can code against code that has yet to be written, just like with reflection, and still gain some of the benefits of reflection. All of this without most of the downsides of the reflection APIs. 

Reflection is an extremely powerful tool in the toolbelt of a Java developer. It is helpful to understand how it works and that it exists but most of the time is not the tool that we should be reaching for.
Beginning to React
Tags: react, redux, bootcamp, beginners
Published: 2021-06-17 03:46:30

As I reach my last week of curriculum at Flatiron, I'm trying to reflect on what I've learned, the projects I've made, and my own personal growth.

I started February 1st, 2021, with almost no coding knowledge. I did the prework, but I didn't fully understand what I was doing. I remember FaceTiming my friend on my first day because I was stuck on the second lab, and her husband (a Python dev) offered advice using 'print'. While I now know that print actually does work in Ruby, I was immediately overwhelmed because that's not what I was looking for. I figured I must be completely wrong and I was confused how to even start over.
My first day also didn't go according to plan, because I was using VSCode and not the IDE, and I didn't know VSCode doesn't default to AutoSave.

I can't believe that was less than five months ago.

I can't believe how confident I feel in things I didn't even know existed before.

I can't believe I've created things like [this](https://github.com/JillKlatt/CharacterCreator) wonderfully silly DM Notebook, or my very first [CLI project](https://github.com/JillKlatt/cocktail-choices-phase1). And soon, I'm excited to add my final REACT project as the main piece of my portfolio:

![A basic drawio of my final project file structure and program flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90sgvovpfdl2xjm1rd4o.png)
*(Created 6/16/21, five days before Project Week begins, a lot can happen)*

This entire experience has been so phenomenal for me personally. I quit my job and cashed out my 401k and took an incredible, dangerous risk by investing in myself. I would be lying if I said I actually thought, back in February, I could make it all the way on time. I expected I would quit halfway through, or some environmental situation would come up, or I'd get kicked out after being held back too many times.

I've always struggled with recognizing my own value. But this bootcamp has made me challenge those intrusive thoughts that haunt me sometimes. I was able to answer that nagging feeling of "You're not actually understanding this, you're a fraud" with the knowledge that if this were true, my cohort lead wouldn't have let me get this far! I'm able to look at tangible evidence of the things I've created and the knowledge I have and my ability to help people and recognize the upward, exponential future I'm heading towards.

Participating in this has been so life changing in so many ways. I've made friends with people I never would've expected, I've learned a new way of thinking about things and looking at life, and I recognized a potential in myself I've been so hesitant to accept and appreciate.
🎥 Kubernetes Services, Ingress, Jobs and CronJobs
Tags: kubernetes, beginners, devops
Published: 2021-06-17 03:37:22

---
title: 🎥 Kubernetes Services, Ingress, Jobs and CronJobs
published: true
description: How can you access workloads inside the Kubernetes cluster? Should you use a NodePort or LoadBalancer service type? How about if you want to expose multiple applications through a single load balancer? In this session, you'll learn how to do all that. We'll deploy an Ambassador ingress controller and show how to expose multiple applications through the load balancer. Finally, we'll look into Jobs and CronJobs and show how to use them to run tasks on schedule. 
tags: kubernetes, beginners, devops
//cover_image: https://direct_url_to_image.jpg
---

How can you access workloads inside the Kubernetes cluster? Should you use a NodePort or LoadBalancer service type? How about if you want to expose multiple applications through a single load balancer? In this session, you'll learn how to do all that. We'll deploy an Ambassador ingress controller and show how to expose multiple applications through the load balancer. Finally, we'll look into Jobs and CronJobs and show how to use them to run tasks on schedule. 

{% youtube ef6UJ5Pa3Dw %}

### What's covered in the video?

00:00 - Introduction
01:00 - Agenda
02:54 - Kubernetes Services
10:24 - Talking to Pods using services (demo/lab)
23:37 - Service types
24:45 - ClusterIP service type
25:56 - NodePort service type
28:00 - LoadBalancer service type
29:00 - ExternalName service type
30:03 - Service types (demo/lab)
40:40 - Ingress introduction (exposing multiple services)
50:50 - Ingress (demo)
54:33 - Deploying Ambassador ingress controller (demo)
01:00:50 - Single service ingress (demo)
01:02:59 - Path-based routing with Ingress (demo)
01:08:13 - Using a hostname instead of an IP address (demo)
01:15:31 - Name-based ingress(multiple hosts) (demo)
01:19:00 - Kubernetes Jobs
01:26:39 - Kubernetes CronJobs
01:32:40 - Jobs and CronJobs (demo) 

You can find all the information on how to join the next live Kubernetes session at [live.startkubernetes.com](live.startkubernetes.com)!
Publish Websites Using Sanity CMS With 21YunBox
Tags: sanity, cms, headlesscm, node
Published: 2021-06-17 03:36:42

---
canonical_url: https://www.21cloudbox.com/cms/publish-websites-using-sanity-cms-with-21yunbox.html
---
In this blog, we will walk through the steps of publishing websites using Sanity CMS with 21YunBox. 


<p>&nbsp;</p>
## Steps to deploy websites with Sanity CMS and 21YunBox:

1. Sign up on [21YunBox](https://www.21cloudbox.com/u/signup/)
2. [Create or use existing Sanity project](https://manage.sanity.io/)
2. Fork [Sanity CMS Starter](https://github.com/21yunbox-examples/sanity-with-21yunbox) on Github
3. Use the following values during creation:

...

To read the full content of this post, go to: [https://launch-in-china.21yunbox.com/cms/publish-websites-using-sanity-cms-with-21yunbox.html](https://launch-in-china.21yunbox.com/cms/publish-websites-using-sanity-cms-with-21yunbox.html)

<p>&nbsp;</p>
<p>&nbsp;</p>
Stop Using Short Hand Autocomplete
Tags: csharp
Published: 2021-06-17 03:33:15

This is just a simple plea to IDE builders.

Visual Studio provides quick help to generate code. For example if you inherent from an interface the IDE can generate methods which throw a not implemented exception.

This generative auto complete is there to get you started to build the implementation.

Well C# provides a short hand => operator to implement short method bodies. Great feature.

```csharp
public class M : IFoo
{
    public string Bar() => throw new NotImplementedException();
} 
```

The point of this short hand is so I don't need to write down so much for a simple return.

The point of code generating is so I don't need to write down all the expected structure. If you generate the simple thing, you aren't doing your job. I have to convert all those arrows into bodies so I can actually implement the methods rather then claim I didn't implement them.