teleren/devto huggingface dataset:
Code that changes together, stays together
Tags: programming, architecture, codebase
Published: 2022-08-02 07:50:18

---
title: Code that changes together, stays together
published: true
date: 2022-08-01 18:30:00 UTC
tags: [programming, architecture, codebase]
canonical_url: https://amol.me/posts/code-that-stays-together/
---

In traditional clean/layered/onion architecture code is organized in layers and so as the abstractions such as controllers, services, repositories.

![Clean Architecture](https://amol.me/assets/blog/clean-architecture.jpeg)

What I have seen most of people do is tried to organize code per layer by structuring code around those layer.
For example

```yaml
- src
 - controllers
 - services
 - use case
 - entities
 - repositories
```

In some projects, where I see team wanted to build modular monolith, they started to group based on some heuristic, that these pieces goes together probably we should modularize it.

```yaml
- src
 - module#1
  - controllers
  - services
  - use case
  - entities
  - repositories
 - module#2
  - controllers
  - services
  - use case
  - entities
  - repositories
```

I consider this way of modularizing code base as premature as it suffers from forcing you to make decision when you the least knowledge about the system. Sometimes this kind of modularizing felt so artificial.

So I was wondering 🤔

- how we could defer decision of making modularizing `code structure` as much as I can?
- How can I let `code structure` evolve itself organically?

There was another problem, If I want to make any changes, I have to make changes in upon 4-5 different packages such as controller, services, use case. In lot of cases I felt that it's lot of ceremony and dancing around so many files. There was urge of keeping things together.

Suddenly something clicked

> *"Neurons that fire together wire together" or "Family thats eats together, stays together"*

which leads to

> ***Code** thats **changes** together, stays together*


![vertical slice](https://amol.me/assets/blog/vertical-slice.png)

![vertical slice](https://amol.me/assets/blog/vertical-slice-detail.png)

As I move code which was changing together closer, 2 things happened

1. Code thats was coming closer, coupling between them increased(on vertical access).
2. Coupling between different slices started to drop

After spending more time with this approach, I learned that code thats shared across slices bubbled up and moved into core of the feature or is a domain concept. or it's just cross cutting concern. which then could moved up and finds it own place not just in code base but also conceptually.

In summary this approach provide me following flexibilities

- ✅ Code structure can evolve as organically as with our understanding of the domain concepts.
- ✅ Provide a way be more pragmatic per slice.
- ✅ Provide way of grouping which can scale with growing feature sets.

---

Final code structure was similar to 👇🏼

```yaml
- src
 - todo
  - api
   - dto
   - controller
  - find-todos
  - complete-todo
  - new-todo
  - todo
 - notes
  - api
   - dto
   - controller
  - new-notes
  - recent-notes
  - note
```
⛑ JSON serialization should never fail.
Tags: node, javascript, json
Published: 2022-08-01 18:22:24

---
title: ⛑ JSON serialization should never fail.
published: true
description: ⛑ JSON serialization should never fail.
tags: [nodejs, javascript, json]
# cover_image: https://raw.githubusercontent.com/ehmicky/design/main/safe-json-value/safe-json-value.png
---

<img src="https://raw.githubusercontent.com/ehmicky/design/main/safe-json-value/safe-json-value.svg?sanitize=true" width="700"/>

[`safe-json-value`](https://github.com/ehmicky/safe-json-value) is a JavaScript library to prevent `JSON.serialize()` from:
 - [Throwing](https://github.com/ehmicky/safe-json-value#exceptions)
 - [Changing types](https://github.com/ehmicky/safe-json-value#unexpected-types)
 - [Filtering](https://github.com/ehmicky/safe-json-value#filtered-values) or [transforming values](https://github.com/ehmicky/safe-json-value#unresolved-values) unexpectedly

Example:

```js
import safeJsonValue from 'safe-json-value'

const input = { one: true }
input.self = input

JSON.stringify(input) // Throws due to cycle
const { value, changes } = safeJsonValue(input)
JSON.stringify(value) // '{"one":true}"

console.log(changes) // List of changed properties
// [
//   {
//     path: ['self'],
//     oldValue: <ref *1> { one: true, self: [Circular *1] },
//     newValue: undefined,
//     reason: 'unsafeCycle'
//   }
// ]
```
[8/40 things about data] Analytics it’s a product, not a department
Tags: data, analytics
Published: 2022-08-01 18:12:54

When you have people asking for metrics and people extracting them from data. For the same metric, you’ll have as many definitions for a metric as people you have in the company.

Reporting is something that requires the same thing a digital product needs: owners, maintenance, clear definitions, improvements and you know, gives people what they want in a way that is useful for everybody in the company.

Many companies don’t consider analytics as a first-class citizen and end up spending more to have less quality.
How to deprecate functions in Nodejs?
Tags: node, javascript
Published: 2022-08-01 18:09:00

Did you know that the 𝗡𝗼𝗱𝗲𝗷𝘀 𝘂𝘁𝗶𝗹 module lets you deprecate functions and classes?

The 𝘂𝘁𝗶𝗹.𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗲 method wraps your function/class in a way that makes it deprecated. When your function/class gets called, a 𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻𝗪𝗮𝗿𝗻𝗶𝗻𝗴 will be emitted using the 𝘄𝗮𝗿𝗻𝗶𝗻𝗴 event. The emitted event will be outputted to 𝘀𝘁𝗱𝗲𝗿𝗿 the very first time the function gets called. After that, any later calls won't log the warning.


Related options and flags:

If either the --𝗻𝗼-𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 or --𝗻𝗼-𝘄𝗮𝗿𝗻𝗶𝗻𝗴𝘀 command-line flags are used, or if the 𝗽𝗿𝗼𝗰𝗲𝘀𝘀.𝗻𝗼𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 property is set to true prior to the first deprecation warning, the 𝘂𝘁𝗶𝗹.𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗲 method does nothing.

If the --𝘁𝗿𝗮𝗰𝗲-𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 or --𝘁𝗿𝗮𝗰𝗲-𝘄𝗮𝗿𝗻𝗶𝗻𝗴𝘀 command-line flags are set, or the 𝗽𝗿𝗼𝗰𝗲𝘀𝘀.𝘁𝗿𝗮𝗰𝗲𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 property is set to true, a warning and a stack trace are printed to 𝘀𝘁𝗱𝗲𝗿𝗿 the first time the deprecated function is called.

If the --𝘁𝗵𝗿𝗼𝘄-𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 command-line flag is set, or the 𝗽𝗿𝗼𝗰𝗲𝘀𝘀.𝘁𝗵𝗿𝗼𝘄𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 property is set to true, then an exception will be thrown when the deprecated function is called.

The --𝘁𝗵𝗿𝗼𝘄-𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 command-line flag and 𝗽𝗿𝗼𝗰𝗲𝘀𝘀.𝘁𝗵𝗿𝗼𝘄𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 property take precedence over --𝘁𝗿𝗮𝗰𝗲-𝗱𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻 and 𝗽𝗿𝗼𝗰𝗲𝘀𝘀.𝘁𝗿𝗮𝗰𝗲𝗗𝗲𝗽𝗿𝗲𝗰𝗮𝘁𝗶𝗼𝗻.

Check the snap below to see how it can be used.

Did you learn something new today?

Like and share this post, and follow me for more!

![deprecate functions in nodejs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fowd9g0mnubkna5cpqlu.png)
RapidAPI Client on VSCode
Tags: api, vscode, rapidapi, programming
Published: 2022-08-01 17:28:52


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fx5qrtm1rebydnae1b1p.png)
Are you a VScode lovers?

If you use a third app like Postman to test your API or another one, you know how it not easy.

RapidAPI created an easy and awesome extension for Visual Studio Code to test and deploy API rapidly.

How to get it
Go to the marketplace for VScode or to your editor and open the extension sidebar.
Search for the "rapid API client"
Then install it and enjoy.

You wanna know more? Look at the official guide.

[Replace API client with VScode](https://rapidapi.com/guides/replace-api-clients-with-vscode-using-the-rapidapi-extension)
Navigation menu animation
Tags: javascript, webdev, react, opensource
Published: 2022-08-01 17:06:19

A few months ago [I posted](https://dev.to/_eduard26/navigation-menu-animation-concept-52h6) about an animation concept I made for a navigation menu. 
Since then I made a [github repository](https://github.com/eduardconstantin/Navigation-menu-animation) and made some improvements (like adding more items inside the menu) based on the feedback I received.

![Small size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90dyl8qpbs0fyfsuzjjj.png)
![Extra large size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/no4fhu1tpk7rifb06630.png)

Any feedback is welcome!
VScode Tips: Cómo manejar múltiples cursores utilizando atajos del teclado
Tags: webdev, vscode, spanish
Published: 2022-08-01 16:43:00


VSCode es un poderoso editor de código con muchas funcionalidades y plugins, pero quizá la mejor manera de realmente utilizar su potencial para aumentar tu velocidad al utilizarlo es saber utilizar sus atajos de teclado.



Es un tema común entre desarrolladores: Usar atajos del teclado "mejora tu productividad" vs utilizar el mouse. Así que en este breve post verás como utilizar el teclado para crear múltiples cursores en tu editor.



## ¿Cómo agregar múltiples cursores en VSCode?



![Múltiples cursores en VSCode](https://cdn.sanity.io/images/cyypawp1/production/4eebcbebc356dd8fbcb29233f9fceacd52a656ce-588x337.gif)

Tener múltiples cursores te permite editar código más rápido y hacerlo con el teclado sería mucho más rápido y cómodo ¿no?



Estos son los atajos que necesitas aprender:

| Atajo | OS |
|--- | ---|
| ⌥ Opt + ⌘ Cmd and then ↑ or ↓ | Mac |
| Ctrl + Alt and then ↑ or ↓ | Windows |
| Shift + Alt and then ↑ or ↓ | Linux |
|  |  |

Para salir del uso de múltiples cursores y volver a un sólo cursor, presiona `Esc`.



Y para ver o modificar los atajos de teclado, tan solo debes ir a: “Archivo” → “Preferencias” → “Atajos de Teclado”.



![Footer Social Card.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1615457338201/5yOtr5SdF.jpeg)
✉️ [Únete a Micro-bytes](https://microbytes.matiashernandez.dev)         🐦 Sígueme en [Twitter](https://twitter.com/matiasfha)           ❤️ [Apoya mi trabajo](https://buymeacoffee.com/matiasfha)
#AzureIoT – Using a Raspberry Pi @Seeedstudio Grove Sensors 👀 in an ☁ Azure IoT Edge Module
Tags: englishpost, azureiot, grove
Published: 2022-08-02 13:29:13

---
title: #AzureIoT – Using a Raspberry Pi @Seeedstudio Grove Sensors 👀 in an ☁ Azure IoT Edge Module
published: true
date: 2022-08-01 16:40:13 UTC
tags: EnglishPost,AzureIoT,EnglishPost,Grove
canonical_url: 
---

Hi !

Last week during my sessions for #JulyOT, I had several questions about how to use SeeedStudio Grove sensors and actuators in custom Azure IoT Edge modules.

I’m updating my previous series of posts to how how to access to specifics sensors connected to the device and send telemetry, and more. I’m missing the Digital Twin part, however, I will wait some time to publish that series.

It all start here with this mess of device, wires, and sensors !

![](https://brunocapuano.files.wordpress.com/2021/08/raspberry-pi-grove-shield-with-sensors.jpg?w=646)

And the step-by-step posts:

#### Create an Azure IoT Module using Raspberry Pi and Grove Sensors

1. [Raspberry Pi + Grove Sensors, read temperature and humidity values](https://elbruno.com/2021/03/05/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-1-n/)
2. [Raspberry Pi + Grove Sensors, send temperature and humidity values as telemetry to Azure IoT Hub](https://elbruno.com/2021/03/08/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-2-n/)
3. [Raspberry Pi + Grove Sensors, create a Azure IoT Module to send temperature and humidity values as telemetry to Azure IoT Hub](https://elbruno.com/2021/03/09/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-3-n/)
4. [Raspberry Pi + Grove Sensors, publish and use the Azure IoT Module](https://elbruno.com/2021/03/10/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-4-n/)
5. [Raspberry Pi + Grove Sensors, notes on build and configuration](https://elbruno.com/2021/08/10/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-5-n/)
6. [Raspberry Pi + Grove Sensors, details on how to send a telemetry message and sample messages](https://elbruno.com/2021/08/17/azureiot-using-a-raspberry-pi-grove-sensor-in-an-%e2%98%81-azure-iot-edge-module-6-n/)

## References

- [Seeedstudio, Grove](https://www.seeedstudio.com/category/Grove-c-1003.html)
- [Create an IoT hub using the Azure portal](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal#:~:text=Azure%20Create%20an%20IoT%20Hub%201%20Sign%20in,to%20use%20for%20your%20hub.%20...%20See%20More.)
- [Tutorial: Develop and deploy a Python IoT Edge module for Linux devices](https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-python-module?view=iotedge-2018-06)
- [Azure Container Registry](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-intro)

Happy coding!

Greetings

El Bruno

More posts in my blog [ElBruno.com](https://www.elbruno.com).

* * *
Redis x DEV Hackathon Help Thread
Tags: redishackathon, redis, help
Published: 2022-08-01 16:28:54

---
title: Redis x DEV Hackathon Help Thread
published: true
description: Comment here if you need any help during the Redis Hackathon on DEV!
tags: redishackathon, redis, help 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/df37ypo5o6rb89nx3x1o.png
---

### **If you're participating in the [Redis x DEV hackathon](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248) and you need some help with your submission, you've come to the right place!** 

If you have any questions about how this contest works (_ex: due dates, how to post your submission, picking a category, etc._) the DEV team will be happy to assist you.

> **If you are running into issues or get stuck when it comes to Redis' in-memory data structure store, please leave those questions here as well.**

Comment below if you need asynchronous assistance with the Redis x DEV Hackathon ❤️ 

_P.S. If you'd like to share an update on the progress you're making on your project or if you'd like to connect with other participants, please do so in the [community discussion thread](https://dev.to/devteam/community-discussion-thread-redis-x-dev-hackathon-4cl6)!_
Community Discussion Thread — Redis x DEV Hackathon
Tags: discuss, redishackathon, redis
Published: 2022-08-01 16:28:14

---
title: Community Discussion Thread — Redis x DEV Hackathon 
published: true
description: A place to discuss your progress with the Redis Hackathon on DEV — and lend encouragement to one another!
tags: discuss, redishackathon, redis  
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51j3z92pxmco4ryujrzv.png
---

### **This thread is your place to share progress with your fellow [Redis x DEV Hackathon](https://dev.to/devteam/announcing-the-redis-hackathon-on-dev-3248) participants and encourage one another throughout the month!**

> In this thread, you can post...
- Positive encouragement for other participants
- Milestones you've achieved or things you've learned throughout the hackathon
- Links to DEV posts related to your official submission (especially if you've written multiple reflections/progress posts). Don't forget to utilize the DEV article embed tag when sharing a link! 


If you need help throughout the Redis x DEV Hackathon, head over to the [help thread](https://dev.to/devteam/redis-x-dev-hackathon-help-thread-a7b)

#### _Comment Below_ 👀
Understanding from scratch, The Event Loop in Node JS
Published: 2022-08-01 16:21:08

There are two major components of Node that make Node what it is. These components are the V8 engine and the Libuv library. The V8 engine is basically an interpreter/compiler. It converts the code you write in Javascript to machine code that your computer can understand. The Libuv library is an open source library that facilitates asynchronous I/O operations. It also provides access to the event loop and the thread pool.

The event loop is what is responsible for executing callback functions. In many places it is described as an orchestrator because it receives events/triggers (i.e a promise resolving, a network request, etc) , and runs the callback associated with that event. Now you may ask where does the thread pool come in? Sometimes, the tasks to be carried out are too heavy for the event loop to run on its own, i.e Cryptography operations, compression, so in these instances the event loop offloads these heavy tasks to the thread pool to run. The event loop decides automatically which tasks it deems too heavy so the developer really doesn’t have to bother about that. But of course, you can bother yourself if you really want to, that is fine as well.

The reason the event loop is called such is because it does exactly what it’s name implies. It loops through certain classes of events to determine the priority of callbacks to execute. It first checks, are there any callbacks in the Timer class to run? By timer class I mean, stuff like setTimeout and other similar functions. Next, it goes on to check if there are any I/O callbacks to execute. After that it checks for setImmediate callbacks to run. The setImmediate callbacks are callbacks that you intend to run immediately after an I/O operation is complete. Lastly the event loop checks for close callbacks, i.e closing a server, closing a network connection, etc.

You may want to ask where Promises fit into these classes, well that is actually a special case. The event loop really loves promises so it really doesn’t matter what’s next. As soon as a promise is resolved or rejected, the event loop immediately runs the callback associated with it. 

It is important to note that the event loop in all its glory can still be blocked and it is recommended that you do not write code that blocks the event loop for the sake of user experience. But like all recommendations, you can totally ignore this and write terrible code. All the same I will be sharing tips to help guide you in writing non-blocking code for the event loop.

Do not use synchronous versions of functions within callbacks. 
Do not do complex computation within callbacks - a loop within a loop within a loop.
Be careful with very large objects. It takes time to stringify or parse large objects to or from JSON.

So that’s it for now from me guys. I really hope you learned something new from this. Happy Coding.
Multiple item using one ref
Tags: react, useref
Published: 2022-08-01 16:17:00

Some cases in ReactJS, we need use a variable declared by `useRef` for items, components, ....

## How to use
First, you need variable declared by `useRef` and 
and set initialValue to be an empty array `[]`

```
const exampleRef = useRef([]);
```

Create a function to add item, component to `exampleRef`

```
const addToRefs = el => {
    if (el && !exampleRef.current.includes(el)) {
       exampleRef.current.push(el);
    }
};
```

Then you just add `ref` to item, component, ...

```
<div ref={addToRefs}>                 
</div>
```

Now, `exampleRef.current` as an array, you can use methods with array to use for `exampleRef` like `map, forEach, ...`
Ingest Regulars NFT events into your App!
Published: 2022-08-01 16:16:46

If you're like us, you've been extremely excited about the [launch of Regulars Jobs](https://twitter.com/monharti/status/1553429859568869382?s=20&t=uOhEp1xlWSLT_j2Z5x_qcw). Regulars are exciting for a few reasons. First, the art is different than anything else out there ([see for yourself](https://opensea.io/collection/regulars)). Second, jobs!!! Regulars can work, get on-chain names from NFT owners, and earn $REG tokens from their jobs. Could this be the beginning of a de-centralized sims? It will be interesting to watch the ecosystem around Regulars continue to grow.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bjb2s8f2yby02abksux.jpeg)

## On-chain names

Regulars can get on-chain names, let's create a Sort query to see what users are naming their Regulars!

```
select
  params[2].value as name,
  params[1].value as token_id,
  transaction_hash,
  timestamp,
from
  ethereum.transaction_log l
where
  function_address = '0x1ffe4026573cead0f49355b9d1b276a78f79924f'
  and name = 'NameChange'
order by
  timestamp desc
limit
  1000
```

[View query results here](https://sort.xyz/query/62e749149f63500cf96437f2)

## Latest Regulars Jobs Minted

```
select
  params[1].value as regular_id,
  params[2].value as new_job_id,
  params[3].value as company_id,
  params[4].value as sender,
  transaction_hash,
  timestamp,
from
  ethereum.transaction_log l
where
  function_address = '0x7e300bb12e416a9242e17ec44bbd9ae4e97f3f54'
  and name = 'jobIDCreated'
order by
  timestamp desc
limit
  10000
```

[View query results here](https://sort.xyz/query/62e7f869d91f287873138664)

Hopefully these queries are enough to get started ingesting Regulars data into your app!

Feel free to ask any questions (or for query help) on our [Discord](https://discord.gg/sort).
How to enable auto dark mode (night theme) in KDE Plasma
Tags: crontab, plasma, kde
Published: 2022-08-01 15:55:00

# Disclaimer!
The method described in this post only works if your cron handles delayed jobs (for when your PC is sleeping/powered off and the job should run).

I got different results from different OS so YMMV!

# Intro
Auto dark mode is new feature that has been gaining a lot of popularity in these years. 

That's because, with its introduction in [Android 10](https://developer.android.com/guide/topics/ui/look-and-feel/darktheme) people have begun to appreciate its benefits, including:
- Can reduce power usage by a significant amount (depending on the device’s screen technology).
- Improves visibility for users with low vision and those who are sensitive to bright light.
- Makes it easier for anyone to use a device in a low-light environment.

For GNOME, this shell extension exists: Night Theme Switcher. 

For KDE Plasma though, unfortunately, the only automatic way I could find to accomplish this is by using [this project on github](https://github.com/baduhai/Koi) which is not supported on every distro (although recently added to the OBS).

Despite this, for users that do not want to install something from a PPA / User repository / Source code, another solution exists, and it leverages the plasma `plasma-apply-colorscheme` command.

## How To

First, open up a terminal and write
```shell
plasma-apply-colorscheme --list-schemes
```
to see which color scheme you have installed on your system. 

_(You can always install more using your distro package manager or the Plasma Settings.)_

After locating the two color themes that we want to use for the **day theme** and the **night theme**, let's open up the user `crontab` manager with
```shell
crontab -e
```
and let's create two cronjob by using [this website](https://crontab-generator.org/), one that will run when we want to switch to the day theme and the other one when we want to switch to the night theme.

The input command will be
```
plasma-apply-colorscheme <colorscheme>
```

For me they will be `openSUSE` from 07:00 till 20:00 and `BreezeDark` for the rest of the day, so the two cronjobs will be:
```cron
0 20 * * * plasma-apply-colorscheme BreezeDark >/dev/null 2>&1
0  7 * * * plasma-apply-colorscheme openSUSE   >/dev/null 2>&1
```

And that's all! Let's close the crontab (Esc -> `:wq` -> Enter) and enjoy the automatic switch!