teleren/devto huggingface dataset:
Some Discuse About JWT  Token AND Database 
Published: 2022-01-05 16:59:32

JWT Token

JSON Web Token Short Hand is JWT is an open standard used to share security information between two parties — a client and a server. Each JWT contains encoded JSON objects, including a set of claims. JWTs are signed using a cryptographic algorithm to ensure that the claims cannot be altered after the token is issued

How JWT Token Works
 
JWTs differ from other web tokens in that they contain a set of claims. Claims are used to transmit information between two parties. What these claims are depends on the use case at hand. For example, a claim may assert who issued the token, how long it is valid for, or what permissions the client has been granted.

What is Aggregation in mongodb

aggregation operations process the data records/documents and return computed results

It collects values from various documents and groups them together and then performs different types of operations on that grouped data like sum, average, minimum, maximum, etc to return a computed result

What is a relational database?

A relational database is a collection of information that organizes data points with defined relationships for easy access. In the relational database model, the data structures -- including data tables, indexes and views -- remain separate from the physical storage structures, enabling database administrators to edit the physical data storage without affecting the logical data structure
🔥 Serverless boilerplate with TypeScript and Express [Open Source] 🚀
Tags: webdev, javascript, serverless
Published: 2022-01-05 16:50:09

---
title: 🔥 Serverless boilerplate with TypeScript and Express [Open Source] 🚀
published: true
description: Serverless express boilerplate using TypeScript with offline support and developer experience with ESLint and Prettier.
tags: webdev, javascript, serverless, javascript
cover_image: https://repository-images.githubusercontent.com/341987132/6a6a5100-777a-11eb-8b21-8c8c71881eb2
---

A Serverless boilerplate to build a backend in Express JS with TypeScript. Built with developer-experience in mind with ESLint, Prettier, Husky and Lint-Staged to help you writing high-quality code.

It also includes VSCode integration for better debugging session.

The Serverless starter code supports several features like:

- ⚡️ Offline support

- ⚙️ Environment variable

- 🚀 Production-ready

- ✨ Live reload

{% github ixartz/Serverless-Boilerplate-Express-TypeScript %}

I use this boilerplate to build all my backend projects. Perfect to start any backend projects like building a REST Api in Serverless.

Fully managed without any server maintenance. No need to learn or use Docker. Highly scalable and keep your cost low.

## Full-stack serverless SaaS application

If you want to build a SaaS application faster and better without losing your time configuring and installing dependencies, I have built a [Serverless SaaS Boilerplate](https://nextlessjs.com).

It includes everything you need to launch your SaaS in 1 month with authentication, subscription payment, user dashboards, landing pages, form management, infrastructure as code, etc. A full-stack application, 100% Serverless written in TypeScript.

[![Serverless SaaS Boilerplate](https://creativedesignsguru.com/assets/images/themes/nextless-react-saas-boilerplate.png)](https://nextlessjs.com)
Native React App coding Language
Published: 2022-01-05 16:49:19

Native React App coding Language

How to Reduce Your Codebase and Enhance Your Development Speed with Native React

Native React is the future of development, but you may be hesitant to jump in until you figure out how it works. Here's how to reduce your codebase and enhance your development speed by learning the basics of Native React.

Visit: Official Source [Website](https://www.olehanagermany.com/)
215. Kth Largest Element in an Array
Tags: 100daysofcode, java, programming, algorithms
Published: 2022-01-05 16:47:51

# [Description](https://leetcode.com/problems/kth-largest-element-in-an-array/)

Given an integer array `nums` and an integer `k`, return *the* `kth` *largest element in the array*.

Note that it is the `kth` largest element in the sorted order, not the `kth` distinct element.

## Example 1:

```
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
```

## Example 2:

```
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
Output: 4
```

## Constraints:

- `1 <= k <= nums.length <= 104`
- `104 <= nums[i] <= 104`

---

# Solutions

## Solution 1

### Intuition

## templates

```cpp
void quick_sort(int q[], int l, int r)
{
    if (l >= r) return;

    int i = l - 1, j = r + 1, x = q[l + r >> 1];
    while (i < j)
    {
        do i ++ ; while (q[i] < x);
        do j -- ; while (q[j] > x);
        if (i < j) swap(q[i], q[j]);
    }
    quick_sort(q, l, j), quick_sort(q, j + 1, r);
}
```

```java
private void quickSort(int[] nums, int l, int r) {
    if (l >= r) {
        return;
    }
    int i = l - 1, j = r + 1, x = nums[l + r >> 1];
    while (i < j) {
        do {
            i++;
        } while (nums[i] < x);
        do {
            j--;
        } while (nums[j] > x);
        if (i < j) {
            swap(nums, i, j);
        }
    }
    quickSort(nums, l, j);
    quickSort(nums, j + 1, r);

}

private void swap(int[] nums, int i, int j) {
    int temp = nums[i];
    nums[i] = nums[j];
    nums[j] = temp;
}
```

### Code

```java
class Solution {
    private int quickSort(int[] nums, int l, int r, int k) {
        if (l >= r) {
            return nums[l];
        }

        int i = l - 1, j = r + 1, x = nums[l + r >> 1];
        while (i < j) {
            do {
                i++;
            } while (nums[i] < x);
            do {
                j--;
            } while (nums[j] > x);
            if (i < j) {
                swap(nums, i, j);
            }
        }
        int s1 = j - l + 1 ;
        if (k <= s1) {
            return quickSort(nums, l, j, k);
        } else {
            return quickSort(nums, j + 1, r, k - s1);
        }
    }

    private void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

    
    public int findKthLargest(int[] nums, int k) {
        return quickSort(nums, 0, nums.length-1, nums.length - k + 1);
    }
}
```

### Complexity

- Time: O(nlogn)
- Space: O(logn)

---

## Solution 2

### Intuition

### Code

```java

```

### Complexity

- Time:
- Space:

---
Converting to Vite (Part 1)
Tags: vite, webdev, tooling, react
Published: 2022-01-05 16:41:57

This is Part 1 of a series about how recently in [Open Sauced](https://opensauced.pizza), we converted the project from using Webpack v4 to using [Vite](https://vitejs.dev)! A lot of what we'll cover in this series deals with [PR #1322](https://github.com/open-sauced/open-sauced/pull/1322). @bdougieyo started this as a `create-react-app` project 5+ years ago and so this conversion certainly turned out to be an undertaking!

You can read in many different places about the benefits of using Vite for tooling, as well as how it works under the hood, but we can unequivocally tell you that it significantly improved on the build times for our project. My fellow contributor @0vortex spent plenty of time with this PR, and he observed going from build times with Webpack around 220 seconds, to full build times with Vite around 9 seconds (and hot module reloads measured in milliseconds at worst).

So how did we get here? **Well, it's a good thing to describe alternatives considered when you add issues to a repo!** Months ago, @0vortex described in [Issue #1131](https://github.com/open-sauced/open-sauced/issues/1131) some opportunities for dependency updates that would require version 5 of webpack with our webpack configuration, and warned that the dependency management would probably be tricky. I fixated on an alternative that he mentioned about converting the project to use [Snowpack](https://www.snowpack.dev/). I had wanted to learn more about bundling tools, so I took a few days here and there after Thanksgiving and got Open Sauced mostly working with it (see [PR #1320](https://github.com/open-sauced/open-sauced/pull/1320)).

@bdougieyo looked over that PR on [stream](https://twitch.tv/bdougieYO), and pointed out that there was a lot more momentum recently with Vite as opposed to Snowpack. He pointed out that [Astro](https://astro.build) was changing from using [Snowpack to Vite](https://astro.build/blog/astro-021-preview/) for bundling, and that these were the same folks responsible for Snowpack. 

As it turned out, the conversion steps for getting our project working with Vite were pretty similar to those for Snowpack, so I managed to get a branch *mostly working* with Vite in about 25 minutes while the stream was still going. Little did I know, there was still plenty to be done!

In Part 2 of this series, I'll talk about some of the snags and learnings we had with the conversion, and in Parts 3 and 4, I'll talk about some of the ways the scope for this PR grew.

*Cover Image by [Anders Jildén](https://unsplash.com/@andersjilden?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/fast?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)*
WhatsApp Custom Link Message
Published: 2022-01-05 16:39:04

Make custom link messages to Whatsapp with nuget package.

```
var waComposer = new WaComposer();
waComposer.WriteText("Pedido",1,1);
//Observation: this 1,1 is break line. 1 before and 1 after

waComposer.WriteText("Item One");

//can format - available options: Italic, Bold, Strikethrough, Monospace.
waComposer.WriteText(WaFormat.Bold("Two")); 
waComposer.WriteText(WaFormat.Italic("Example Number: ") + "3");

var textResult = waComposer.GetText();

var whatsAppLink = WaSender.GetLink("PHONE_NUMBER_HERE",textResult);

//example output of whatsAppLink 
"https://wa.me/123/?text=THE_MESSAGE_FORMATED_BY_PACKAGE_HERE"
or on mobile 
"whatsapp://send?text=THE_MESSAGE_FORMATED_BY_PACKAGE_HERE&phone=123"

```
being able to stay like this for example:

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


Available on https://www.nuget.org/packages/WhatsAppLink/
Github https://github.com/oalexandrefreire/WhatsAppLinkCSharp
How to fix express-js CORS requests that use req.session.id
Tags: cors, express, fetch
Published: 2022-01-05 16:32:01

I had a problem: I had an **express-js** server serving the frontend by directly serving an HTML page.
For the frontend development, I was using a dev script which, using Rollup, was bundling js (and css and imgs and etc...) in a single file. I decided to switch to `Vite` for better developer experience, but I faced a problem I didn't expect: when setting up **CORS** permissions (by using express' middleware), the frontend did not work properly. I will not go into details of the code.

The problem was that the server used, for some requests, the `req.session.id` string as a common ground for storing some (important!) information. In the previous setting, this string remained unique among all the requests coming from the frontend, but at this point it was not the case anymore.

To resolve this problem, it was simply necessary to add the following option when calling the `fetch` function (to
all of them):

```js
fetch('endpoint', {
	credentials: 'include',
})
```

(And obviously enabling credentials in the CORS middleware:)

```js
app.use(
	cors({
		credentials: true,
	}),
)
```

This fix, in some way that I'm still not 100% sure, helps keeping the same `req.session.id` by passing in the HTTP
headers the necessary cookies.
1 line of code: How to convert tabs to spaces
Tags: javascript, webdev, productivity, codequality
Published: 2022-01-05 16:12:31

```javascript
const tabsToSpaces = (str, tabsize = 4) => str.replaceAll("\t", " ".repeat(tabsize));
```

Returns the string and replaces a series of spaces (`tab size`) with a tab.

---

## The repository & npm package

You can find the all the utility functions from this series at [github.com/martinkr/onelinecode](https://github.com/martinkr/onelinecode)
The library is also published to [npm as @onelinecode](https://www.npmjs.com/package/@onelinecode/onelinecode) for your convenience.

The code and the npm package will be updated every time I publish a new article.

---

Follow me on [Twitter: @martinkr](http://twitter.com/_martinkr) and consider to [buy me a coffee](https://www.buymeacoffee.com/martinkr)

Photo by [zoo_monkey](https://unsplash.com/@zoo_monkey) on [Unsplash](https://unsplash.com/s/photos/fuji)

---

[![Subscribe to the weekly modern frontend development newsletter](https://modernfrontend.dev/banner/banner_583-111.png)](https://modernfrontend.dev/)

---
My Developer Advocacy Origin Story
Tags: devrel, career, culture
Published: 2022-01-05 16:10:14

In the run-up to Christmas, I [took part in the Developer Adventcado](https://avocados.dev/adventcado/2021/12/15/andy-piper/) - it's a fun project from the [Developer Avocados website](https://avocados.dev) 🥑 a way to share and get to know other folks in the Developer Relations space. Five questions, and the answers to them: introducing who I am, what I do, and who and what has influenced me.

I'm not going to re-post the whole thing here, as you can [read it in full on the Developer Avocados website](https://avocados.dev/adventcado/2021/12/15/andy-piper/), but I've copied the answer to the first question below, which fills in my background.

If you are interested in Developer Relations, you can also sign up to the [Developer Avocados Weekly newsletter](https://developeravocados.net/), and "meet" many other folks from the [2021 Adventcado](https://avocados.dev/adventcado/2021/), over on [their site](https://avocados.dev).

---

## Tell us a bit about yourself.

Oh, hi! 😀 I am [@andypiper](https://twitter.com/andypiper), a Developer Advocate at Twitter. I live in the UK. I’m self-taught in tech - my education was primarily in Arts subjects (History), but I’ve always been fascinated by the possibilities for technologies to improve society. I grew up on British 8-bit computers, and learned BBC BASIC.

Jumping all the way back, I got my first job after university in the UK Post Office’s IT division. After that, I worked as a technical consultant for 10 years at IBM, before some folks noticed me building community and giving talks around a technology called MQTT (which they picked up via my Twitter profile). Through that, I moved into a full-time DevRel role as one of the first advocates for Cloud Foundry. After 2 years in the cloud, I was invited to join the DevRel team at Twitter… and I’ve been here nearly 8 years. For me, it’s the ideal combination of a technical role, on a platform that is all about social - connecting people. In total I think [I’ve been doing DevRel activities for 13 years or so](https://dev.to/andypiper/handling-change-as-a-developer-advocate-3j6d), out of [~20 years in tech](https://andypiper.medium.com/21-years-in-tech-d762810663ec). 

Other things I’ve done - I’ve been an Open Source project lead and admin, I’ve worked with the Eclipse Foundation, I’ve contributed to Ubuntu and was an occasional guest on the Ubuntu UK Podcast, back in the day. Oh, I also currently contribute to a [fun weekly podcast called Games at Work](https://gamesatwork.biz), looking at future tech and gaming technologies, with a pair of friends I’ve known since my IBM days - it keeps my curiosity active!

I also [love LEGO](https://andypiper.co.uk/2012/01/16/makers-creativity-learning-lego-ftw/)!

_[Read the rest on avocados.dev](https://avocados.dev/adventcado/2021/12/15/andy-piper/)_

---

_related content on DEV_ -- [Handling change as a Developer Advocate](https://dev.to/andypiper/handling-change-as-a-developer-advocate-3j6d) (with video, from DevRelCon Tokyo 2019)
Building a parser combinator: the parser class.
Tags: javascript, parser, parsercombinator, showdev
Published: 2022-01-05 15:49:51

This series presents the implementation of a parser combinator, step-by-step from scratch explaining how it works.

first, what is a parser combinator?

> a parser combinator is a higher-order function that accepts several parsers as input and returns a new parser as its output.

## the parser class

This class's object represents the simplest building block of the parser combinator.

```js
class Parser {
  constructor(process) {
    this.process = process;
  }
}
```

The `constructor` function takes a function `fn = fn(state) -> state`, where `state` is the current state of the parser, and returns a new state.

## chaining parsers

The core function is to "chain" parsers, so they can work in sequence, passing the `state` to each other.

```js
class Parser {
  // ...
  chain(parser) {
    return new Parser(state => {
      return parser.process(this.process(state));
    });
  }
}
```

The `chain` method takes a parser as an argument, and return a new parser.

## the `next` function

To be able to do further operations on the result of a parser provided that the status of the parser matches the given status, `next` method have been added to take the resulting state and operates on it.

```js
class Parser {
  // ...
  next(fn, status) {
    return this.chain(
      new Parser(state => {
        return state.status & status ? fn(state) : state;
      })
    );
  }
}
```
 
It simply "chains" a new parser to the current one, which - depending on `status` value - returns the `state` that was passed to it as it is, or the state returned from `fn`.

To simplify working with `next`, two method have been added.

## operating on the `state`

The `ok` method works if the `status` is `OK`.

```js
class Parser {
  // ...
  ok(fn) {
    return this.next(fn, State.OK);
  }
}
```

## catching errors

The `error` method works if there was an error.

```js
class Parser {
  // ...
  error(fn) {
    return this.next(fn, State.ERROR);
  }
}
```
----

Well, that that doesn't look very useful right now, but in the next post, basic parsers will be implemented using the parser class, and finally they can be "combined" together to make larger parsers.

You can find the full code on github on `main` branch {%github 0xc0Der/pari %}
Thanks for reading :smile:.
Penjelasan sederhana metode reduce pada Javascript
Tags: javascript, programming, tutorial
Published: 2022-01-05 15:43:51

Metode `reduce` dalam JavaScript digunakan untuk menggabungkan nilai array menjadi satu nilai, atau menjumlahkan array.


### Contoh penggunaan
Misalkan kita mempunyai data kalori makanan, kita bisa mendapatkan jumlah kalorinya dengan menggunakan fungsi `reduce`.

![penjelasan secara visual](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov2xk1nnzyl0d1fjdc3z.png)

penggunaan dalam kode Javascript
```javascript
let foodCalories = [800, 200, 100, 300, 700]
let totalCalories = foodCalories.reduce((sum, calory) => sum + calory)
// totalCalories mempunyai nilai = 2100
```

---

Sekian penjelasan `reduce` secara sederhana dari saya, semoga bermanfaat :)
Coba Cek, Apakah Anda Pekerja Keras atau Workaholic? 
Published: 2022-01-05 15:42:30

[Pekerja keras](https://www.lifetrends.live/) dan workaholic memang susah diperbedakan karena ke-2 nya sama berdedikasi tinggi pada kerjanya. Tetapi ke-2 nya memiliki ketidaksamaan dalam menanggapi beban kerja sebagai tanggung jawabannya. Bagaimana dengan seorang yang kerjanya lembur terus atau ketika akhir pekan masih bergelut dengan tugas, apa terhitung pekerja keras atau workaholic?

Berikut ketidaksamaan dari 2 istilah itu

1. Work Life Balance Biasanya, pekerja keras bisa mewujudkan work-life balance. Mereka mengetahui kapan harus bekerja dan kapan harus istirahat. Oleh karena itu, pekerja keras memakai waktu berliburnya untuk santai. Berlainan dengan workaholic yang saat berlibur, masih bergelut dengan kerjanya.

2. Konsentrasi Saat bekerja, pekerja keras akan konsentrasi dan kerap tidak ingin terganggu supaya kerjanya cepat usai. Berbeda hal dengan workaholic, mereka kemungkinan serius, tapi sering tidak sadar dan terikut oleh situasi kantor atau rekanan kerja yang menyukai bercakap hingga membuat kerjanya jadi terhalang.

3. Terus Belajar Seorang pekerja keras akan usaha mengoreksi diri bila sasaran belum tepat. Mereka terus akan belajar untuk capai sasarannya. Tetapi seorang workaholic, umumnya akan berambisi pada kerjanya yang malah akan membuat stress bila sasaran tidak terwujud.

4. Lebih Efisien Yang paling akhir, bila disaksikan dari waktu pembuatan, pekerja keras semakin lebih efisien mengoptimalkan waktu. Oleh karena itu, kualitas yang dibuat lebih bagus. Meskipun begitu, tidak berarti kualitas dari workaholic tidak baik. Karena, bisa jadi kualitas kerja workaholic tidak kalah baik dibanding dengan sang pekerja keras meskipun kemungkinan tidak seefektif dari pekerja keras.
Cara Agar Selalu Bisa Bekerja Dengan Semangat
Published: 2022-01-05 15:37:56




Tidak semua karyawan berasa semangat saat pergi ke kantor. Ada-ada saja hati jemu dan malas yang mengganggu sampai membuat semangat itu menyusut saat bekerja.

Walau demikian, sebetulnya ada beberapa hal yang dapat menggerakkan Anda supaya lebih semangat dalam bekerja. Bahkan juga Anda dapat berikan motivasi diri kita tanpa kontribusi seseorang.

Ingat, semangat untuk berusaha keras sebagai salah satunya kunci untuk capai keberhasilan. Berikut empat langkah berikan motivasi diri kita untuk berusaha keras seperti diambil dari Business Insider, Jumat (3/10/2014):

1. Konsentrasi pada Arah Berkarier

Salah satunya langkah paling mudah menggerakkan diri kita dengan berasa percaya tugas tidak berasa berat saat Anda berusaha keras. Konsentrasi pada arah Anda akan membuat tugas apa saja berasa lebih gampang.

Bikinlah usaha keras sebagai suatu hal yang gampang dengan menganggap sebagai rintangan untuk ditaklukan.

2. Bergabung dengan Rekanan Kerja yang Bekerja Keras

Jauhi rekanan kerja yang suka mengeluhkan dan malas. Yakinkan Anda bergabung dengan rekanan kerja yang suka berusaha keras dan menolong Anda.

Itu karena pemikiran dan sikap Anda pun kurang lebih dikuasai rekanan kerja lain.

3. Permudah Tugas yang Ada

Bikinlah tugas jadi gampang dengan membagikan ke beberapa tugas kecil. Yang paling penting ialah melakukannya keseluruhannya dan cara barusan akan menolong Anda membuat jadi lebih gampang.

4. Berlaku Positif

Ketidakberhasilan bisa menerpa siapa yang tidak percaya dianya bisa raih keberhasilan. Yakinkan Anda selalu berpikiran dan berlaku positif saat bekerja.

Jangan sampai menyaksikan karyawan lain sukses dengan rendah diri. Tetapi menjadikan keberhasilan seseorang sebagai pecut untuk diri kita supaya cemerlang dalam berkarier.