teleren/devto huggingface dataset:
Kotlin Code Smell 1 - Constants and Magic Numbers
Tags: kotlin, codesmells, cleancode, programming
Published: 2022-12-04 11:15:23

---
title: Kotlin Code Smell 1 - Constants and Magic Numbers
published: true
date: 2022-11-30 18:52:36 UTC
tags: kotlin,codesmells,cleancode,programming
canonical_url: https://yonatankarp.com/kotlin-code-smell-1-constants-and-magic-numbers
---

![382byvsz5zmnq11ww9ar.png](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/382byvsz5zmnq11ww9ar.png)

> **TL;DR:** Avoid using magic numbers without explanation. Their source is unknown, and we fear changing them.

## Problems

* Coupling
    
* Low testability
    
* Low readability
    

## Solutions

* Rename the constant with a meaningful and intention-revealing name.
    
* Replace constants with parameters, allowing them to be mocked from the outside.
    
* The constant definition should be separate from its usage.
    

## Examples

* Algorithms Hyper Parameters
    

## Sample Code

### Wrong

```kotlin
fun energy(mass: Double) = (mass * 299792458).pow(2)
```

### Right

```kotlin
typealias MetersPerSeconds = Int

// Using a specific unit of measure to avoid another code smell
const val LIGHT_SPEED: MetersPerSeconds = 299792458

fun energy(mass: Double) = (mass * LIGHT_SPEED).pow(2)
```

---

Stay updated with my latest thoughts and ideas by registering for my [newsletter](https://yonatankarp.com/newsletter). Connect with me on [LinkedIn](https://www.linkedin.com/in/yonatankarp/) or [Twitter](https://twitter.com/yonatan_karp). Let's stay connected and keep the conversation going!

---

## More Information

* [Refactoring Guru](https://refactoring.guru/es/replace-magic-number-with-symbolic-constant)
    
* [How to Decouple a Legacy System](https://maximilianocontieri.com/how-to-decouple-a-legacy-system)
    

## Credits

* [Code Smell 02 - Constants and Magic Numbers](https://maximilianocontieri.com/code-smell-02-constants-and-magic-numbers) by @[Maxi Contieri⭐⭐⭐](@mcsee)
100% Free Online tools for Everyday Needs
Tags: webdev, beginners, tutorial, productivity
Published: 2022-11-30 18:36:34

Hello Everyone 👋

I'd like to share with you the best free online tools for everyday needs on internet to boost your online business. free, ad-free, use it any times without any restriction 👻

Tools in one place for you to improve the performance of your business and increase the speed of your daily work 🔁

100% Free Tools for everyone - Make Money, Community Managers, Developers, Small Business, Entrepreneurs, Youtubers, Students, Influencers, Freelancers, Bloggers, Designers, Dropshippers, Writers, SEO, Teachers, Artists, Lawyers, Doctors ... 🥳

- Save Time & Money 
- Boost Productivity
- Increase Sales
- Attract New Customers 

Like & Share these tools with your friends 😊

- 10.000+ daily visitors
- 300.000+ monthly pageviews
- 200+ free online tools

[1tools.co](https://1tools.co)

Hope you found these tools useful, If you have any feedback, please reach out to me 🙏 

Have a good day 👋


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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7c6iy5dtfpg6518xllv1.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h1tsxiemi3c5i6kl3xl.PNG)

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

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

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

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhatucwjw4mq20v45ezy.PNG)
Golang: Named Returns Are Useful!!!
Tags: go
Published: 2022-11-29 21:40:16

# Named returns

If you are not familiar with what a named return is, reference [A Tour of Go Basics](https://go.dev/tour/basics/7).

## Named returns... Hurk...

I know, I know... Named returns can decrease the readability of longer functions written in Golang, but there is a case in which they are a necessity. Handling panics gracefully!

### Problem

In many languages, you might use a try/catch block to handle some code that might otherwise throw an exception and wreak havoc. They allow us to override any values. In Golang, we have panics.

First, let's create a simple function that divides 2 integers:

```golang
func Divide(numerator, denominator int) (int, error) {
	return numerator / denominator, nil
}
```

The issue with this code is that we cannot divide by `0`. Doing so will result in: `panic: runtime error: integer divide by zero`.

We could have a check for whether the denominator is `0`, but for the purposes of this post, how can we gracefully handle this panic?

### Solution

[Here's a refresher on panic, defer, and recover.](https://go.dev/blog/defer-panic-and-recover)

By naming the return values, `val` and `err` respectively, we can recover from the panic and return any value and error we would like. 

```golang
func Divide(numerator, denominator int) (val int, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()

	return numerator / denominator, nil
}
```

Now, instead of needing to handle the panic everywhere `Divide` is called, callers can simply handle the graceful error.
How to create a send button with animation - Step-by-step
Tags: css, webdev, tutorial, beginners
Published: 2022-11-30 18:15:28


![Send button with animation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zxtiwp2ldkf4fg68bxb.png)

**Tutorial on how to create a send button with animated icon.**

## HTML
For HTML, we need a send svg and text "SEND" inside a div with "send-button" class.

```html
<div class="send-button">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" width="20" height="20">
        <path stroke-linecap="round" stroke-linejoin="round" d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5" />
    </svg>
    <span>SEND</span>
</div>
```

## CSS
For css, first we'll style the div element with "send-button" class.

First, we'll set some basic styling: font to Tahoma, cursor to pointer, background to dark blue, text color to white.

Now we'll position elements in a row using flexbox and align items in center.

We'll set width to fit content and add a little padding.

```css
.send-button {
    font-family: Tahoma;
    cursor: pointer;
    background-color: #34495e;
    color: #fff;
    display: flex;
    align-items: center;
    width: fit-content;
    padding: 10px 15px;
}
```

Now we'll add some padding to span element with "SEND" text.

```css
.send-button span {
    padding: 0 20px;
}
```

Then we'll rotate svg by -40 degrees and add 200ms transition.

```css
.send-button svg {
    transform: rotate(-40deg);
    transition: 0.2s;
}
```

On hover, we'll move svg a by 50% to the right and 5% to top, and rotate by 10 degrees.

We'll also add 200ms transition.

```css
.send-button:hover svg {
    transform: rotate(10deg) translate(50%, 5%);
    transition: 0.2s;
}
```

Now we'll create an animation named "move" that will, as the name says, move an element.

This animation will move an element by 5% to top and 5% to bottom.

This is why we set 5% X translation to svg on button hover.

Also, it will rotate an element by 10 degrees in both directions.

```css
@keyframes move {
    0% {transform: rotate(10deg) translate(50%, 5%);}
    50% {transform: rotate(-10deg) translate(50%, -5%);}
    100% {transform: rotate(10deg) translate(50%, 5%);}
}
```

Lastly, we'll add created animation to our svg.

"move" is the name of our animation, infinite is the iteration count, which means that animation will be infinite, 1s is the duration of the animation (for 1 iteration), and 0.2s (200 milliseconds) is animation delay. I added the delay because of the transition I set on svg. Animation will start as soon as the transition finishes.

```css
.send-button:hover svg {
    transform: rotate(10deg) translate(50%, 5%);
    transition: 0.2s;
    animation: move infinite 1s 0.2s; /*  New line -> Animation  */
}
```

And that's it.

You can find the video with step-by-step guide [here](https://designyff.com/code/send_button_with_animation).

Thank you for reading ❤️
Create and Attach EBS volume to EC2 instance
Tags: powershell, automation, aws, cloudcomputing
Published: 2022-11-30 17:55:15

After launching an EC2 instance you may require a need to create additional EBS volume and attach it to EC@ instance, below powershell script will create and attach EBS volume to already running EC2 instance

[Create and Attach EBS Volume to EC2 Instance](https://www.magicpowershell.com/2022/07/create-attach-ebs-volume-to-EC2-Instance-powershell.html)
CLI command for creating Azure Resources
Published: 2022-11-30 17:33:47

- Created VM , System assigned Identity using CLI

1. Creating ResourceGR
2. Create VM with system assigned ID
	az vm create \
	--resource-group userRG \
	--name userVM \
	--image ubuntuLTS \
	--generate-ssh-key \
	--assign-identity \
	--admin-username user \
	--admin-password pass1234@
-----------------------------------------------------------------------------------------
- Created VM, User Assigned Identity using CLI
1. Create ResourceRG (If you've not created before)
2. Create the User Identity to be assigned to the VM
	az identity create --name bruno123 --resource-group saviourRG

3. Create VM the user Identity assigned
	az vm create \
	--resource-group userRG \
	--name userVM --image ubuntuLTS \
	--generate-ssh-key \
	--assign-identity bruno123 \
	--admin-username user \
	--admin-password pass1234@

------------------------------------------------------------------------------------------------

using variable to create KeyVault
	myKeyVault=az204vault-$RANDOM
	myLocation=<myLocation>

Creating Keyvault
	az keyvault create --name $myKeyVault --resource-group az204-vault-rg --location $myLocation
Creating secretkey
       az keyvault secret set --vault-name $myKeyVault --name "ExamplePassword" --value "hVFkk965BuUv"
To see check the secret
	az keyvault secret show --name "ExamplePassword" --vault-name $myKeyVault

-------------------------------------------------------------------------------------------------
- Delete Resource Groups Created (Cleaning UP) 

	az group delete --name <name of the resource group>
	az group delete --name elodemoRG --no-wait
	az group delete --name demokeyvault --no-wait
	az group delete --name NetworkWatcherRG --no-wait

-----------------------------------------------------------------------------------------------
Link for online terminal for practice
[](https://docs.microsoft.com/en-us/cli/azure/identity?view=azure-cli-latest)
Golang useful links
Tags: go, gonuts, opensource, github
Published: 2022-11-30 17:25:37


* [Golang](https://golang.org/doc/code.html)
```
General recommendations from the Go website
```
* [Effective Go](https://golang.org/doc/effective_go.html)
```
Effective Go - Per-subject recommendations from the Go website
```
* [Libraries](https://awesome-go.com) 
```
awesome-go - Curated list of Go libraries
```
* [Search](https://libs.garden/go)
```
 Search engine for Go libraries
```
* [Book](https://www.programming-books.io/essential/go/)
```
 Essential Go - A free book about the Go programming language
```

* [FAQ](https://golang.org/doc/faq) 
```
Go FAQ - From the Go website
```
* [LearnGo](https://blog.learngoprogramming.com/) - 
 [GithubLink](https://github.com/inancgumus/learngo) 
```
Learn GO
```
Remote debug with pydevd-pycharm for PyCharm
Tags: pycharm, python, debugging
Published: 2022-11-30 17:22:56

---
title: Remote debug with pydevd-pycharm for PyCharm
published: true
description: Motivation. It is the second attempt to set up this configuration, and I forgot what I did in the previous approach. My notes what How I setup configuration.


tags: pycharm, python, debugging
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-11-30 16:55 +0000
---

## Motivation 
It is the second attempt to set up this configuration, and I forgot what I did in the previous approach. My notes what How I set up configuration.

## Project
Project-based on Django. The project uses a Docker and a docker-compose. Pycharm uses a Python interpreter from docker-compose. We separate the project into two services: 
 * Celery
 * API

## Debugging

For API I use PyCharm Django debugger. Work fine and does not have any problems. But when I need to debug the Celery task. We have an issue with the classical debugger. 
Pydevd-pycharm server good resolved the problem with it.

## Setup
* Dockerfile. pip install pydevd-pycharm-<actual-version>
* Put to problem part of code:

```python
import pydevd_pycharm
pydevd_pycharm.settrace('host.docker.internal', port=7777, stdoutToServer=True, stderrToServer=True)
```
Attention: `host.docker.internal` hostname of host machine in a container.

* Mapping folders between a host project and a container copy project.

* Setup `Python Debug Server` in Pycharm. Where we find instruction how to setup pydevd-pycharm. Host: localhost Port: 7777
Project From Scrimba for learning MD Language
Tags: beginners, md
Published: 2022-11-30 17:08:05

# Markdown Course LIVE on Scrimba
 ---
Just a beginner guide about using markdown language.

### Challenge: Introductory Paragraph
Markdown is a lightweight markup language for creating formatted text using a plain-text editor.
### Challenge: How to Bold text? 
  There are two ways to bold 
- Using two Asterisk around the text like this `**Bold**` **Bold**
- Another way is using two underscores like this ` __bold 2__` __bold 2__

### Challenge: How to Italicize text?
There are two ways to Italicize.
- Using single  Asterisk around the text like this `*Italic Text 1*` *Italic Text 1* 
-  Another way is using single underscore like this ` _Italic2_` _Italic2_
Testing in Ruby
Tags: ruby, rails, testing, webdev
Published: 2022-11-30 17:03:22

> Testing your Ruby code with Unit and Integration testing libraries 🤩

Writing test cases is one way to ensure that your code behaves as expected, but it can be very time consuming.
That's why I'm excited to share the latest libraries I'm using to make testing my Ruby code easier and faster.
Unit testing libraries like Minitest and RSpec allow developers to precisely test small pieces of their code (e.g. a single method) and integration testing libraries like Capybara help you run tests on entire web applications by simulating user actions.
These tools are incredibly useful for finding bugs in your code that might not be obvious at first glance!

## Rspec

Have you ever been amazed by the power of RSpec unit tests written in Ruby code? Try it out and you'll be hooked! 
When we write RSpec tests, we specify a set of expectations that define the expected behavior of our application. We can also use them to test for edge cases such as unexpected inputs and other scenarios that may cause our app to crash or respond strangely.
RSpec uses a DSL (domain specific language) to describe each test. This allows us to write expressive tests that are readable by non-technical people as well.
With RSpec, we can ensure that our application behaves correctly in all scenarios, so we can focus on developing features knowing that our code is reliable.
Give it a try and see how powerful and fun writing unit tests can be!


## Capybara
If you're an aspiring Ruby developer, you never want to miss the opportunity for integration testing with Capybara. Not only is it autonomous and easy to use, but it also makes testing more efficient and successful. This forward-thinking tool supports cross-browser functionality, accurately simulates user interaction on your website, and even has its own DSL. With Capybara, you can be rest assured that your code is running exactly as it should - and that's something every Ruby developer should be excited about!

It's the perfect way to make sure your applications are working as expected, from logging in to filling out forms to clicking buttons - it covers it all. 
Integration testing with Capybara is fast, effective and provides you with a comprehensive overview of how the application is going to work once released. It also ensures that everything from the front end design down to the backend functionality is working as expected - and that's what makes it so great. 
Start taking advantage of Capybara for your integration testing today! 💻
React Virtual Dom...?
Tags: react, virtualdom, solidjs, svelte
Published: 2022-11-30 17:01:16

Why **React** is not dropping the virtual DOM like **Svelte** || **Solid** ?

Won't it make **React** more **performant** ?

Also why not re-rendering dynamic values where needed (like **Solid.js** ) rather then doing a full page/component re-render ?
AWS CLI
Tags: aws, awscli, commandline
Published: 2022-11-30 16:42:04

**AWS Command Line Interface - CLI**, é a interface de interação do usuário com a plataforma,acesso via ssh(ex:'criação,configuração,monitoramento de serviços,leitura de logs dos mesmos,automações') via linha de comando, terminal no Linux(Debian) 'sudo apt-get install aws cli'.Também será necessário a configuração da ferramenta com as credencias fornecidas ao seu usuário criado no IAM - Identity Access Management.Para efetuar a configuração da mesma, o usuário deve diginar no terminal: 'aws configure', digitar o id access key, da secret,a região, no nosso caso como brasileiros e devido aos tributos para operar em nosso país, ser mais viável a utilização de datacenters do exterior, localizados em outros países.Depois você escolhe o formato do arquivo do output(log de saída).Dai para frente você já está habilitado a disparar um aws --help para melhor entender a sua devida aplicação e com qual o serviço deseja itneragir.Para maiores informação é recomendando o acesso a documentação oficial, na página do  **AWS CLI** https://docs.aws.amazon.com/cli/index.html
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uddz0tmpntl5naak5w54.png)
Question Answering as a Service with Cohere and Qdrant
Published: 2022-11-30 16:41:45

Bi-encoders are probably the most efficient way of setting up a semantic Question Answering system. This architecture relies on the same neural model that creates vector embeddings for both questions and answers. The assumption is, both question and answer should have representations close to each other in the latent space. It should be like that because they should both describe the same semantic concept. That doesn’t apply to answers like “Yes” or “No” though, but standard FAQ-like problems are a bit easier as there is typically an overlap between both texts. Not necessarily in terms of wording, but in their semantics.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukurddjav6ibxr63o35i.png)
Read more in the [**article**](https://qdrant.tech/articles/qa-with-cohere-and-qdrant/) by Kacper Łukawski.
Vue.js + Spring Boot example | Spring Data JPA + REST + MariaDB CRUD
Tags: vue, springboot, mariadb, springdata
Published: 2022-11-30 16:35:39

https://ozenero.com/vue-js-spring-boot-example-spring-data-jpa-rest-mariadb-crud-example

Tutorial: Vue.js SpringBoot CRUD MariaDB Example | Spring Data JPA + REST + MariaDB CRUD


In this Vue.js SpringBoot tutorial, we show you Vue.js Http Client & Spring Boot Server example that uses Spring JPA to do CRUD with MariaDB and Vue.js as a front-end technology to make request and receive response.
Angular 6 – Display Image from Amazon S3 with SpringBoot RestAPI + Bootstrap 4 Example
Tags: angular, amazon, s3, restapi
Published: 2022-11-30 16:30:12

https://ozenero.com/angular-6-display-image-from-amazon-s3-with-springboot-restapi-bootstrap-4-example

Technologies
Angular 6
Bootstrap 4
Java 1.8
Spring Boot 2.0.4.RELEASE
Maven 3.3.9
Spring Tool Suite 3.9.0.RELEASE
Amazon S3
Automated stair lighting project
Tags: opensource, programming, microservices, luos
Published: 2022-11-30 16:30:05

Nicolas Rabault built an automated stair lighting project which was featured on EDN!
⏩ Read the full [article](https://www.edn.com/automated-stair-lighting-project/)

💬“My solution involved a staircase illuminated with LEDs, a sensor at each step connected to an independent board with all the boards connected and communicating with each other to form the system.” Nicolas Rabault
tRPC-SvelteKit v3 supports tRPC v10 🎉
Tags: typescript, svelte, trpc, fullstack
Published: 2022-11-30 15:59:00

---
title: tRPC-SvelteKit v3 supports tRPC v10 🎉
published: true
description: tRPC-SvelteKit is an adapter allowing you to build and consume type-safe APIs in your SvelteKit applications
tags: typescript, svelte, trpc, fullstack
cover_image: https://user-images.githubusercontent.com/581999/204842918-5d10432e-3c5f-44b6-b29f-9b5ba80c7625.png
# Use a ratio of 100:42 for best results.
published_at: 2022-11-30 15:59 +0000
---

It's been 10 months since I released the initial version of tRPC-SvelteKit, an adapter enabling TypeScript developers to build and consume type-safe APIs in SvelteKit applications.

I'm happy to announce that v3 works with tRPC v10 and comes with a nice documentation website:

[icflorescu.github.io/trpc-sveltekit](https://icflorescu.github.io/trpc-sveltekit/)

The documentation website showcases how you could use tRPC procedures in SvelteKit's [page load](https://icflorescu.github.io/trpc-sveltekit/page-data) / [page server load](https://icflorescu.github.io/trpc-sveltekit/page-server-data) functions and how you could implement cookie-based [authentication](https://icflorescu.github.io/trpc-sveltekit/authentication).

Have a look at it and please [star the project repo](https://github.com/icflorescu/trpc-sveltekit) if you find it useful.

Also, if you're looking to hire the services of a seasoned front-end/full-stack React and/or Svelte developer, have a look at my [GitHub profile](https://github.com/icflorescu) and don't hesitate to drop me a line at the email address you'll find in there.