teleren/devto huggingface dataset:
Make it Short - Make it Better
Published: 2022-09-10 18:40:22

Hey there Fellow Javascript Coder!
Whether you're a experienced programmer or just someone who just started with javascript basics, this list of hacks is definitely for you! Please note that you might have already known one or more features of javascript from the below list, and that's **awesome**! But not everyone knows them 😉

So let's straight hop in!

![Let's start](https://c.tenor.com/4yEqi3nmP0QAAAAM/steven-he-glasses.gif)

---

## Convert Any Datatype to Boolean

By using `!!` in front of any variable, we can get the Boolean version of it! Let's see how:

```js
let variable = 100;
variable = !!variable // returns true
variable = 0;
variable = !!variable //returns false
```

Isn't this easier to write and use in real life?
Well, this is more easier:
```js
let variable = 100;
if(variable) console.log("True"); // Logs True!
variable = 0;
if(variable) console.log("True"); // doesn't log anything
```

## Find whether a property exists in an Object

If you were using `if(obj.property)` or `if(obj["property"])` till now, it's time to make your code more readable by using `if("property" in obj)`.

## Become Lazy and truncate Array just as you wanted

This just works!

```js
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
console.log(arr); // Logs all the 10 elements
arr.length = 5;
console.log(arr); // Logs only [1, 2, 3, 4, 5] Holy Moly!?
```

## Remove Duplicates from your Array

```js
let arr = [1, 2, 1];
console.log(arr); // [1, 2, 1], as expected.
arr = Array.from(new Set(arr));
console.log(arr); // [1, 2], and cheers!
```

## Avoid Server Lag during 2 or more Array Concats
Instead of using this:
```js
let list1 = ['a', 'b', 'c', 'd', 'e'];
let list2 = ['f', 'g', 'h', 'i', 'j'];

let list = list1.concat(list2);
```

Try using this alternative:
```js
let list1 = ['a', 'b', 'c', 'd', 'e'];
let list2 = ['f', 'g', 'h', 'i', 'j'];

let list = list1.push.apply(list1, list2)
```
The latter code saves your server from high memory consumption because the first code creates a new array in memory, whereas this one works with the `list1` array instead of creating a new array.

---

I hope I made you learn something new today! If I did, consider hitting a like, a unicorn and a bookmark on this Post! Also you can hit a star on my current project - Reejs at https://github.com/rovelstars/reejs , a star means a lot to me!

Have a nice day 🙃!

P.S. Comment down below if you have any ideas on what the next blog should be, I will try my best if I can write on it!
First Blog
Tags: opensource
Published: 2022-09-10 17:24:07

Hi, my name is Alan.  I’m in my seventh semester of the BSD program, and am planning on graduating next year.  I took this course mainly because I am interested in learning new things.  I want to expand my knowledge, and this course seems like a challenging yet rewarding way of learning practical skills I can apply throughout my career.  Open Source is completely new to me, so I am excited to see what it has in store.

Like I mentioned before, I hope to learn as much as I can this term.  I want to gain more experience in an environment that will encourage me to study new things, and I want to work on projects that help me explore new ideas.

The GitHub repository I researched was primarily about Python frameworks and other related resources.  It was the first one that stuck out to me; I previously took a course on Python, but my experience with it is quite limited.  That is why I explored this repository to try and see if it could convince me to try developing using Python.  After all, doesn’t ‘awesome-python’ sound enticing?

(Here is the link: https://github.com/vinta/awesome-python)
Kotlin Springboot -- Part 9 Domain に中身の比較のドメインロジックを生やして活用する
Tags: kotlin, springboot, ca
Published: 2022-09-10 18:40:04


## why

ドメインロジックの理解のため。
Person 全てではなく、Age が 10 未満の Person のみを返す機能を実装したかったから。

---

## なぜ Gateway などには書かないか

Gateway は単に Driver の結果を Domain に詰め替える為の場所であるべきだから。

---

## なぜ Usecase にロジックを書かないか。

Usecase は単にビジネスロジックを書く場所であり、
ここをみたらビジネスの都合で何をしているのかわかってほしい。
だから細かい実装の内容は書くべきではない。

---

## Usecase に処理の呼び出しを書く

```kotlin
  fun getU10Persons():Persons {
    val persons = personsGateway.getAllPersons()
    val age = Age(10)
    return persons.filterByLessThan(age)
  }
```

Gateway から呼び出したドライバーの処理をドメインに詰め替えた結果。

このドメインの中のロジックに、さらに Age ドメインを渡して実行する。

---

## Domain に処理を書く

Persons のドメインに書いて終わりではない。

```kotlin
data class Persons(val list: List<Person>) {
  fun filterByLessThan(age: Age): Persons {
    return Persons(this.list.filter { it.isLessThan(age) })
  }
}
```

Persons は内部で Person (this) 一つ一つをマップして
条件に当てはまるものだけを返している。
その条件を Person のドメインに書いている。

```kotlin
data class Person(val name: Name, val age: Age) {
  fun isLessThan(age: Age): Boolean {
    return this.age.isLessThan(age)
  }
}
```

Person のドメインでは Person の Age に生えている isLessThan の結果を返している

This で中身の Age インスタンスにアクセスできる。


```kotlin
data class Age(val value: Int) {
  fun isLessThan(other: Age): Boolean {
    return this.value < other.value
  }
}
```

そして Age の中に比較関数の本体がある。

this.value が Person ドメインに入っている Age の実際の数値。

それに対して引数の比較対象は other.value にしている。

これ(this)と他(other)の比較。そういう意味。

これで Persons ドメインで isLessThan というドメインロジックが機能する。

---

## 結果

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



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

query でかえられるともっと面白くて実用的かも知れない

```kotlin
  @GetMapping("/persons/{age}")
  @ResponseBody
  fun getPersonsByAge(@PathVariable("age") age: Int): String {

    val persons = personsUsecase.getPersonsByAge(Age(age))
```

Rest で PathVar で Int で受け取って
Usecase に渡すまえに　Age に詰めて

```kotlin
  fun getPersonsByAge(age: Age):Persons {
    val persons = personsGateway.getAllPersons()
    return persons.filterByLessThan(age)
  }
```

後は中で呼べば引数からの絞り込みが完成した。使いやすい。 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3ojxbdel6qxk9xz7duo.png)
Structuring SEO and Format of a page in Next.js Effectively
Tags: nextjs, typescript, javascript, react
Published: 2022-09-10 18:33:28

Organizing your Next.js application and using components.

Imagine you want to use Next.js to build an application and that you want each page to have a distinct SEO strategy as well as the same header, footer, and navbar.

What you can manage to do?

The simple option is to build a shared component that is called repeatedly on each page.

But, You might try this 👇


- I hope you have already developed a Next.js app before reading this.
If not, visit this page 👉 [https://nextjs.org/docs/getting-started](https://nextjs.org/docs/getting-started)


- Create two components with the names **Format** and SEOSetup in a new folder called **components** inside the src directory.
This component, “Format,” refers to the layout of the page.
Here, in this case, the layout of every page will be in this flow **Navbar** then **Main** content, and then a **Footer**.
And, We are therefore defining it below 👇

```
import { FC } from 'react';

import Footer from '../Footer';
import Navbar  from '../Navbar';

const Format: FC = (props) => {
  return (
    <>
      <Navbar />
      <Main>{props.children}</Main>
      <Footer />
    </>
  );
};

export default Format;
``` 


- In **SEOSetup**, we’re really constructing a common tag with data supplied as props for the meta and title tag fields.
So that we may utilize this **SEOSetup** component each time we need to define SEO-related information on a page rather than creating a head tag repeatedly.

```
import Head from 'next/head';

export interface MetaData {
  title: string;
  description: string;
}

const SEOSetup: FC<MetaData> = (props) => {
  const {
    title,
    description,    
  } = props;

return (
    <Head>
      <title>{title}</title>
      <meta name={'title'} content={title} />
      <meta name={'description'} content={description} />
    </Head>
  );
};

export default SEOSetup;
```


- Finally, utilize them on a page. Here we are just wrapping the page with the Format component and setting up SEO with our custom **SEOSetup** tag.

```
import type { NextPage } from 'next'

import Format from '../components/Format';
import SEOSetup from '../components/SEOSetup';

const Home: NextPage = () => {
  return (
    <Format>
      <SEOSetup
        title="This is title of the Home Page"
        description="This is description of Home Page"
      />
      <div>
        This is Home Page.
      </div>
    </Format>
  )
}

export default Home;
```


⭐️ ⭐️ THE END ⭐️️️️️ ⭐️


I hope you find this helpful. 🙌
Please tell me in the comments. 📪

For more of this type of stuff, follow me on Twitter — [**@ShubhInTech**](https://twitter.com/ShubhInTech)
If you've made an error which went unnoticed, how did you address the error after you found out about it?
Published: 2022-09-10 18:22:09

I always find it hard to admit that I made a mistake. Especially since it's often my job to find mistakes and report them to management, I'm probably more sensitive than most people to the possibility of being blamed for something. And when a mistake is pointed out by someone else — especially if they're not happy about it — I tend to feel defensive and upset. So even when I know that my error has caused problems for other people, it isn't easy for me to say "oops."

But when someone else points out a problem with my work, I know that some kind of apology is in order.

If there are any issues with what I've done, I try to acknowledge them immediately and apologize as best I can. For example, if there's a problem with my code (which happens more often than you might think), then I'll try to fix it as quickly as possible — especially if there are bugs in production or test environments. If there's an issue with documentation, then I'll update the docs as soon as possible (and ideally before anyone notices).
Demonstrate an awareness of the functional adaptations needed for prehension when underlying systems have been altered.
Published: 2022-09-10 18:17:21

The hand is an extremely complex and intricate structure, consisting of numerous bones, muscles, ligaments, and nerves. It is also capable of a very diverse set of movements. The hands are used for a variety of purposes, including grasping, holding, pushing and pulling, as well as fine motor skills such as writing and typing (Kalsi-Ryan et al., 2020). The functions that depend on the use of the hand can be subdivided into two categories: prehension (the ability to grasp objects) and manipulation (the ability to move objects).

Prehension refers to the act of grasping, holding or manipulating objects, and is an important component of human hand function (Kalsi-Ryan et al., 2020). The ability to prehend objects is dependent upon a number of factors, including the size and shape of the object, the strength of the grasp, and fine motor coordination. The brain must also be able to interpret the sensory information received from receptors in the hand in order for prehension to occur effectively.

The functional adaptations needed for prehension when underlying systems have been altered include:

1) The ability to understand how objects are grasped depends on a number of factors including their size and shape as well as their weight and texture. The system used to detect shape and size involves visual acuity, posture and muscle strength. This system can be affected by neurological conditions such as stroke or Parkinson's disease which may result in poor vision or tremors that impair balance and coordination.

2) The ability to hold an object depends on muscle strength, particularly if it is heavy or bulky. If there is weakness due to neurological conditions such as stroke or Parkinson's disease then this could affect how securely an object can be held between two hands or fingers during prehension activities such as grasping food items or lifting objects off a shelf without dropping them.

References
Kalsi-Ryan, S., Riehm, L. E., Tetreault, L., Martin, A. R., Teoderascu, F., Massicotte, E., ... & Fehlings, M. G. (2020). Characteristics of upper limb impairment related to degenerative cervical myelopathy: Development of a sensitive hand assessment (graded redefined assessment of strength, sensibility, and prehension version myelopathy). Neurosurgery, 86(3), E292-E299.
Colima - How to use docker without Docker Desktop?
Tags: docker, containerapps, linux
Published: 2022-09-10 18:05:48



So you want to start using Docker and as a mac user you head over to [Install Docker Desktop on Mac](https://docs.docker.com/desktop/install/mac-install/) .

Setup seems super simple until you see this

`Docker Desktop is free for small businesses........but it requires a paid subscription for professional use.`

Now what do you do ? 
How to leverage the power of Docker on your macOS without paying a hefty subscription fees.

Enter **[colima](https://github.com/abiosoft/colima)**

Using colima is simple

```bash
brew install colima
brew install docker
```

That's it.
Now you can go on to use docker without any issues.

---

But let's dive deeper .

**What is colima? Why we needed Docker Desktop at all?**


**What are containers?**

A container is a sandboxed process on our machine that is isolated from all other processes on the host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker packages these capabilities  so that they are easy to use. 

**So Docker can only be run on Linux OS ?**

Yes, Docker as technology can only be run on Linux OS.

**How do i use docker on my Mac then ?**

You use Docker Desktop.

 It does 2 important things

- creates Linux VM on your host OS (Windows / Mac)
- forwards docker-cli commands from the host OS to created Linux VM

Thus we are able to run and use docker-cli on Windows/Mac even though these OS's do not support docker images/containers.

But since Docker Desktop is no longer free, we need alternatives.

**Lima**

> **Lima** is tool that launches Linux virtual machines with automatic file sharing, port forwarding, and containerd.
> **Li**nux on **Ma**c

Lima uses **QEMU** which is type-2 hypervisor, which virtualises the host operating system.

Hence we can now run linux virtual machine on top of our mac.

Also it gives use

- Filesystem sharing between mac host system and  virtual machine
- Automatic port forwarding

Lima setup a virtual machine with *containerd*  as container runtime on Mac
We can use *[nerdctl](https://github.com/containerd/nerdctl)* which `docker` cli replacement to run our containers.

**Colima**
> Colima : **Co**ntainers on **Li**nux on **Ma**c.

Colima builds on top of Lima, it configures the Docker CLI and set docker context such that you can use the `docker` client on macOS after `colima start` with no additional setup.

---

_Was this article useful to you? I’d love to hear your feedback, so don’t hold back. If you are interested in Kafka, Docker, microservices, or event streaming, or just have any questions, follow me on [Twitter] (https://twitter.com/suave_sethi)._ 


--

Sources
* https://stackoverflow.com/questions/58859039/what-is-the-use-of-docker-desktop
* https://docs.docker.com/desktop/install/mac-install/
* https://www.thoughtworks.com/en-in/radar/platforms/colima
* https://github.com/lima-vm/lima
Briefly explain the concept of “bureaucracy” and then evaluate the arguments that support Weber’s ideal type of bureaucracy?
Published: 2022-09-10 18:02:28

Max Weber argues that bureaucracy is the most efficient way to organize a business. He believes that bureaucracy has made it possible for modern society to function efficiently and effectively. Weber’s ideal type of bureaucracy can be defined as a hierarchical organization with clearly defined roles, rules and procedures.

Weber argues that bureaucracy is based on impersonal rules and procedures. In other words, it does not rely on the personalities of managers but rather on their qualifications. This argument is supported by the fact that bureaucracies are often very large organizations with thousands or even millions of employees. It would be impossible for each individual manager to know all their subordinates at such an organization; therefore, they must rely on position descriptions so they can assign tasks accordingly.

Another argument supporting Weber’s ideal type of bureaucracy is that bureaucracies are also very efficient because they have clearly defined goals and objectives that must be met within specified timeframes. Without this type of structure, companies would not be able to meet their targets or deadlines which could result in them losing money or customers which would ultimately lead to bankruptcy.
API, REST, and RESTful API Simplified.
Tags: api, restfulapi, programming, tutorial
Published: 2022-09-10 18:00:47

## What is API?

APIs are interface programs that let the components of two or more different applications, that are not fully integrated with each other, interact with one another.

## What is REST

REST is a method (a software architectural style) of building and using programs, i.e. APIs, that can effectively communicate with other applications.

## What does REST do?

Rest standardizes how APIs and applications function. While every application is different, using REST to guide development makes certain aspects of the design more predictable.

Rest uses HTTP requests like GET, PUT, POST, and DELETE to manage CRUD (Create, Read, Update, and DELETE) operations.

## What is RESTful?

While REST is a set of constraints, RESTful is an API that adheres to those constraints.

## Conclusion

A RESTful API (popularly referred to as ~~REST~~API is an API that conforms to the constraints of REST architectural style and allows for interaction with other RESTful services.

## Reference / Deep Diving

- https://devmountain.com/blog/what-is-the-difference-between-rest-and-restful-apis/#:~:text=It%20is%20a%20set%20of,is%20the%20set%20of%20constraints.

- https://www.redhat.com/en/topics/api/what-is-a-rest-api

- https://www.geeksforgeeks.org/know-the-difference-between-rest-api-and-restful-api/

- https://www.integrate.io/blog/what-is-a-mysql-rest-api/

## Acknowledgement

[Dev P Academy](https://devpacademy.hashnode.dev)

## Thanks for engaging 🎉.
What is the doctrine of double effect and share an example of how is it used or could be used to resolve conflicting moralduties
Published: 2022-09-10 17:59:31

The doctrine of double effect is an argument against the killing of non-combatants, even in a just war. The argument states that it is permissible to use force in order to achieve a good end, even if the means used is not itself morally good or neutral (Govindarajulu et l., 2019). In other words, one may commit an act which has both good and bad effects if the bad effect is not intended but merely foreseen as a side-effect of doing what is morally required (Govindarajulu et l., 2019). The doctrine of double effect can be traced back at least as far as St Thomas Aquinas (1225–1274) who used it to argue against killing civilians in wartime. It was later adapted by John Duns Scotus (1266–1308) who argued that it could never be morally permissible to kill innocent people (Uniacke 1984). The doctrine became controversial following its use by Catholic theologians during World War II who justified bombing civilian targets on the grounds that although it would cause civilian casualties, this was not intended but merely foreseen as an unavoidable side-effect of doing what was morally required; namely, defeating Hitler’s Germany by whatever means necessary.

For example, consider the following scenario:

A doctor has five patients who need organ transplants. Unfortunately, there are only five organs available for transplantation. If the doctor does not take action, all five patients will die within a week. However, if she performs an operation on one patient in order to save their life, she will also kill them (through organ removal).

The doctrine of double effect says that it is acceptable for the doctor to perform this operation because A) performing this surgery is morally good (saving someone’s life), B) removing this person’s organs is not morally bad (it’s not murder or something else), and C) since there are no other options for saving these patients’ lives, there’s nothing she can do to avoid killing them anyway (Govindarajulu et l., 2019).

References

Govindarajulu, N. S., Bringsjord, S., Ghosh, R., & Peveler, M. (2019). Beyond the doctrine of double effect: A formal model of true self-sacrifice. In Robotics and Well-Being (pp. 39–54). Springer, Cham.

Uniacke, S. M. (1984). The doctrine of double effect. The Thomist: A Speculative Quarterly Review, 48(2), 188–218.
How do you know if your perception or that of others is the correct interpretation of reality
Published: 2022-09-10 17:56:32

As a society, we are constantly trying to determine what is real and what is not. We see it in politics, religion, science, and art. There are many ways to determine what is real and what is not.The first method is the scientific method. This method uses several steps to prove or disprove an idea. The first step is to observe something in nature and record it as accurately as possible. Next, one must conduct experiments on this observation in order to test its validity. Finally, one must draw conclusions based on these results and then publish them so others can build upon them or disprove them as needed.

The second way is through logic and reason. The best example of this is math where one begins with simple facts like 1 + 1 = 2 and builds upon those basic facts by using logic until they reach complex conclusions like how many books would fit on a shelf if each book was 4 inches thick? This type of thinking allows people to make accurate predictions about the future based on past events or even predict things that have never happened before such as winning lottery numbers or predicting stock market trends months before they happen because of patterns already seen in history.
Is the Blockchain a myth?
Tags: blockchain, decentralised, ethereum, web3
Published: 2022-09-10 17:34:20

#why the whole noise about blockchain?

 Everyone who works or previously worked at finance institutions knows that 'accountant' or 'boss' who kept on adjusting dates and amount of certain transactions, or diverted huge sum of money from the company into their personal account ... sounds familiar right? 

  
Issues like this was what led two(2) researchers (Stuart Haber & Scott Stornette) in 1991 to work on a research project that would create a system where timestamp of documents, payment ledger cannot be tampered with which led to the discovery of ***blockchain***!

######Now, what is Blockchain?
>Blockchain is a list of record called blocks that stores 
data publicly and in chronological order. The information is encrypted using cryptography to ensure that the privacy of the user is not compromised and data cannot be altered. These Blocks have storage capacities and when filled are closed and linked to the previously filled block, forming a chain of data known as the blockchain.

You should know that this information(data) stored can not be edited which means it is irreversible and it is accessible for everyone who is part of the blockchain network to see.
 
Another interesting fact about blockchain is that it is decentralized what this means is that, these data is stored in thousands of devices across various locations, which prevents any attempt at altering the data if it was kept  in a central location and was controlled by specific people only.

It was on the foundation of ***blockchain*** that ***bitcoin*** was built!