teleren/devto huggingface dataset:
Learn KOTLIN in 25 minutes
Tags: kotlin, android, mobile, programming
Published: 2022-05-07 17:38:45

The first time I heard about Kotlin, I thought it's the Russian island west of Saint-Petersburg 🤓, but then one of my fellow programmers corrected me and said "No dummy 😔, it's the best language today -this was in December 2019 - a month before COVID!!- to develop android apps"!

Hello guys, my name is Amir Bekhit aka Bek Brace, and I am so glad I started blogging again on DEV.to and this time I am going to talk a little bit about Kotlin programming language.

Kotlin - which ironically named after the Kotlin island in Russia - is a general purpose statically typed language that has become extremely popular in the last few years, designed quite simply as a better alternative to java like java it compiles to bytecode that runs on the java virtual machine but kotlin provides a more concise syntax and language features.

Out of 7.3 billion smartphones world wide, kotlin now is widely used for android development 
to write apps for the 2.5 billion devices running the android operating system.

Kotlin has been created in 2011 by JetBrains company, which is very well known for its IDEs such as IntelliJ, Pycharm and Datagrip; and the first stable release was in 2016; and in 2019 Google 
has named Kotlin The Preferred Language for Android Development over Java.

To write Kotlin code, you will need to use intellij which you can download for free > jetbrains.com/idea/download
There is another way to write Kotlin on VScode, but quite honestly I don't recommend using another text editor other than IntelliJ, come on it's produced by JetBrains which has invented Kotlin!

I have a 25 minutes video, feel free to check it out and let me know your thoughts about the language if you have worked before with it, or if you have long experience with the language, what are the pros and cons of Kotlin from your stand point of view ?

{% youtube ffPq1usEZSI %}

Thank you for reading - and watching maybe 🙃

Twitter : https://twitter.com/BekBrace
Instagram : https://www.instagram.com/bek_brace/
Website : https://bekbrace.com
Don't abuse critical sections
Tags: programming
Published: 2022-05-07 17:30:03

Critical section is a code block that cannot be executed by more than one process/thread at a time, which is why critical sections are expensive and can lead to a performance "bottle neck" at a specific flow. 

Critical sections must be as short, simple (if possible), and efficient as possible. 

For example, let's examine the following code block, which  generates a new UUID for a shared object:


```
with self._mutex:
    # start of lock 
    try:
        self._action.id = str(uuid.uuid4())                      
        self._logger.trace("action generated, action_id={action_id}".format(action_id=self._action.id))
    except BaseException as err:
        self._logger.error(err,"failed to generate uuid")
    # end of lock
```


I did three common mistakes here:

1. try & catch, ok, I admit it, probably not a common mistake since no one will put a try & catch that could be outside of a critical section inside of it without a good reason
2. logging inside a critical section. Usually, logging is an expensive IO operation which could have be done outside
3. generating the UUID inside the critical section

Here is the another code block which does the exact same thing, just without the three mistakes:

```
try:
    action_id = str(uuid.uuid4())
    with self._mutex:
        # start of lock
        self._action.id = action_id                  
        # end of lock
    
    self._logger.trace("action generated, action_id={action_id}".format(id=action_id))  
except BaseException as err:
    self._logger.error(err,"failed to generate uuid")
```

When you are using lock remember that is purpose is to avoid more than one thread access shared resources at the same time
Handle Multiple Promises using Async/Await
Tags: javascript, tutorial, programming, webdev
Published: 2022-05-07 17:26:34

In this example below, we loop through an Array of userIDs to fetch information about the user.

A naive approach may be to await each response one by one.

### ❌ The wrong and slow way

```js
userIDs = ['fooID1', 'fooID2', ...]
const slowMethod = async (userIDs) => {
    const results = [];
    for (let i = 0; i < userIDs.length; i++) {
        const res = await fetch(`https://api.foo.com/users?uid=${userIDs[i]}`)
        const data = await res.json()
        results.push(data);
    }
    return results;
}
await slowMethod(); //O(n) time
```

### ✔️ The Fast Way

```js
userIDs = ['fooID1', 'fooID2', ...]
const fastCleanMethod = async (userIDs) => {
    const promises = userIDs.map(async userID => {
        const res = await fetch(`https://api.foo.com/users?uid=${userID}`);
        return await res.json();
    });
    return await Promise.all(promises);
}
await fastCleanMethod(); //O(1) time
```
## 🧐 How it works

The fast method takes advantage of the Promise.all() method. The way it works is by fetching all the data first, then using Promise.all() to resolve/reject later. 

By doing this, we do not have to wait for each response one by one.

## Another Example of two separate fetches

Let's say we want to fetch user data and their entries. Here are two ways to do it.

### ❌ Fast but Fails Slow

```js
const getUserData = async (userIDs) => {
    const userDataPromise = fetch(`https://api.foo.com/users?uid=${userID}`);
    const userEntriesPromise = fetch(`https://api.foo.com/entries?uid=${userID}`);

    const [userDataRes, userEntriesRes] = [(await userDataPromise).json(), (await userEntriesPromise).json()];
    const [userData, userEntries] = [await userDataRes, await userEntriesRes];
    return {
        ...userData,
        userEntries,
    }
}
```
This method works well in most cases but if the second Promise is rejected bad things can happen. The reason it fails slow is because if the second Promise is rejected, the first Promise still runs for the whole duration.

Stack Overflow user [@T.J. Crowder](https://stackoverflow.com/users/157247/t-j-crowder) explains [parallel Promise patterns best here](https://stackoverflow.com/a/46889489).

### ✔️ Fast and Fails Fast

```js
const getUserData = async (userIDs) => {
    const userDataPromise = fetch(`https://api.foo.com/users?uid=${userID}`);
    const userEntriesPromise = fetch(`https://api.foo.com/entries?uid=${userID}`);

    const [userDataRes, userEntriesRes] = await Promise.all([userDataPromise, userEntriesPromise]);
    const [userData, userEntries] = await Promise.all([userDataRes.json(), userEntriesRes.json()]);
    return {
        ...userData,
        userEntries,
    }
}
```
We use Promise.all() because when a Promise is rejected, it immediately throws an error without waiting for other Promises.

It may be tempting to use pure async/await for handling multiple Promises but Promise.all() is still our best bet.
Setting up an expo CLI for development
Tags: javascript, nativedevelopment, tutorial, programming
Published: 2022-05-07 17:20:55

Hello developers, let’s set up an expo CLI into the machine to start an app-development !

Prerequisites,
You need to have a node install on your machine, haven't? get node from [here](https://nodejs.org/en/download/).
You must have simmulator on your machine. If your mac user you can have Xcode(get from app store) and android both, but this choice is limmited to android for windows user’s, get android studio [here](https://developer.android.com/studio?gclsrc=aw.ds&gclid=CjwKCAjwjtOTBhAvEiwASG4bCCeFkbUBba0lkpRCzm3qE-G4ETrRxM24NqsE-17Htnj55Qiwpy2BbxoCNzcQAvD_BwE).
Let’s check the version of our node and npm, to do so run following command in terminal.

`node --version`

`npm --version`

Now we need an expo CLI for initializing our app’s, so we get an expo globally

`npm i -g expo-cli`

This will install expo CLI on your machine. If your Mac user, you need to prefix this with ‘sudo’ and to install that, you were asked for the password by terminal, go ahead and install expo.

After setting up all, run following command to create a new expo app.

`expo init blog-app`

This will prompt for choosing template for your project, will go with blank.

Congratulations developers! we have created a new expo app.

We have successfully created our first expo app, now we need to run our app for that you can see [this](https://abhijeetgavali.medium.com/setting-up-an-expo-cli-for-development-9dff1e73e6d0) guide.

Till then keep learning :)
Golang Print Struct Verbosely
Tags: beginners, go
Published: 2022-05-12 02:21:24

---
title: Golang Print Struct Verbosely
published: true
date: 2022-05-07 17:00:01 UTC
tags: Beginner,golang
series: "Sunday Snippet"
canonical_url: https://clavinjune.dev/en/blogs/golang-print-struct-verbosely/
---

 ![Sunday Snippet #16 golang print struct verbosely](https://clavinjune.dev/img/sunday-snippet/image.png "Sunday Snippet #16 golang print struct verbosely")

```go
package main

import (
	"fmt"
)

type Foo struct {
	bar Bar
}

type Bar struct {
	number int
	word   string
}

func NewFoo(number int, word string) *Foo {
	return &Foo{Bar{number, word}}
}

func main() {
	f := NewFoo(10, "testing")
	fmt.Printf("%+v\n%#v\n%v", f, f, f)
}
```

```shell
$ go run main.go
&{bar:{number:10 word:testing}}
&main.Foo{bar:main.Bar{number:10, word:"testing"}}
&{{10 testing}}
```
next-export-i18n v2: updated to react v18 and next v12
Tags: javascript, nextjs, react, webdev
Published: 2022-05-07 16:59:47


The `version 2.0.x` of `next-export-i18n`, the i18n module for Next.js which is fully compatible with `next export`, supports react v18 and next v12.

---

Install `next-export-i18n` with `$ npm i next-export-i18n` or get [`next-export-i18n v1.3.0`](https://www.npmjs.com/package/next-export-i18n) from npm.js.

---


## About `next-export-i18n`

**This npm module provides a simple solution for Internationalization (i18n) of projects using `next export`.**

Next.js already has support for internationalized (i18n) routing out-of-the-box. You can provide a list of locales, a default as well as  domain-specific locales and Next.js  automatically handles the routing. It streamlines the touring and locale parsing for nearly all existing l18n library solutions available for Next.js such as `react-intl`, `react-i18next`, `lingui`, `rosetta`, `next-intl`.

Unfortunately, [`Next.js` i18n-routing](https://nextjs.org/docs/advanced-features/i18n-routing) does not supports `next export`.
This means that _none_ of the i18n-libraries (which are utilizing the build in i18n-routing) is able to support fully static sites which are generated with `next export`. 

`next-export-i18n` provides a simple solution for Internationalization (i18n) when you want to generate a truly static website with `next export`.

Read the [Introduction to `next-export-i18n` - next.js: i18n with static sites](https://dev.to/martinkr/next-js-i18n-with-static-sites-2644) for more details.

---

### Sample implementation 

You can also take a look at the example implementation [next-export-i18n-example.vercel.app](https://next-export-i18n-example.vercel.app) and its source code at [github: `https://github.com/martinkr/next-export-i18n-example`](https://github.com/martinkr/next-export-i18n-example).

---


## Links
- [`next-export-i18n` npm module](https://www.npmjs.com/package/next-export-i18n)
- [next.js: i18n with static sites (Introduction)](https://dev.to/martinkr/next-js-i18n-with-static-sites-2644)
- Example implementation: https://next-export-i18n-example.vercel.app
- Github for the npm-module: https://github.com/martinkr/next-export-i18n
- Github for the example: https://github.com/martinkr/next-export-i18n-example

---

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

--- 

Photo by [Jerry Zhang](https://unsplash.com/@z734923105?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText") on [Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

---
Day 7- Is Java pass by value or reference?
Tags: java, beginners
Published: 2022-05-07 16:59:42

---
title: Day 7- Is Java pass by value or reference?
published: true
date: 2022-05-07 16:55:26 UTC
tags: java, beginners
canonical_url: https://blog.sanjaybabu.dev/day-7-java-pass-by-value-or-reference
series: 100 days of interview questions
---

Again Java passes variables in functions similar to js. Check out the detailed explanations here.

{% embed https://dev.to/sanjaybabu/day-6-is-javascript-pass-by-value-or-pass-by-reference-1p19 %}
## Pass by Value

All primitive data types are passed by value in java.

```
class passByValue {
    public static void main(String args[]) {
        Integer i=0;
        increment(i);
        System.out.println("Value of i outside the function: "+i);
    }
    static void increment(Integer i){
        i++;
        System.out.println("Value of i inside the function: "+i); 
    }
}

/*
Output : 
Value of i inside the function: 1
Value of i outside the function: 0
*/

```

## Pass by Reference

Objects & arrays are pass by reference in java

```
class PassByValue {
  public static void main(String[] args) {
    Integer[] array = new Integer[2];
    array[0]=2;
    array[1]=3;
    add(array);
    System.out.println("Result from main: " +(array[0]+ array[1]));
  }

  private static void add(Integer[] array){
    array[0] = 10;
    System.out.println("Result from method: " +(array[0]+ array[1]));
  }
}

/*
Output:
Result from method: 13
Result from main: 13

*/

```
Is DevRel a luxury for big corporations?
Tags: devrel, community
Published: 2022-05-07 12:00:34

Is it true that only giants should invest in a DevRel team? The answer is becoming clearer than ever that it is "no".

And the reason for this is that smaller companies, startups, and medium-sized businesses, more than large corporations, need to connect with their user base and partner with them.

But, what exactly is DevRel?

> Developer Relations (DevRel) is a mindset that aims to get developers to adopt a platform or technology and succeed in their professional lives or side projects.

To ensure the success of Developers with your product, you need:

- Existence of market fit
- Developers know how to use it
- Developers enjoy using it

So, if you have a ten-person startup, why should one of them be a DevRel expert? First and foremost, because you are most likely still **developing your product** and want to shape it to meet the demands of developers, you should have someone form relationships with that audience, solicit input, and influence your product roadmap. Aside from that, receiving feedback from the field and demonstrating market fit will help you** gain investor confidence**.

After you've established market fit and made your product stand out from the crowd, you'll want to make sure you give your developers an exceptional Developer Experience. So, in addition to the product's usability, it's critical to develop tools that help your Developer be more **productive** with your product - how-tos, tutorials, sample code, training, and so on. tutorials, sample code, training, and so on.

However, productivity isn't always enough to keep developers on board. They must also like using your product and be able to brag about their achievements to their peers. With that in mind, "**Community**" is another pillar DevRel provides that can help a Startup succeed.

Building a sustained and vibrant community can help developers form an emotional connection with you and provide the resources they need to succeed, such as a network of like-minded individuals who can help them **unblock when they get stuck**. When they become fans, they will tell the world how they feel about you and your product, and they will help you raise **awareness** among the developer community throughout the world.

**In conclusion, DevRel can assist with the following high-level business objectives:**

- Confirm Market fit
- Shape product roadmap
- Raise awareness and drive adoption of the product
- Decrease time-to-deployment/time-to-revenue (productivity)
- Expand your support efforts

Finally, DevRel stands for intensive relationship management and **should not be viewed as a sprint but rather an endurance race**. The successful build-up of Community and networking in the developer scene requires a long-term, sustainable strategy and a great deal of **energy** and **repetition**. Winning over depends on good ideas, suitable content, holistic support, and follow-through.
Loyalty Reward Programs with AWS Blockchain
Tags: loyalty, aws, blockchain, hyperledger
Published: 2022-05-07 16:15:45

A 𝙣𝙚𝙬 𝙩𝙧𝙚𝙣𝙙 is emerging in the world of 𝙡𝙤𝙮𝙖𝙡𝙩𝙮 𝙥𝙧𝙤𝙜𝙧𝙖𝙢𝙨 for businesses around the globe. 𝙋𝙖𝙧𝙩𝙣𝙚𝙧𝙨𝙝𝙞𝙥-𝙗𝙖𝙨𝙚𝙙 𝙡𝙤𝙮𝙖𝙡𝙩𝙮 𝙥𝙧𝙤𝙜𝙧𝙖𝙢𝙨, in which participating companies 𝙖𝙜𝙧𝙚𝙚 𝙩𝙤 𝙘𝙧𝙚𝙖𝙩𝙚 𝙖 𝙘𝙪𝙧𝙧𝙚𝙣𝙘𝙮 that can be 𝙚𝙭𝙘𝙝𝙖𝙣𝙜𝙚𝙙 𝙖𝙩 𝙖𝙣𝙮 of the participating companies’ marketplaces, is growing in popularity. 


Customers encounter these programs regularly—for example, flight passengers might 𝙪𝙨𝙚 𝙩𝙝𝙚𝙞𝙧 𝙥𝙤𝙞𝙣𝙩𝙨 𝙩𝙤 𝙧𝙚𝙙𝙚𝙚𝙢:

(1) 𝙝𝙤𝙩𝙚𝙡 𝙧𝙤𝙤𝙢𝙨, 
(2) 𝙩𝙧𝙖𝙣𝙨𝙥𝙤𝙧𝙩𝙖𝙩𝙞𝙤𝙣, or 
(3) 𝙖𝙢𝙚𝙣𝙞𝙩𝙞𝙚𝙨 at a hotel 

included in a 𝙥𝙖𝙧𝙩𝙣𝙚𝙧𝙨𝙝𝙞𝙥 𝙥𝙧𝙤𝙜𝙧𝙖𝙢.

The 𝙗𝙡𝙤𝙘𝙠𝙘𝙝𝙖𝙞𝙣 is currently the 𝙡𝙚𝙖𝙙𝙞𝙣𝙜 𝙩𝙚𝙘𝙝𝙣𝙤𝙡𝙤𝙜𝙮 that companies are using to 𝙟𝙤𝙞𝙣 𝙩𝙝𝙚𝙨𝙚 𝙥𝙖𝙧𝙩𝙣𝙚𝙧𝙨𝙝𝙞𝙥 𝙣𝙚𝙩𝙬𝙤𝙧𝙠𝙨. Simply put, 𝙩𝙝𝙚 𝙗𝙡𝙤𝙘𝙠𝙘𝙝𝙖𝙞𝙣 𝙝𝙚𝙡𝙥𝙨 𝙪𝙨 𝙩𝙤 𝙘𝙧𝙚𝙖𝙩𝙚:

(1) a 𝙨𝙚𝙘𝙪𝙧𝙚, 
(2) 𝙧𝙤𝙗𝙪𝙨𝙩, 
(3) 𝙥𝙧𝙞𝙫𝙖𝙩𝙚, 
(4) 𝙩𝙧𝙖𝙣𝙨𝙥𝙖𝙧𝙚𝙣𝙩 

𝙙𝙖𝙩𝙖𝙗𝙖𝙨𝙚 where each partner 𝙨𝙚𝙩𝙩𝙡𝙚𝙨 𝙘𝙪𝙨𝙩𝙤𝙢𝙚𝙧𝙨’ 𝙩𝙧𝙖𝙣𝙨𝙖𝙘𝙩𝙞𝙤𝙣𝙨 directly with each other.

Amazon 𝙈𝙖𝙣𝙖𝙜𝙚𝙙 𝘽𝙡𝙤𝙘𝙠𝙘𝙝𝙖𝙞𝙣, a fully managed blockchain service that makes it easy for users to:

(1) join 𝙥𝙪𝙗𝙡𝙞𝙘 𝙗𝙡𝙤𝙘𝙠𝙘𝙝𝙖𝙞𝙣 𝙣𝙚𝙩𝙬𝙤𝙧𝙠𝙨 or 
(2) create and manage 𝙨𝙘𝙖𝙡𝙖𝙗𝙡𝙚 𝙥𝙧𝙞𝙫𝙖𝙩𝙚 𝙣𝙚𝙩𝙬𝙤𝙧𝙠𝙨, works under two popular frameworks: 
- 𝙃𝙮𝙥𝙚𝙧𝙡𝙚𝙙𝙜𝙚𝙧 𝙁𝙖𝙗𝙧𝙞𝙘 or 
- 𝙀𝙩𝙝𝙚𝙧𝙚𝙪𝙢. 


Thanks to Arturo Minor Bahena and Pedro Pimentel for their blog post which focuses on the Hyperledger Fabric framework

𝙂𝙧𝙤𝙬 𝙖𝙣𝙙 𝙀𝙭𝙥𝙖𝙣𝙙 𝙇𝙤𝙮𝙖𝙡𝙩𝙮 𝙍𝙚𝙬𝙖𝙧𝙙 𝙋𝙧𝙤𝙜𝙧𝙖𝙢𝙨 𝙒𝙞𝙩𝙝 𝘼𝙢𝙖𝙯𝙤𝙣 𝙈𝙖𝙣𝙖𝙜𝙚𝙙 𝘽𝙡𝙤𝙘𝙠𝙘𝙝𝙖𝙞𝙣 (𝙋𝙖𝙧𝙩 𝙊𝙣𝙚)
https://aws.amazon.com/blogs/industries/grow-and-expand-loyalty-reward-programs-with-amazon-managed-blockchain-part-one/

𝙎𝙩𝙖𝙮 𝙩𝙪𝙣𝙚𝙙 𝙗𝙮 𝙛𝙤𝙡𝙡𝙤𝙬𝙞𝙣𝙜
https://www.linkedin.com/feed/hashtag/didAbRyouAbRknowAbRthat/


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnltongtjshliph5733k.png)
[Login App using Appwrite]
Tags: appwritehack
Published: 2022-05-07 16:14:24


**Overview of My Submission**
_I didn't had a lot of time, and even less ideas, so I created a Login App with google's OAuth and custom signin and signup features. 
Easy to use and made possible with the use of appwrite and tech stacks.
I am passionate about technology, innovation and big challenging tasks on my to-do list.
That makes me want to learn more and keep up with building something.
I want to Bring things to life with code._

**Submission Category:**
_Wacky Wildcards_

**Link To Code**
https://github.com/MrKrishnaAgarwal/Login-Appwrite-App

**Additional Resources / Info**
**Screenshots/demo videos**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjdpr2bu698ub3cf9i2d.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cid0yfhz8gir9u4gy3pe.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyzorrp6qbjysnwbd1jl.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ku8n8t1tzegmbcyt1hwr.png)
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu25ncq2glhb21gokron.png)
![Short demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwhe495l2cw297ffxf79.gif)

**Tech Stack Used**
React
AppWrite
CSS
HTML

Created by Krishna Agarwal
GitHub: @MrKrishnaAgarwal `https://github.com/MrKrishnaAgarwal`

**Conclusion** 
I'm new to appwrite and started with this little thing but want to explore more appwrite and it's features in future.
This project was super fun to do.
Nestjs: Introduction and setup
Tags: javascript, typescript, tutorial, programming
Published: 2022-05-07 15:46:25

Nestjs is a Nodejs framework to build complex backend applications using Typescript instead of javascript for better code reliablity and less bugs.

## Why use Nestjs
So why should you use Nestjs instead of just using express ? the answer is that Nestjs is kinda more opinionated on how you structure your application code, meanwhile express let's you freely organize the app howerver you want and that may lead to bad structure especially when your application grows in size and complexity, also Nestjs provides support for database connection, authentication, caching, graphql, testing and many other things out of the box.
also, keep in mind that Nestjs uses express behind the scenes but you can change it to fastify which is another good nodejs framework, so why not put the time to learn Nestjs ?

## How a Nestjs app is structured
Nestjs applications are divided into modules, each module takes care of 1 feature of that application.
let's take an Ecommerce app as an example and divide it to Nests modules it would look something like this:

![App diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph9yx0f2jb4kt3hth32m.png)
and each module contains:
- a controller where you define the different routes for that feature

- a service that contains all the business logic related to that feature

- guards to prevent access for a certain route until a condition is met (authentication for example)

- a repository to access the database

- data transfer objects to ensure the data coming from the client is valid

- pipes to transform data

## Getting started with Nestjs
First you need install Nodejs on your sistem, then install the Nestjs cli globally

```
npm install -g @nestjs/cli
```
then create a new project

```
nest new project-name
```
now you can open your editor and start coding the app