teleren/devto huggingface dataset:
Kotlin Springboot -- Part 5 Rest で全てのインスタンスを作って Driver まで動くようにする
Tags: kotlin, ca
Published: 2022-09-03 16:31:57


## why

companion object を使うと外から呼び出しやすいが、Unit テストを書く時にうまくいかないため。

全てクラスのメンバー関数で作って、そのインスタンスを作って使うように修正する。

---

## REST

RestController で Template なしでシンプルにした。

```kotlin
personHoge = PersonHoge()
```

PersonHoge というクラスを使って変数を作ることで、
そのクラスのインスタンスを作ることができる。

これでまずは Driver のインスタンスを引数なしで作成する。
次に Gateway のインスタンスを、Driver のインスタンスを引数に渡して作成する。
さらに Usecase のインスタンスを、Gateway のインスタンスを引数に渡して作成する。

作成された Usecase のインスタンスの中のメンバ関数の getAllPersons を呼び出して、中身をとって return する。

これで companion object を使わなくても
Usecase で Gateway が呼べて
Gateway で Driver が呼べる。

```kotlin
@RestController
class PersonHandler {
  @GetMapping("/")
  fun root(): String {
    return "index2"
  }
  @GetMapping("/persons")
  @ResponseBody
  fun getPersons(): String {
    val personsDriver = PersonsDriver()
    val personsGateway = PersonsGateway(personsDriver)
    val personsUsecase = PersonsUsecase(personsGateway)
    val persons = personsUsecase.getAllPersons()
    print(persons)
    return persons.toString()
  }
}
```

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

---

## Usecase

Gateway のインスタンスを受け取るように作る。

```kotlin
class PersonsUsecase(val personsGateway: PersonsGateway) {
  fun getAllPersons():Persons {
    return personsGateway.getAllPersons()
  }
}
```

---

## Gateway

Usecase からインスタンスで呼び出すようになったため
comapanion object は必要なくなった。
渡された Driver のインスタンスを使って findAll した結果を return する。

```kotlin
class PersonsGateway(
  val personsDriver: PersonsDriver
) {
  fun getAllPersons():Persons {
    return personsDriver.findAll()
  }
}
```

---

## Driver 

最終地点なので何もインスタンスを受け取らない。
companion だけ解除した。

```kotlin
class PersonsDriver() {
  private val data:Persons = Persons(listOf(
    (Person(Name("taro"), Age(12))),
    (Person(Name("hanako"), Age(10))),
  ))
  fun findAll():Persons {
    return data
  }
}
```

---

## まとめ

Kotlin Springboot で
Rest <- Usecase <- Gateway <- Driver 
と伝搬していくためには

Rest で 
Driver のクラスから引数なしで Driver のインスタンスを作り
Gateway のクラスから Driver のインスタンスを引数にして Gateway のインスタンスを作り
Usecase のクラスから Gateway のインスタンスを引数にして Usecase のインスタンスを作り

Usecase のインスタンスの中身を使う。
I got Demigod badge🥳🥳🥳
Tags: badge, achievement, hackerearth, chiki1601
Published: 2022-09-03 16:18:34


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

#competetiveprogramming
#misspoojanilkumarpatel
#chiki1601
#development
#achievementunlocked
OCI Oracle Golden Gate Deployment Status for Extracts and Replicats
Published: 2022-09-03 16:18:13

Here is the next OCI utility to identify the status of extracts and replicats , there is no need to log into the deployment to identify the status and lag.

Check the Source Code here
https://github.com/abhilash-8/ogg_dep_status

 # #oracle #oci #oracledatabase #goldengate #curl #api #oraclecloud #oracledba #nabhaas
A discord server for Flutter developers.
Tags: flutter, dart, community, codenewbie
Published: 2022-09-03 16:12:56

Hello everyone,
I hope you are doing well.

Today, I created a discord server called " Programming Folks", whose aim is to mentor and answer the questions of upcoming Flutter developers.

If you are learning Flutter, then this is a great place to ask your questions and get mentorship from experienced Flutter developers.

I plan to get some experienced Flutter developers to join our discord server so they can mentor and assist developers who are learning Flutter.

Please join the Discord server from the following links if you are interested.

Discord server: https://discord.gg/PGhk6tSB

Kind regards,
MD Sarfaraj
Enhanced Switch Statement in Java
Tags: tutorial, beginners, programming, java
Published: 2022-09-03 15:52:35

If you are a developer, there is a high chance that you have already know a feature called _Switch_ in which has appeared in majority of programming languages. Using switch is often very lengthy and that is why sometime if-else statement is used. However, enhanced switch come into action to address this problem in the modern latest Java version.

To give you more understanding, I will give you an example of classic Java switch and also the enchanced one.

**Classic Switch**
```java
    public String toDayStringUsingSwitch(int dayIndex) {
        String result;

        switch (dayIndex) {
            case 1:
                result = "Sunday";
                break;
            case 2:
                result = "Monday";
                break;
            case 3:
                result = "Tuesday";
                break;
            case 4:
                result = "Wednesday";
                break;
            case 5:
                result = "Thursday";
                break;
            case 6:
                result = "Friday";
                break;
            case 7:
                result = "Saturday";
                break;
            default:
                throw new IllegalArgumentException("Invalid day index");
        }

        return result;
    }
```

**Enhanced Switch**
```java
    public String toDayStringUsingSwitch(int dayIndex) {
        return switch (dayIndex) {
            case 1 -> "Sunday";
            case 2 -> "Monday";
            case 3 -> "Tuesday";
            case 4 -> "Wednesday";
            case 5 -> "Thursday";
            case 6 -> "Friday";
            case 7 -> "Saturday";
            default -> throw new IllegalArgumentException("Invalid day index");
        };
    }
```

From the above example, you can see that the lines of code is reduced significantly by using the enhanced Java switch, and I personally think that the enchanced version of switch is more readable if compare to the classic version.

If you not yet familiar to Switch Statement, you might want to check the following article: [What Is Switch Statement](https://dev.to/luthfisauqi17/what-is-switch-statement-am4)

---

Image cover:
https://i.picsum.photos/id/650/1920/720.jpg?hmac=tz4eU3jOg0EzPCvHIjfNrmhsBBod2_2OpGBBmARc6B0
Error: useParams Not Destructuring In Typescript
Tags: typescript, webdev, react, programming
Published: 2022-09-03 15:35:54

I've seen this error in the code block below cause issues for developers who are just starting out with TypeScript. I'm going to show you how to solve this error.

```
const { token } = useParams();
```

First, you need to be aware that typescript can't destructure generic plain objects like `{}` which means useParams() is a generic. Peradventure, you might have also tried using this code block below:

```
const { token } = useParams() as any
```

The code block above is very wrong because `any` can't just be thrown around in this case. The keyword `any` should only be used when the object can be of any type, in our case here we know the properties and the type of our object, therefore, `any` shouldn't be used in this scenario.

_Side Note: If you know anything about the property of your object or what it will hold, then the keyword `any` shouldn't be used. It defeats the entire purpose of using typescript in this context._

Now, you might be wondering; what is the best possible solution. You need to tell TypeScript the value of the generic. Say, the value of our generic is a string. Then we write it like this:

```
const { token } = useParams<{token?: string}>()
```

From the above code, we're simply telling TypeScript that the value of our token is either a string or undefined. The `?` in our code is an optional operating chaining operator in TypeScript. By now, your error should have been solved and doubts cleared.
Devs: Single Quotes or Double Quotes on Attribute Values?
Tags: html
Published: 2022-09-03 15:34:14

I typically use single quotes in my code and reserve double quotes for literal strings. 

I'm in the middle of a HTML Certification course through W3 Schools and all of the examples have double quotes. The best practice section only states that HTML Attributes should be quoted and only uses double quotes in the examples. 

For current Devs who work on the front end, do you find there is any preference? 

Note: This is more for curiosity. I'm going to go with double quotes for the W3 course since that's what they recommend.
<bits/stdc++.h> in C++
Published: 2022-09-03 15:33:25

It is basically a header file that includes every standard library.

People do focus more on finding the algorithm to solve a problem than on software engineering.



𝘼𝙙𝙫𝙖𝙣𝙩𝙖𝙜𝙚𝙨 𝙤𝙛 𝙗𝙞𝙩𝙨/𝙨𝙩𝙙 𝙞𝙣 𝙘++
 
✔ In contests, using this file is a good idea, when you want to reduce the time wasted doing chores; especially when your rank is time sensitive.

✔ This also reduces all the chores of writing all the necessary header files.

✔ You don’t have to remember all the STL of GNU C++ for every function you use.


𝘿𝙞𝙨𝙖𝙙𝙫𝙖𝙣𝙩𝙖𝙜𝙚𝙨 𝙤𝙛 𝙗𝙞𝙩𝙨/𝙨𝙩𝙙 𝙞𝙣 𝘾++

✘ bits/stdc++.h is a non-standard header file of GNU C++ library. So, if you try to compile your code with some compiler other than GCC it might fail.

✘ Using it would include a lot of unnecessary stuff and increase compilation time.

✘ This header file is not part of the C++ standard and is, therefore, non-portable, and should be avoided.


 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gsabrbrpf2ii7l6p12l.jpg)


**Read related articles:**
[What is the difference between C and C++?](https://dev.to/jmrashed/what-is-the-difference-between-c-and-c-3fl7)
Earn new badges by building your cloud storage knowledge
Tags: aws, cloud, devops, beginners
Published: 2022-09-03 15:33:04

AWS Storage learning plans
AWS Training and Certification provides flexible Storage learning plans through AWS Skill Builder to help you build in-demand cloud storage knowledge by progressing from foundational to advanced concepts. AWS Storage digital learning badges are available to showcase your knowledge once you score 80% or higher on the associated online assessment for any of these learning plans. The Storage Learning plans include:

Storage Learning Plan: Object – Learn about Amazon Simple Storage Service (Amazon S3), which is built to store and retrieve any amount of data from anywhere.
Storage Learning Plan: Block – Learn about Amazon Elastic Block Storage (Amazon EBS) for both throughput and transaction intensive workloads.
Storage Learning Plan: File – Dive into Amazon EFS, a simple, serverless, set-and-forget, elastic file system and the Amazon FSx family of fully managed storage service solutions.
Storage Learning Plan: Data Protection and Disaster Recovery – Explore methods on how to centrally manage and automate backups across AWS services, ensure your data is protected, and examine best practices in disaster recovery using AWS storage services.
Storage Learning Plan: Data Migration – Learn about data migration services and strategies to move your data to the cloud.
Whether you’re an on-premises or cloud storage engineer, storage administrator, developer, solutions architect, or just interested in building your cloud storage knowledge, these learning plans and digital courses have been designed by our AWS Storage teams based on best practices to help you discover more possibilities with modern AWS Cloud Storage services and solutions.

“Earning seven AWS Storage badges in two months required discipline. To better assist our customers in optimizing and innovating, I’m driven to acquire in-depth knowledge in broad and complex areas. Common use cases include Data Migration, Data Protection and Disaster Recovery,” says Gokul Bala, Cloud Solutions Architect at Crayon, an AWS Premier Partner. “Thanks to these learning plans and badges, I’ve added value to my position as a Cloud Solution Architect, and provided value to other Crayon consultants who have found my expertise useful in differentiating their bids and delivery.”

Reference : https://go.aws/3Tt5vHo
Various Consistencies in Distributed Systems
Tags: distributedsystems, algorithms
Published: 2022-09-03 15:29:31

## Introduction
The word "consistency" has many meanings in computer science. In this article, we will explain the various consistency aspects of distributed system replication in a clear and straightforward manner.

## Serializability
State machine replication with linearizability sorts transactions into a sequence, and that sequence is guaranteed for all replicas. This is completely independent of real-world time.

Linearizability causes the problems shown in the following figure.

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

Linearizability only guarantees the update order between replicas, as shown in the figure above, and there is no way to know when that information will be transmitted to other replicas. So, it is possible to read the latest value only at the replica where the latest write was performed, but it is not guaranteed that the latest value can be read at the other replicas.

## Linearizability
The difference between linearizability and serializability is always the ability to read the latest value at any replica. Linearizability allows any replica to read the latest value.

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

The following words are synonymous with linearizability.

1. **Atomic consistency**
2. **Strong consistency**
3. **Immediate Consistency**
4. **External Consistency**

### How do we achieve linearization?
Linearizability wants to make the data look like one. To do so, simply lock the whole thing when updating. Therefore, guaranteeing linearizability sacrifices availability.

## Eventual Consistency
Eventual consistency means that if you stop writing to the database and wait for some unspecified length of time, then eventually all read requests will return the same value. This means that it is not known when updates to the database will stop, but it is guaranteed that identical values will eventually be read from all replicas. This is a very weak guarantee and says nothing about when the convergence will occur.
AWS Training and Certification launched exciting new courses...
Published: 2022-09-03 15:25:42

In August, AWS Training and Certification launched exciting new courses and updates including:
🕹️ A 5th role – security specialist – for AWS Cloud Quest
🇨🇳 🇪🇸 AWS Certified Cloud Practitioner exam and prep in 2 new languages
🧑‍💻 9 digital training courses on AWS products


Learn more: https://go.aws/3efnJvW
A small, self-contained, cross-platform web server for development
Tags: go, webdev, programming, javascript
Published: 2022-09-03 15:12:48

---
title: A small, self-contained, cross-platform web server for development
published: true
description: A small web server that allows to monitor and deliver files written in go.
tags: go,webdev,programming,javascript
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wmh6ba4v6hysyrwb4xuq.png
series: A small, self-contained, cross-platform web server
---

In addition to [researching and reading](https://dev.to/volker_schukai/a-cli-tool-for-providing-files-and-directories-over-http-with-directory-monitoring-3he1), I also wrote some code on a rainy sunday.

A small [development web server](http://download.schukai.com/tools/conan/) with the ability to monitor file changes and call external tools. 

[Here](http://download.schukai.com/tools/conan/) you can download the binary for Linux and Windows.

---

I have named it conan - the little wolf. 

![little wolf](https://media.giphy.com/media/aF8nZCmUEgmBO/giphy.gif)

---

In the video you can see how the autoload function works. At the bottom left I start the web server. Once with a command line option and once with a configuration file. 

In the upper right corner I make changes which are then automatically displayed without having to manually reload the browser.

{% embed https://youtu.be/_1c3YFXslHg %}

---

A simple configuration file `config.yaml` can be used to specify not only the standards such as the host and the port, but also the directories and files to be monitored.

The command is then executed when changes are made.

The keys are intuitive.

```yaml
Server:
  
  # Host: localhost:8080
  # Address: localhost
  # Port: 8080
  
  Path:
    Web: web
    
  Watch:
    - Path: .
      Command: esbuild --bundle --outfile={{ .WebPath }}/bundle.js --sourcemap
      Exclude:
        - ~$
        - ^\.
    
  Flags:
    FollowSymlinks: true
    
```

The programme is then started:


```bash
conan --config=config.yaml server serve
```

That's it!

---
Functions in SASS Tutorial
Tags: productivity, programming, tutorial, webdev
Published: 2022-09-03 15:01:47

Sass **functions** can receive arguments and return a single value.

They add an element of programming to writing CSS code, and we can now do math!

The standard math operators `+`, `-`, `*`, `/`, and `%` can all be utilized.

## An Example Function
The following function can accept two arguments, `$first-number` and `$second-number`. The value that is returned by the function is the sum of the two variables:
```sass
@function add-numbers($first-number, $second-number) {
  @return $first-number + $second-number
}
```
Say we want to replace the value of a `padding` property with the sum of two separate values.

We would call our function and pass in the arguments like so:
```sass
.box1 {
  padding: add-numbers(5px, 10px);
}
```
The resulting CSS output would be:
```sass
.box1 {
  padding: 15px;
}
```
Lets see the full code:
```html
<html>
  <head>
    <title>Page Title</title>
  </head>
<body>
<nav class="navbar">
  <ul>
    <li>Home</li>
    <li>Services</li>
    <li>Contact Us</li>
  </ul>
</nav> 
</body>
</html>
```
And our SASS:
```sass
@function add-numbers($first-number, $second-number) {
  @return $first-number + $second-number
}

.navbar {
  background-color: red;
  padding: add-numbers(5px, 100px);
  ul {
    list-style: none;
  }
  li {
    text-align: center;
    margin: 1rem;
  }
}
```
As you can see, functions help you write more readable and DRY Sass, as you can utilize reusable logic in a very efficient manner. This can make a huge difference when you start working on larger and more complex projects!

## Conclusion
If you liked this blog post, follow me on [Twitter](https://twitter.com/RembertDesigns) where I post daily about Tech related things!
![Buy Me A Coffee](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijinng8k7bf23v0o6gkj.png) If you enjoyed this article & would like to leave a tip — click [here](https://www.buymeacoffee.com/rembertdesigns)

### 🌎 Let's Connect

- [Portfolio](https://www.rembertdesigns.co/)

- [Twitter](https://twitter.com/RembertDesigns)

- [LinkedIn](https://www.linkedin.com/in/rrembert/)

- [Hashnode](https://rembertdesigns.hashnode.dev/)

- [Devto](https://dev.to/rembertdesigns)

- [Medium](https://medium.com/@rembertdesigns)

- [Github](https://github.com/rembertdesigns)

- [Codepen](https://codepen.io/rembertdesigns)
What Is Switch Statement
Tags: tutorial, beginners, programming, java
Published: 2022-09-03 15:00:41

Switch Statement is a feature in many programming languages that allow the programmer to eliminate numerous nested if-else constructs thus improving code clarity.

Take a look on the following example:
```java
public String toDayStringUsingIf(int dayIndex) {
        String result;

        if (dayIndex == 0) {
            result = "Sunday";
        } else if (dayIndex == 1) {
            result = "Monday";
        } else if (dayIndex == 2) {
            result = "Tuesday";
        } else if (dayIndex == 3) {
            result = "Wednesday";
        } else if (dayIndex == 4) {
            result = "Thursday";
        } else if (dayIndex == 5) {
            result = "Friday";
        } else if (dayIndex == 6) {
            result = "Saturday";
        } else {
            throw new IllegalArgumentException("Invalid day index");
        }

        return result;
    }
```

In the switch statement form:
```java
public String toDayStringUsingSwitch(int dayIndex) {
        String result;

        switch (dayIndex) {
            case 1:
                result = "Sunday";
                break;
            case 2:
                result = "Monday";
                break;
            case 3:
                result = "Tuesday";
                break;
            case 4:
                result = "Wednesday";
                break;
            case 5:
                result = "Thursday";
                break;
            case 6:
                result = "Friday";
                break;
            case 7:
                result = "Saturday";
                break;
            default:
                throw new IllegalArgumentException("Invalid day index");
        }

        return result;
    }
```

You can see individual cases more clearly in the switch statement, it makes other developer understand the code easily. <u>It may still looks longer than the if-else statement, but there are some improvement in the enhanced version of switch statement that makes the code more leaner.</u>. Even that Switch statement is more clearer than the if-else statement, there are several conditions that Switch statement cannot replace the if-else statement.

To learn more about the enhanced version of switch in Java, you could check this article: [Enhanced Switch Statement in Java](https://dev.to/luthfisauqi17/enhanced-switch-statement-in-java-2513)

To understand this concept even more, it is highly suggested to surf throughout the reference list down below.

---

References:
* https://docs.oracle.com/en/java/javase/13/language/switch-expressions.html
* https://www.w3schools.com/java/java_switch.asp
* https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
* https://www.baeldung.com/java-switch

Image cover
https://i.picsum.photos/id/42/1920/720.jpg?hmac=Cx0R9ISRIt0e1aHq11irofoe6qabiOl5Bpf668nqsiQ
Trabalhar em Casa
Published: 2022-09-03 14:59:22

Se você sempre quis trabalhar em casa para ter uma melhor qualidade de vida ou até mesmo ganhar mais dinheiro, está no lugar certo!

Seja por insatisfação do emprego atual, querer ser o seu próprio chefe, montar um negócio online ou ganhar renda extra.

Todos esses motivos são legítimos e você merece conquistar todos esses objetivos buscando o que é melhor para você.

Contudo, separei uma pequena lista das melhores opções onde é totalmente possível trabalhar em casa e viver da internet. Confira:

- Trabalhe sendo um afiliado digital
- Monte uma loja virtual
- Seja um freelancer
- Trabalhe fazendo importações de produtos
- Crie um blog
- Faça edições de vídeos

Veja mais informações: [Fórmula Negócio Online vale a pena?](Se você sempre quis trabalhar em casa para ter uma melhor qualidade de vida ou até mesmo ganhar mais dinheiro, está no lugar certo!

Seja por insatisfação do emprego atual, querer ser o seu próprio chefe, montar um [negócio online](https://apliqueiganhei.com/) ou ganhar renda extra.

Todos esses motivos são legítimos e você merece conquistar todos esses objetivos buscando o que é melhor para você.

Contudo, separei uma pequena lista das melhores opções onde é totalmente possível trabalhar em casa e viver da internet. Confira:

Trabalhe sendo um afiliado digital
Monte uma loja virtual
Seja um freelancer
Trabalhe fazendo importações de produtos
Crie um blog
Faça edições de vídeos

Veja mais informações: [Fórmula Negócio Online vale a pena?](https://apliqueiganhei.com/formula-negocio-online-funciona/)