teleren/devto huggingface dataset:
Object desctructuring
Tags: javascript, react
Published: 2022-11-07 01:38:57

# Object Destructuring

Object desctructuring is similar with array desctruturing concept, but you can't named the object name as you wish. Instead, you can create *alias* for it.

## Case 1: Destruct an `Object` Stored in `Variable/Constant`

Let's say, we have `function` that returns an object of detail user that fetched from API.

```jsx
const getUser = async (username) => {
	const user = await fetch(`/user/${username}`);
	const userJson = user.json();
	return userJson;
};
```

We call that above `function` and store the returned object .

```jsx
const main = async () => {
	const user = await getUser('estotriramdani');
	console.log(user.fullname);
	console.log(user.nickname);
};
```

Now, let's destruct that constant.

```jsx
const main = async () => {
	const { fullname, nickname } = await getUser('estotriramdani');
	console.log(fullname);
	console.log(nickname);
};
```

Make sure `fullname` and `nickname` are the same with the original object (before destructuring).
If we destruct like this

```jsx
const { name, nickname } = await getUser('estotriramdani');
```

`name` will `undefined` since the returned object has no `name` property.
So, if we want result like that (`name` property), we can give that property an alias by placed double colons `:` after `fullname` followed by alias name we want.

```jsx
const { fullname: name, nickname } = await getUser('estotriramdani');
```

`alias` is usefull when we get user with the same `function` (we only change the `username` params).

```jsx
const {
	fullname: fullnameUser1,
	nickname: nicknameUser1
} = await getUser('estotriramdani');
const {
	fullname: fullnameUser2,
	nickname: nicknameUser2
} = await getUser('john_doe');
```

Code above will avoid naming conflicts.

## Case 2: Destruct `Function` Parameter

This topic will extremely usefull in React. Because `props` (we will learn it later in React section) is an object.
We have function that receive an object.

```jsx
const createHouse = (params) => {
	const { name, length } = params;
	// do other stuffs
};
```

Code above is work just fine, but we can simplify it again.
The following code is equivalent with code that we've just wrote above.

```jsx
const createHouse = ({ name, length }) => {
	// do others stuffs
};
```

As we can see, we can destruct the object right in function params. By doing this way, we can eliminated a line.
Create a `function`  with this kind of parameter also can be called as `named parameter`. We can put `name` or `length` anywhere.

```jsx
createHouse({ name: 'Little House', length: 50 }); // it is valid
createHouse({ length: 50, name: 'Little House' }); // it is also valid!
```

See you on the next post!
Stop writing your SQL code inside your Go source files!
Tags: go, sql
Published: 2022-11-07 01:02:12

You are writing Go but you need to write some SQL, so you end up writing SQL inside your Go source code, this is not a problem as long as they are short queries, but when your queries take up more lines of code they become hard to read and to modify, besides the lack of indentation and coloring of the code make it worse.

So... What is the solution?

Keep your SQL code as SQL and your Go code as Go (don't write SQL inside Go).

For this you can use [sqload](https://github.com/midir99/sqload)!

`File users.sql`
```sql
-- query: FindUserById
SELECT first_name,
       last_name,
       dob,
       email
  FROM user
 WHERE id = :id;

-- query: UpdateFirstNameById
UPDATE user
   SET first_name = :first_name
 WHERE id = :id;

-- query: DeleteUserById
DELETE FROM user WHERE id = :id;
```

`File main.go`
```go
package main

import (
    _ "embed"
    "fmt"

    "github.com/midir99/sqload"
)

//go:embed users.sql
var sqlCode string

var Q = sqload.MustLoadFromString[struct {
    FindUserById        string `query:"FindUserById"`
    UpdateFirstNameById string `query:"UpdateFirstNameById"`
    DeleteUserById      string `query:"DeleteUserById"`
}](sqlCode)

func main() {
    fmt.Printf("- FindUserById\n%s\n\n", Q.FindUserById)
    fmt.Printf("- UpdateFirstNameById\n%s\n\n", Q.UpdateFirstNameById)
    fmt.Printf("- DeleteUserById\n%s\n\n", Q.DeleteUserById)
}
```

By keeping your SQL and Go separate you get the following advantages:

- Better support by your IDE or code editor (because you are now handling SQL code in its own file with its .sql extension).
- Your DBA will be able to easily find the code of each query that your project is running.
- SQL reuse, simply copy the same .sql files from one project to another.
- Keep your Go code free of SQL queries.

[sqload](https://github.com/midir99/sqload) is a library with 100% test coverage, free of dependencies
from third parties and their documentation has many examples.

[sqload](https://github.com/midir99/sqload) is inspired by Yesql (Clojure).

https://github.com/midir99/sqload
https://pkg.go.dev/github.com/midir99/sqload
Made Markdown parsing great again
Tags: opensource
Published: 2022-11-06 22:38:30

Hi, it is finally time to make a nice and stable markdown processing. The idea to implement came from [docusaurus](https://docusaurus.io/) which is the tool or I would probably even call it framework for creating documentation fast and easily. 

## Requriments 
The first important decision that I had to make to implement that feature is to find a nice package which parses markdown and converts it to HTML. My criteria were the following: 
- The package has to be relatively popular (a few thousand stars on GitHub
- It should have a typescript support

## Package
[Marked](https://www.npmjs.com/package/marked) package turned out to be an optimal solution for this case and I went ahead and used it. The installation and integration process was pretty straightforward. 
##  Implementation
The integration of the marked package shorted the `getSerializedHtmlFromMd()` function code from about 40 lines to just 6 lines and now it looks way cleaner and professional. Additionally, now it supports most or all markdown features which are available which is also a really good thing.  

## Implementation 
First of all, I created the [issue](https://github.com/Myrfion/izyum/issues/17) for [izyum](https://github.com/Myrfion?tab=repositories) where I briefly described what I want to do and how I am going to achieve it. After that, I made an implementation and created [PR](https://github.com/Myrfion/izyum/pull/18), which approved myself :)
Deja de escribir código SQL dentro de código Go, ¡la solución está aquí!
Tags: go, sql, spanish, showdev
Published: 2022-11-07 00:44:53

Estás escribiendo Go pero necesitas escribir un poco de SQL, por lo que terminas escribiendo código SQL dentro de tu código fuente Go, esto no es un problema mientras sean consultas cortas, pero cuando tus consultas ocupan más líneas de código éstas se vuelven difíciles de leer y de modificar, además la falta de indentación y coloreado del código lo hacen peor.

Entonces... ¿Cuál es la solución?

Mantén tu código SQL como SQL y tu código Go como Go (no escribas SQL dentro de Go).

¡Para esto puedes usar [sqload](pkg.go.dev/github.com/midir99/sqload)!

`Archivo users.sql`
```sql
-- query: FindUserById
SELECT first_name,
       last_name,
       dob,
       email
  FROM user
 WHERE id = :id;

-- query: UpdateFirstNameById
UPDATE user
   SET first_name = :first_name
 WHERE id = :id;

-- query: DeleteUserById
DELETE FROM user WHERE id = :id;
```

`Archivo main.go`
```go
package main

import (
	_ "embed"
	"fmt"

	"github.com/midir99/sqload"
)

//go:embed users.sql
var sqlCode string

var Q = sqload.MustLoadFromString[struct {
	FindUserById        string `query:"FindUserById"`
	UpdateFirstNameById string `query:"UpdateFirstNameById"`
	DeleteUserById      string `query:"DeleteUserById"`
}](sqlCode)

func main() {
	fmt.Printf("- FindUserById\n%s\n\n", Q.FindUserById)
	fmt.Printf("- UpdateFirstNameById\n%s\n\n", Q.UpdateFirstNameById)
	fmt.Printf("- DeleteUserById\n%s\n\n", Q.DeleteUserById)
}
```

Manteniendo tu SQL y Go separados obtienes las siguientes ventajas:

- Mejor soporte por parte de tu IDE o editor de código (porque ahora estás manejando código SQL en su propio archivo con su extensión .sql).
- Tu DBA podrá encontrar fácilmente el código de cada consulta que tu proyecto está corriendo.
- Reúso de SQL, simplemente copia los mismos archivos .sql de un proyecto a otro.
- Mantén tu código Go libre de consultas SQL.

[sqload](pkg.go.dev/github.com/midir99/sqload) es una librería con 100% de test coverage, libre de dependencias
de terceros y su documentación cuenta con muchos ejemplos.

[sqload](pkg.go.dev/github.com/midir99/sqload) está inspirada en Yesql (Clojure).

https://github.com/midir99/sqload
https://pkg.go.dev/github.com/midir99/sqload
Counting to 1 Billion (Node vs. Bun)
Tags: node, webdev, javascript, programming
Published: 2022-11-07 00:02:54

I was inspired by Ishaan Sheikh's post here on counting to 1 billion: https://dev.to/sheikh_ishaan/count-to-1-billion-20de.

I wanted to see if there was a sizable performance difference in counting to 1 Billion in Javascript when using Node vs. when using Bun.

I ran this program and timed it using the MacOS `time` utility:

```javascript
for (let i = 0; i < 1_000_000_000; i++) {
}
```

I ran it with Node and got:

```
node counter.js  0.46s user 0.03s system 84% cpu 0.578 total
```

Then, I ran it with Bun and got:

```
bun counter.js  0.90s user 0.01s system 99% cpu 0.912 total
```

I was surprised to see in something as simple as this the time difference was double for Bun vs. Node! Especially since Bun claimed that it was faster than Node since it uses Javascript Core instead of V8.

To verify this was the case, I tested it on 10,000,000,000. Here were the results:

```
node counter.js  7.87s user 0.06s system 97% cpu 8.118 total
```

```
bun counter.js  8.79s user 0.02s system 99% cpu 8.820 total
```

Clearly, it seems that there may be some bun startup/initialization cost that is causing the counting to be slower than Node. I'm curious to know where this is coming from.

Thanks to [writethrough.io](https://writethrough.io/) for helping me write this article.
Kubernetes Cluster with Kind
Tags: kubernetes, beginners
Published: 2022-11-06 23:59:06

## Introduction

In this article, I  will show you how you can create a Kubernetes (k8s) cluster using the tool Kind. Kind is a tool that uses docker to create the cluster nodes that may be used for local development or CI, to know more about it, you can go to the [Kind official page](https://kind.sigs.k8s.io/).


## Environment

- Linux Mint 20.2
- Docker version 20.10.12, build e91ed57


## Install

To use Kind, we need to have installed Docker,  [How to install Docker](https://docs.docker.com/engine/install/).


After installing Docker or if already you had installed it, you need to check if the docker daemon is installed and running.

```
docker info
```


Now you can install Kind using the steps in the [Kind official docs](https://kind.sigs.k8s.io/docs/user/quick-start#installation) in the install section.

This my case, I used the steps for Homebrew:

```
brew install kind
```

After that, we can check the Kind installation with this command

```
kind version                                           
```

You should see something like this `kind v0.11.1 go1.16.4 linux/amd64` 


## Creating a K8s Cluster

To create a k8s cluster with kind with a basic configuration you can execute this command

```
kind create cluster
```

**Output:**
```
$ kind create cluster 
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.21.1) 🖼
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Have a nice day! 👋
```

It is all, you created a k8s cluster with basic kind config, to check your cluster you can use 

```kind get clusters```

to see your cluster name and 

```kind get nodes```

to list nodes' names.

**Output:**

```
$ kind get clusters
kind

$ kind get nodes     
kind-control-plane
```

Now you can use `kubectl` command to interact with your cluster. To see how to install kubectl please see this documentation [install kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)

## References

- [K8s tool kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
- [K8s tool kind](https://kubernetes.io/docs/tasks/tools/#kind)
- [Docker install](https://docs.docker.com/engine/install/)
Error [ERR_MODULE_NOT_FOUND]: Cannot find module
Tags: cli, node, es6, javascript
Published: 2022-11-06 23:25:53

---
title: Error [ERR_MODULE_NOT_FOUND]: Cannot find module
published: true
description: 
tags: cli, node, es6, js
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-11-06 23:21 +0000
---


If you want to use import instead of require you need to add `module` part to your package.json 

```json
"type":"module"  
```



But don't forget you need to import with file extension. 

```js 

import { ErrorMessage } from "../alerts.js"; // WORK

import { ErrorMessage } from "../alerts"; // WONT WORK!
```


SOURCE: https://stackoverflow.com/a/67105989/10694425
Ng-News: Episode 22/44
Tags: angular, javascript, webdev, programming
Published: 2022-11-06 23:04:43

Jeremy Elbourne, an Angular team member, improvised and live-coded the board game "Boogle". Joey Perrott revealed some insights about Angular development at Google. And we have got two interesting articles about unit testing and Three.js in Angular.

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

## Building Games and Q/A with the Angular team

NgGaming used to be a monthly session on YouTube where participants could ask questions, and members of the Angular core team, mostly Jeremy Elbourne and Mark Thompson, responded.

The format changed a little bit. The focus is now more on Jeremy live-coding some popular board games.

Jeremy has an improvised style, which means we see him struggling, as we all do when we write code.

And this is what sets it apart from other sessions, where presenters rehearsed everything to perfection.

You can see and learn how Jeremy approaches a problem and how he tries to solve it.

{% embed https://youtu.be/-2KgP-b_QRM %}

## A View From the Inside of the Angular Team with Joey Perrott

Joey Perrott, a member of the Angular team, participated in the latest episode of "The Angular Plus Show", a podcast. In the first part of the episode, he gave some insider information.

Google has an internal repository but syncs it with the official one on GitHub. So this means that Google has no Angular internal stuff, which they hide from us.

Three teams are mainly responsible for Angular: The framework team, the tooling (Angular CLI), and the components, which is Angular material.

They also talked about Bazel, Google's open source build orchestration tool. It can build artifacts quickly but is also very time-consuming, i.e., you have to write many build files.

{% embed https://podcasts.apple.com/us/podcast/s4-e11-a-view-from-the-inside-of-the/id1501989276 %}

## Articles

### Renan Ferro: Understanding and Implementing Three.js with Angular and creating a 3D Animation

Renan Ferro wrote an article on integrating Three.js natively into an Angular application. Three.js is an abstraction library over WebGL, and you use it to generate 3D graphics in the browser. Natively means you don't need a glue library like ngx-three-js or something similar.

{% embed https://dev.to/renancferro/understanding-and-implementing-threejs-with-angular-and-creating-a-3d-animation-3eea %}

### Quantarius Ray: Angular Testing: Unit Testing

Another article is from Quantarius Ray. He discusses the differences between unit and component tests and especially in which cases unit tests make sense. According to Quantarius, you test only a class in unit tests, and in component tests, you go via the DOM.

[Link to Article](https://medium.com/ngconf/angular-testing-unit-testing-a843fa6f11c9)

## Spectator 12

NgNeat released with version 12 a new major of its popular testing library Spectator. It has Angular 14.2 as a minimum requirement.

{% embed https://ngneat.github.io/spectator/ %}
A Little Elixir for Pythonistas
Tags: elixir, beginners, programming
Published: 2022-11-06 22:14:18

I was reading Elixir in Action by Saša Jurić and came across an example that, with a little modification, demonstrated some useful similarities between Elixir and Python, which might be helpful for another Elixir noobs like me who know a little Python. This straightforward example takes a list of names and prints them with an index. 


![Elixir list comprehension example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgm622cz1w3wct0ug99h.png)

It begins with a list construction that looks exactly like what you'd see in Python. The following line is an Elixir list comprehension. It begins with `for` but otherwise is similar to list comprehensions in Python. You'd read it in English as: "For each {name, index} pair in Enum.with_index(employees), print the formatted result."

`IO.puts()` is similar to `print()`, and the `"#{variable}"` syntax is quite similar to Python's f-strings.

This list comprehension is iterating over `Enum.with_index(employees)`, which is analogous to Python's `enumerate()` in that it returns a tuple of `{value, index}` for each element of the iterable, although in Elixir the value comes first, then the index.

In Python, the final list comprehension might look like this:

`[print(f"{idx}.  {value}") for idx,value in enumerate(employees)]`

I'll leave it to you to decide if either is more clear than the other. My experience so far is that Elixir comprehensions are more flexible and powerful. 

For example, if your comprehension generates tuples, you can use the syntax `into: %{}` to build a map (a dictionary in Python) where the first element of the tuple is the key and the second element is the value.


![Elixir map example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xdts1dpomyt71eb66qg.png)

As with dictionaries in Python, you can get the value of a map entry by key using the `map_name[key]` syntax. 

Granted, you could do the same thing in Python using a dictionary comprehension:

`employee_dict = {key:value for (key, value) in enumerate(employees)}`

It's really been fun learning Elixir. I may pass along more tips and tidbits down the road.
'Rest care' can offer carers a genuinely necessary reprieve, yet many find getting to it troublesome
Tags: webdev
Published: 2022-11-06 21:55:24



To look for "relief" is to search for a break from exhausting work to re-energize and refocus. With regards to **Community Care**, sponsored reprieve care offers transitory help to more established individuals, which gives their carers a short alleviation or "rest" from their mindful obligations.

Carers care for a relative or companion who is fragile or has an incapacity, psychological maladjustment, substance reliance, constant condition, dementia, terminal or difficult sickness. Approaching reprieve administrations is critical, as only one out of five carers of a more established individual reports they can without much of a stretch sort out a companion or relative to take care of them.

Admittance to relief can likewise work on a carer's prosperity, empower them to go on in their mindful job, and defer the requirement for a more seasoned individual to move into long-lasting private consideration.

Nonetheless, in a new study, just 30.6% of carers revealed getting to rest in the earlier year, and simply over portion of the people who did were happy with it.

Understand more: Facing everyday life after a stroke: Loved ones give practically all post-clinic care, however who's really focusing on the guardians?
What is relief care?

Rest care is a help administration for more seasoned individuals intended to give their carers a transient break from their mindful obligations. It very well may be arranged or utilized in a crisis, for example, when a carer becomes sick.

In Australia, rest happens in different settings. The more formal private reprieve happens when a more established individual stays briefly in a matured consideration home. In any case, there is likewise a scope of local area based rest administrations. These incorporate "day stays" in nearby local area clubs, short term visits in committed "rest houses", as well as choices for [Community Care](https://optimisticcommunitycare.com.au/) laborers to offer help in individuals' own homes.

In 2020-21, 67,775 individuals got private relief care, and 46,527 got local area based reprieve care.

While this might appear as though a great deal, it is little contrasted and the 428,500 individuals who are the essential carer for an individual matured 65 years or more seasoned. Also, formal rest administrations represented only 3.2% of all administration use on matured [care](https://www.sharkpapers.com/review-order?o=Mzc2MzY4&u=5a52d47df50fba009ecf8fe03a26330a&order=SP-376368).
The definitive guide to migrating from Blogger to Docusaurus
Tags: blogger, docusaurus, blog, migration
Published: 2022-11-06 21:10:39

My blog used to be hosted on Blogger. I made the move to Docusaurus about 18 months ago and I'm delighted with the experience! To make it easier for others to do the same thing I've put together a migration guide.


[The definitive guide to migrating from Blogger to Docusaurus](https://blog.johnnyreilly.com/definitive-guide-to-migrating-from-blogger-to-docusaurus)
Nice cyber punk open source library with +90 HUD elements. we want to reach +1000 elements. (L)
Tags: react, librar, opensource, love
Published: 2022-11-06 19:28:44

you can check it out here: https://github.com/thiswallz/react-cyber-elements

I want to build over 1.000 HUD elements for free for all your fancy projects. I love all regarding cyberpunk, and actually we will be building an entire ecosystem for this.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95jmdhh0fds58ltnwjcr.gif)
 
thnks!