teleren/devto huggingface dataset:
Elasticsearch Tokenizers – Structured Text Tokenizers
Tags: elasticsearch, tokenizers
Published: 2021-05-22 10:18:41

https://ozenero.com/elasticsearch/elasticsearch-tokenizers-structured-text-tokenizers

Elasticsearch Tokenizers – Structured Text Tokenizers


In this tutorial, we're gonna look at Structured Text Tokenizers that are usually used with structured text like identifiers, email addresses, zip codes, and paths.

<!--more-->
<h2>I. Keyword Tokenizer</h2>
<code>keyword</code> tokenizer is the simplest tokenizer that accepts whatever text it is given and outputs the exact same text as a single term.

For example:
<pre><code class="language-json">
POST _analyze
{
  "tokenizer": "keyword",
  "text": "Java Sample Approach"
}
</code></pre>
Term:
<pre><code class="language-json">
[ Java Sample Approach ]
</code></pre>
<h2>II. Pattern Tokenizer</h2>
<code>pattern</code> tokenizer uses a regular expression to either split text into terms whenever it matches a word separator, or to capture matching text as terms.

The default pattern is <code>\W+</code>, which splits text whenever it encounters non-word characters.

For example:
<pre><code class="language-json">
POST _analyze
{
  "tokenizer": "pattern",
  "text": "Java_Sample_Approach's tutorials are helpful."
}
</code></pre>
Terms:
<pre><code class="language-json">
[ "Java_Sample_Approach", "s", "tutorials", "are", "helpful" ]
</code></pre>
<h3>Configuration</h3>
- <code>pattern</code>: Java regular expression, defaults to <code>\W+</code>.
- <code>flags</code>: Java regular expression flags. (for example: "CASE_INSENSITIVE|COMMENTS") More flags at: <a href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#field.summary" rel="nofollow" target="_blank">regex Pattern</a>
- <code>group</code> capture group to extract as tokens. Defaults to <code>-1</code> (split).

For example, we want to break text into tokens when it encounters commas:

More at:

https://ozenero.com/elasticsearch/elasticsearch-tokenizers-structured-text-tokenizers

Elasticsearch Tokenizers – Structured Text Tokenizers
Elasticsearch Tokenizers – Partial Word Tokenizers
Tags: elasticsearch, tokenizers, partial, word
Published: 2021-05-22 10:13:43

https://grokonez.com/elasticsearch/elasticsearch-tokenizers-partial-word-tokenizers

Elasticsearch Tokenizers – Partial Word Tokenizers


In this tutorial, we're gonna look at 2 tokenizers that can break up text or words into small fragments, for partial word matching: <strong>N-Gram Tokenizer</strong> and <strong>Edge N-Gram Tokenizer</strong>.

<!--more-->
<h2>I. N-Gram Tokenizer</h2>
<code>ngram</code> tokenizer does 2 things:
- break up text into words when it encounters specified characters (whitespace, punctuation...)
- emit N-grams of each word of the specified length (<strong>quick</strong> with length = 2 -> [qu, ui, ic, ck] )

=> N-grams are like a sliding window of continuous letters.

For example:
<pre><code class="language-json">
POST _analyze
{
  "tokenizer": "ngram",
  "text": "Spring 5"
}</code></pre>
It will generate terms with a sliding (1 char min-width, 2 chars max-width) window:
<pre><code class="language-json">
[ "S", "Sp", "p", "pr", "r", "ri", "i", "in", "n", "ng", "g", "g ", " ", " 5", "5" ]
</code></pre>
<h3>Configuration</h3>
- <code>min_gram</code>: minimum length of characters in a gram (min-width of the sliding window). Defaults to <strong>1</strong>.
- <code>max_gram</code>: maximum length of characters in a gram (max-width of the sliding window). Defaults to <strong>2</strong>.
- <code>token_chars</code>: character classes that will be included in a token. Elasticsearch will split on characters that don’t belong to:
+ letter (a, b, ...)
+ digit (1, 2, ...)
+ whitespace (" ", "\n", ...)
+ punctuation (!, ", ...)
+ symbol ($, %, ...)

Defaults to <strong>[]</strong> (keep all characters).

For example, we will create a tokenizer with sliding window (width = 3) and character classes: only letter & digit.
<pre><code class="language-json">
PUT jsa_index_n-gram
{
  "settings": {
    "analysis": {
      "analyzer": {
        "jsa_analyzer": {
          "tokenizer": "jsa_tokenizer"
        }
      },
      "tokenizer": {
        "jsa_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 3,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  }
}

POST jsa_index_n-gram/_analyze
{
  "analyzer": "jsa_analyzer",
  "text": "Tut101: Spring 5"
}</code></pre>
Terms:

More at:

https://grokonez.com/elasticsearch/elasticsearch-tokenizers-partial-word-tokenizers

Elasticsearch Tokenizers – Partial Word Tokenizers
Programlama Dili Öğrenmek için Yardımcı Olacak İpuçları
Tags: blog, programming, learning
Published: 2021-05-22 10:13:34

Herkesin herhangi bir programlama dilini öğrenebileceğine inanıyorum. Herhangi bir programlama dilinde usta olmak istiyorsanız, birkaç ipuçları vereceğim. 
Bunlar:

## 1. Günlük Kod Yazmak

Kodlamayı hayatının bir parçası yapmak istiyorsanız, her gün belirli bir zamanınızı programlama diline ayırarak tekrar etmektir. Kod yazmanız gerektiğini size hatırlatan bir şey istiyorsanız, telefonunuza bir alarm kurabilirsiniz.

## 2. Uygun Bir Çalışma Ortamı Oluşturun

![Alt](https://kodsozluk.com/uploads/images/contents/XSfsTo9fjuoIyKIohOTZWL3q.jpeg)

Her gün, bir işe gidiyor ve orada çalışmak üzere size evde ayrılan bir alan oluşturulmuş gibi düşünün. Çalışma alanları, öğrenmeye en elverişli alanlardır...

Devamı için; [kodsozluk.com](https://kodsozluk.com/mehmeterim/programlama-dili-ogrenmek-icin-yardimci-olacak-ipuclari)
3 Habits For Better Life
Tags: productivity
Published: 2021-05-22 08:47:32

The best way to change the future life is to change your daily routine. The habits we keep in our daily life determines our future.  The best way to change a bad habits is to replace them with good habits. Like if you spend 2 – 3 hours watching television you can use these 2 – 3 hours in reading books. Like if you spend 1 or 2 hours in gossip with your friends you can use these hours in watching entrepreneurship videos or you listen podcast of successful authors. 
The best way to change a habits is to replace them with good ones. 

### Habit 1 : Listen more than you talk

Success is not final; failure is not fatal; It is the courage to continue that counts. – Winston Churchil

The people who talks a lot are the ones who is silently hated by everyone. The best way to learn from everyone is to keep your mouth shut and earn open. Develop a habit of listening within yourself and always try to see things not just from your point of view but also from other person point of view. The people who keep their mouth shut are the ones who liked by everyone because people think they are listening their stories with full interest. When you are talking you are only repeating what you had already learn but when you are listening you are learning new things from other people. But it does not mean you will start listening your friend gossip. Change your surroundings surround yourself with people are successful than you or you can learn from them by reading their biographies. 

### Habit 2 : Goal Setting

If people are doubting how far you can go, go so far that you can’t hear them anymore. – Michele Ruiz
The goals is what turn invisible into visible. The goals is what gives you a reason to wake up early in the morning. The goals is what makes you think outside the box. Living a life without goals is like travelling without destination. Give yourself goals in every field of your life when you have written goals about your dreams you won’t procrastinate. People usually procrastinate when they don’t have clear plans and goals about their dreams and destination. 

### Habit 3 : Surround Yourself with Positive people

There is no elevator to success. You have to take the stairs. - Unknown
Always remember that the people you surround yourself with matters. The people you surround with words you hear or the words you use in your daily life matters. Be clear about what you want how you are going to achieve it. Surround yourself with people who are smarter than you whose behavior is better than you and one day you will drift to their direction.
Elasticsearch Character Filters
Tags: elasticsearch, filter, character
Published: 2021-05-22 10:03:17

https://grokonez.com/elasticsearch/elasticsearch-character-filters

Elasticsearch Character Filters

Elasticsearch Character Filters preprocess (adding, removing, or changing) the stream of characters before it is passed to Tokenizer. In this tutorial, we're gonna look at 3 types of Character Filters: HTML Strip, Mapping, Pattern Replace that are very important to build Customer Analyzers.

<!--more-->
<h2>1. HTML Strip Character Filter</h2>
<code>html_strip</code> character filter can:
- strip out HTML elements (like <code>&#60;b&#62;</code>)
- replace HTML entities with their decoded value (<code>&#38;amp;</code> becomes <code>&</code>).

For example:
<pre><code class="language-json">
POST _analyze
{
  "tokenizer":      "keyword", 
  "char_filter":  [ "html_strip" ],
  "text": "<p>JavaSampleApproach&apos;s tutorials are so <b>helpful</b>!</p>"
}</code></pre>
Terms:
<pre><code class="language-json">
[ \nJavaSampleApproach's tutorials are so helpful!\n ]
</code></pre>
<h3>Configuration</h3>
<code>escaped_tags</code>: array of HTML tags which should not be stripped.

For example, we want to to leave &#60;b&#62; and &#60;p&#62; tags in place:
<pre><code class="language-json">
PUT jsa_index_char_filter_html
{
  "settings": {
    "analysis": {
      "analyzer": {
        "jsa_analyzer": {
          "tokenizer": "keyword",
          "char_filter": ["jsa_char_filter"]
        }
      },
      "char_filter": {
        "jsa_char_filter": {
          "type": "html_strip",
          "escaped_tags": ["b", "p"]
        }
      }
    }
  }
}

POST jsa_index_char_filter_html/_analyze
{
  "analyzer": "jsa_analyzer",
  "text": "<p>JavaSampleApproach&apos;s tutorials are so <b>helpful</b>!</p>"
}
</code></pre>

More at:

https://grokonez.com/elasticsearch/elasticsearch-character-filters

Elasticsearch Character Filters
Font Awesome with VueJS 3
Tags: vue, vuejs3, fontawesome, javascript
Published: 2021-05-22 10:03:14

>version 5

Font Awesome is a great tool for working with various of icons. It is the most popular and widely using icon toolkit. In a VueJS 3 CLI project you can easily add Font Awesome library by following these easy steps:

# install `fontawesome` packeges from `npm`
>install all of them one by one
```shell
npm i --save @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-brands-svg-icons
npm i --save @fortawesome/free-regular-svg-icons
npm i --save @fortawesome/vue-fontawesome
npm i --save @fortawesome/vue-fontawesome@prerelease
```
**5 no is for Vue version 3 only**
**6 no is for Vue 3++ version, also work with Vite**

> install 5 or 6, not both

## import in `main.js`
>You can find `main.js` inside your vuejs 3 project, `/src` folder. 
```js
//vue-app/src/main.js
import { library } from "@fortawesome/fontawesome-svg-core";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { fas } from '@fortawesome/free-solid-svg-icons'
library.add(fas);
import { fab } from '@fortawesome/free-brands-svg-icons';
library.add(fab);
import { far } from '@fortawesome/free-regular-svg-icons';
library.add(far);
import { dom } from "@fortawesome/fontawesome-svg-core";
dom.watch();

const app = createApp(App);

app.component("font-awesome-icon", FontAwesomeIcon);

// add necessary dependencies...

app.mount("#app");
```

Thats it! now you can use [font awesome](https://fontawesome.com/) icon in your VueJS 3 project!

```html
<i class="fad fa-laugh-wink"></i>
```
>if there any problem popup, don't forget to ask me!

Follow me on Twitter [sabbirsobhani](https://twitter.com/sabbirsobhani)

Note: This article was originally Posted on May 22, 2021. While the core concepts discussed here remain relevant, please be aware that the technology landscape is constantly evolving. Libraries, frameworks, and best practices may have changed since this article was written. For the most up-to-date information, consider checking the latest documentation or resources.
JavaScript try...catch
Tags: javascript
Published: 2021-05-22 09:09:24

Try catch confused me for a long time, both how you use it and why you use it. Let's start with how.

### It's like if else, but not

If you were to write try catch as an if else, it would look like this:
```
if(it works) {
  do something
} else {
  show an error
}
``` 
But it's not an if else, so it actually looks like this:
```
try {
  getting it to work
  it worked, so do something
} catch {
  show an error
}
``` 
It's the same, but the condition is effectively inside the try block. And not an explicit condition. And involves magic. Or so it seems. Because if the thing doesn't work it skips everything else in the try block and skips to the catch block.

It's the difference to if else that trips me up, even though the try and catch are good words to understand what's going on. For example:
```
try {
  to fly on a trapeze
  fly!
} catch {
  in the net
}
``` 
So in summary, it's an if else, but the condition is implicit.

### But what's it for?
A good use is for APIs. If the API doesn't send back data then it's good to find a way to tell the user that, rather than leaving them waiting, wondering if the data is ever going to arrive.
```
try {
  to get some data from an API
  show data
} catch (error) {
  show error
}
``` 
I added a bit here which I skipped from my explanation further up, for the sake of simplicity. The cool thing that try catch does is that when it fails, it sends that information to the catch block. So your error might be "404 Not found" for example.

There's another extra bit you can add, which is finally. It runs whether you succeeded or not, after it's finished either the try or the catch block:
```
try {
  to fly on a trapeze
  fly!
} catch (me) {
  me in the net
} finally {
  have another go!
}
``` 

It's simple when you know how it works!
React Hook vs. Classes
Published: 2021-05-22 08:34:49

When I first stumbled upon React Hooks, I had just finished learning how to use class components and set up state variables. I thought React Hooks was just another gimmick on how to form a component. But the more I started using React, the more I naturally gravitated towards React Hooks. Nowadays, I look at class components and I shudder a little bit thinking just how much easier it would have been to do that in Hooks.

So lets compare!

To compare, let’s sketch up a component that can display and increment a counter. But let’s do it both in React Hooks and a regular class component.

First lets do it with a class component. Side note, without React Hooks, to have a stateful component, you actually NEED to have a class component as functional components can not hold state without Hooks.

```
import React from ‘react’;

class Counter extends React.Component{
   constructor(props){
      super(props);
      this.state={
         counter:0
      }
   }

   handleClick = () => {
      this.setState( (prevState) => {
         return { counter: prevState.counter + 1 }
      })
   }

   render(){
      return(
         <button onClick={ handleClick }>
            {this.state.counter}
         </button>
      )
   }
}

export default Counter;
```

Yes, that whole thing is just to store and display one state. Now lets do that same thing but with React Hooks.

```
import { useState } from ‘react’;
function Counter(){
   const [counter, setCounter] = useState(0);
   const handleClick = () => {
      setCounter(counter + 1);
   }

   return(
      <button onClick={handleClick}> {counter} </button>
   )
}
export default Counter;
```
Isn’t that insane?! It still boggles my mind how simple React Hooks makes it! React Hooks gets rid of the need for a constructor just to instantiate your state, gets rid of the need to define your own setState method, gets rid of needing to use a callback function to store and reference the previous state just to increment that and set it to the current state, gets rid of the messy ‘this’ thats all over the place. Over all I think React Hooks simplifies our components alot and that that’s something we should all want to do. With that being said, I think it is still widely useful to learn the classical way with components before jumping into React Hooks. I’m very glad to be fortunate enough to start off with the class components first because I feel it gave me a better understanding of why React Hooks is needed and to actually have experienced the problem it tries to solve. That and also since legacy code bases are probably still written with class components and therefore making it still relevant.
CDN Invalidation using AWS Lambda Function
Tags: aws, cdn, awslambda, cloudskills
Published: 2021-05-22 08:29:42

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/drglrlo6m6w9bjyijpbm.png)

Steps to create Invalidation using lambda function are:
  1. Create a Lambda Function and write a code.
  2. Create an API Gateway / API from which we are going to create 
     Invalidation of CDN

Step:1
Creating a Lambda Function:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4xagib2j0hbjys21a9e.png)

Just give a name of the function and use the Runtime of python 3.8 and put rest all things as it is.

Now Click on Create Button and Your Function is created.

When you go inside a function you will find this window.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8kks8mb44wurwrr8z7n.png)

Paste this code inside the code area.

> from __future__ import print_function

> import boto3
> import time

> def lambda_handler(event, context):
>  client = boto3.client(‘cloudfront’)
>  path = “/*”
>  invalidation = client.create_invalidation(DistributionId=”Put your CDN ID”,
>    InvalidationBatch={
>     ‘Paths’: {
>     ‘Quantity’: 1,
>     ‘Items’: [path]
>    },
>    ‘CallerReference’: str(time.time())
>   })

You will get your CDN ID from Cloudfront Dashboard like this

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

Now attach the Cloudfront full access policy to our lambda policy like this.

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


We have completed step 1.

Step:2

Create an API for that you have to use AWS API Gateway Service.

Create HTTP API. 

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


The Integration, section adds lambda and selects your lambda function in my case it is an invalidation name of the function.

And rest all thing keep as it is and create an API.

We have successfully completed all the steps.

Now come to the lambda function and reload our lambda function page and you will get our API Gateway in the trigger section like this 

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

Now Click on API Gateway you will get something page like this:

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

Click on API Endpoint and execute this URL in the browser and here your CDN invalidation is created.

You can check it like this:  

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

So here we Created a CND Invalidation using AWS Lambda Function.

Thank you for reading this blog, hope you learned some new thing.

Still, if you have any query you can refer to my video 

https://www.youtube.com/watch?v=sDT1sg72fUY

Still, you have any doubt you can contact me on LinkedIn

LinkedIn: https://www.linkedin.com/in/nipun-parekh-6006a0152/
Setting up Nodejs with nvm on WSL 2
Tags: linux, windows, node, wsl
Published: 2021-11-15 07:44:12

---
title: Setting up Nodejs with nvm on WSL 2
published: true
date: 2021-05-22 07:17:14 UTC
tags: linux, windows, node, wsl
canonical_url: https://blog.devsharma.live/setting-up-nodejs-with-nvm-on-wsl-2
---

## Installing node.js in WSL 2

( **NOTE** : Although this tutorial demonstrates WSL 2/Ubuntu, this installation is primarily for Linux) In this tutorial, we will use node version manager or _nvm_ to install and manage node versions. nvm certainly has its advantages as it allows you to easily install and manage multiple node versions on your system. This also means you can easily switch node and npm versions with a single command and that comes in handy.

If you don't already have it, install `curl`

```
sudo apt-get install curl


curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

```

( **Note:** _instead of `v0.38.0` Use the [latest version of nvm from GitHub](https://github.com/nvm-sh/nvm)_)

Verify your installation using

```
command -v nvm

```

(If you get an error `command not found`, restart your shell and try again.)

Let's install the LTS and latest stable version of Nodejs, you can also choose one of those if you prefer, but believe me, it's super simple to switch between different node versions using nvm.

Install the LTS version

```
nvm install --lts

```

Install the latest version

```
nvm install node

```

You can check all the installed versions using the following command

```
nvm ls

```

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1621192941097/_6rZJ-dZ9.png)

Check the version of node and npm you are running:

```
node --version
npm --version

```

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1621193220922/LLP4pPSPL.png)

You can install a specific version of node:

```
nvm install 14.17.0

```

To use a specific node version:

```
nvm use 14.17.0
# lts version
nvm use --lts
# latest stable version
nvm use node

```

Feel free to reach out to me on Twitter [@cryptus\_neoxys](https://twitter.com/cryptus_neoxys) and connect with me on [LinkedIn](https://www.linkedin.com/in/cryptus-neoxys/).

* * *

## Refs & Resources

[Microsoft Docs](https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl)

[nvm-sh/nvm](https://github.com/nvm-sh/nvm#readme)
Developers Ego
Tags: discuss, programming, codereview
Published: 2021-05-22 06:39:52

Ego Hurts!

Everyone has ego accepting it just the first stage. Its hard to take comments from anyone on your beautifully written code, as the quote goes...

> Beauty is in the eye of the beholder

Its human nature to have it nothing wrong with it. There are 8 billion perspectives so is the population.

When a developer writes code he would mostly want cover as many scenarios there is, being human is our only limitation for now 😉.

We get so involved writing to those limited perspectives we can imagine, that it hurts when someone points out the missed ones. Only thing that teaches to take in criticism is **experience**.

Don't worry about the ego it fades with time 😇

Code on!

Photo by [Charles Deluvio](https://unsplash.com/@charlesdeluvio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)