teleren/devto huggingface dataset:
Ruby, multidimensional arrays, and mutability
Tags: ruby, mutability, adventofcode
Published: 2022-12-12 13:49:03

As I progress doing the [advent of code](https://adventofcode.com/2022), the challenges start becoming more interesting and difficult, and eventually, a multidimensional array is needed.

Ruby is famous for its succinct syntax, but there are some subtleties to pay attention to.

## A shorthand

Given we need to instantiate an array, and the size (or minimum size) is known, we can allocate the memory upfront by specifying how many items we want:

```ruby
irb> my_array = Array.new(6)
=> [nil, nil, nil, nil, nil, nil]
```

All of them will be `nil`, but we can provide a default value as well:

```ruby
irb> my_array = Array.new(6, 42)
=> [42, 42, 42, 42, 42, 42]
```

Things start to become interesting (not to say disastrous) when we pass an object as the default value.

“But in Ruby, everything is an object!”, you might be wondering, and you’re totally right. However, numbers in Ruby are immutable objects.

## The multidimensional array

Given that `Array.new` can receive its size and a default value, we can think of using the expressiveness and succinctness of Ruby to allow us to generate a multidimensional array as a one-liner:

```ruby
irb> my_array = Array.new(6, Array.new(2, 42))
=> [[42, 42], [42, 42], [42, 42], [42, 42], [42, 42], [42, 42]]
```

It’s phenomenal, but let’s see what happens in practice:

```ruby
irb> my_array[0][0] = 0
=> 0 
irb> my_array
=> [[0, 42], [0, 42], [0, 42], [0, 42], [0, 42], [0, 42]]
```

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

## Not obvious, but expected!

It is one of such things we should not be surprised by, still, it may catch us off-guard.

When the syntax `Array.new(6, Array.new(2, 42))` is used, and the default parameter received is a mutable object, every single item of the array is populated with a reference for the same object, therefore changing one value implies it reflecting everywhere there’s a reference to it.

Fear not! There’s an easy fix for that:

```ruby
irb> my_array = Array.new(6) { Array.new(2, 42) }
=> [[42, 42], [42, 42], [42, 42], [42, 42], [42, 42], [42, 42]]
irb> my_array[0][0] = 0
=> 0
irb> my_array
=> [[0, 42], [42, 42], [42, 42], [42, 42], [42, 42], [42, 42]]
```

By using the block syntax, the `Array.new` will run the block for every entry to generate a default value, thus populating the entries with different objects.

If you got curious about the advent of code challenge, you can check out my solution [here](https://gitlab.com/bitmaybewise/advent-of-code/-/blob/main/2022/10/10.rb#L4) (spoiler alert, be advised).

---

If you liked this post, consider subscribing to my newsletter [Bit Maybe Wise](http://bitmaybewise.com/).

You can also follow me on [Twitter](https://twitter.com/bitmaybewise) and [Mastodon](https://mastodon.online/@bitmaybewise).

---


Photo by [Joanna Kosinska on Unsplash](https://unsplash.com/photos/tfHzx98iTLI)
To create a timer in a React app using TypeScript and Moment.js
Tags: webdev, beginners, tutorial, react
Published: 2022-12-12 13:46:15

To create a timer in a React app using TypeScript and Moment.js, you can use the setInterval() method from the window object, along with Moment.js's duration and add methods to calculate the remaining time.

Here is an example of how you might implement a timer in a React component using TypeScript and Moment.js:

```
import React, { useState, useEffect } from 'react'
import moment from 'moment'

const MyComponent: React.FC = () => {
  const [timeLeft, setTimeLeft] = useState(moment.duration(5, 'minutes'))

  // Use the useEffect hook to set up the timer
  useEffect(() => {
    const interval = setInterval(() => {
      setTimeLeft(timeLeft => timeLeft.subtract(1, 'seconds'))
    }, 1000)

    // Clean up the interval when the component unmounts
    return () => clearInterval(interval)
  }, [])

  return (
    <div>
      <p>Time left: {timeLeft.minutes()}:{timeLeft.seconds()}</p>
    </div>
  )
}
```

In this example, the useEffect hook is used to set up the setInterval() method when the component is mounted. The setTimeLeft callback function is used to subtract one second from the timeLeft state variable every second, using Moment.js's duration and subtract methods. This causes the component to re-render with the updated time remaining.

Note that the useEffect hook takes an array of dependencies as its second argument. In this case, we've passed an empty array to indicate that the effect should only run once when the component is mounted. This is important, as it prevents the timer from being reset every time the component re-renders.
macOS Tip: How To Cut and Paste (Move) Files In MacOS Finder
Tags: macos, webdev, tutorial, productivity
Published: 2022-12-12 13:30:00

- [Introduction](#introduction)
- [Moving Files in Finder](#moving-files-in-finder)
- [Conclusion](#conclusion)

## Introduction

Having used macOS for many years, I have missed a feature from Windows and Linux desktops that didn't seem to exist in macOS: Cutting and pasting files from one location to another.

There is no option for this in the right-click menu so I always thought it wasn't a feature that macOS had. As it turns out there is a way to get a similar function to this in macOS.

So, how is it done?

## Moving Files in Finder

As it turns out, it is a very simple process:

1. Open a Finder window and browse to the file(s) you need to move (cut and paste).
2. Select the file(s) and copy them using either *CMD+C* or right-click and selecting *copy*.
3. Next, open another Finder window (or tab) and browse to the destination folder where you would like to place the files.
4. Finally, use either *CMD+OPTION+V* or right-click in the location, press and hold the *OPTION* key and *paste* will turn to *Move*. Left click on *Move* and the files will be moved. The file(s) in the source folder will no longer be present.

This works when moving files on the same drive or to a different drive. No need to copy, paste and delete the source copy anymore.

## Conclusion

I hope you found this useful. Thank you for reading and have a nice day!
Amazon EC2 Tutorial for Beginners | What is Amazon EC2 | AWS EC2 TutoriaL
Tags: aws, ec2, cloud, awsec2
Published: 2022-12-12 13:28:57

Amazon EC2 Tutorial for Beginners | What is Amazon EC2 | AWS EC2 Tutorial

This AWS EC2 lesson will help you learn what EC2 is, how to create an EC2 instance, and how to run your instances in Linux, Windows, and Ubuntu. AWS provides a wide range of services in a variety of sectors. One of these is Elastic Computing Cloud (EC2), a web service that makes life simpler for developers by offering safe and resizable compute power in the cloud. We'll also look at how to run your own web server, design your own AMI template, expand your storage capacity, and assign your static elastic IP address.


{% embed https://youtu.be/ynPjd9TKLc4 %}
I don't call myself a TDD practitioner anymore, neither should you.
Tags: tdd, cleancode, testing, programming
Published: 2022-12-12 13:28:07

I don't call myself a TDD practitioner anymore, neither I think I should use TDD all the time.

I didn't think it was possible but it feels liberating! What made me change my mind?

I have posted a couple of posts about the drawbacks/limitations of TDD and I was surprised by some pushback I received. Not that I didn't expect the pushback, but I expected way more sober and constructive pushback. Allegedly TDD is "the only way to write software" and if you disagree you are just a rubbish developer who didn't learn TDD well.

I think one reason that TDD is not more popular is the toxic and often blind members of the community. At times, it seems that merely doubting the value of TDD makes you a bad person or professional.

This is wrong. By refusing to consider the drawbacks of TDD, we are not allowing ourselves to improve the practice or to look for better alternatives. That's when I realized that I don't want to be associated with this kind of attitude, and so I have stopped calling myself a "TDD practitioner" or a "member of the TDD community".

TDD is a useful practice and I will still use it when I think it is helpful. But I have started to question TDD even more, and have been looking for other approaches that are less counter-intuitive and take less time to learn, but still provide the same benefits. I think I found something real.

I am currently working on a video script that will explain my findings and thoughts in more detail.
CSS Flexbox (Flexgrid) and how to use it quick ?
Tags: beginners, css, modcss, tutorial
Published: 2022-12-12 13:19:54

Flexbox make easier design of flexible responsive layout structure.

When you are new to CSS, it can be difficult to create a flexbox grid yourself. The easiest way is to use a framework or library that does it good. 
_MOD-CSS_ does this easily and quickly with extensive customization options.

**For example,**

 the following code creates a simple grid with one container, three columns and one row:

```
<div :mod="container[90%]">
    <div :mod="row[100%]">
        <div :mod="column[20%]"> ...col1 </div>
        <div :mod="column[40%]"> ...col2 </div>
        <div :mod="column[fit]"> ...col3 </div>
    </div>
</div>

```
**Find this snippet on** [codepen](https://codepen.io/dev-geos/pen/bGKyrEd)

**More examples are available**
If you want to see more setup, get links below :
[Offical documentation](https://mod-css.com/docs/layout/)
[More example](https://mod-css.com/presets/Flexgrid/)

##  
## What is MOD-CSS ?
It was designed to be a good alternative to bootstrap and tailwind. 
It is lightweight and quite complete.

[Offical website](mod-css.com)
[Github](https://github.com/modsLabs/mod-css/)
How to know if you're a good developer?
Tags: developer, webdev, softwareengineer, programming
Published: 2022-12-12 13:19:10

As a developer, it can be difficult to know if you are truly good at what you do. After all, programming is a constantly evolving field and there is always more to learn and improve upon. However, there are some key indicators that can help you determine whether you are a good developer or not.

![constantly learning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19tf0tbr36j3md73250u.jpg)
First and foremost, a good developer is someone who is constantly learning and staying up-to-date with the latest technologies and best practices. This not only shows a dedication to the craft, but also ensures that you are able to deliver high-quality, modern solutions to the problems you are solving.

![write clean code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qfhoh6y3jtw4g7c1ww1.jpg)
Another important indicator of a good developer is the ability to write clean, efficient, and well-documented code. This means not only writing code that works, but also code that is easy for others to understand and maintain. Good developers understand the importance of readability and maintainability in their code and strive to create solutions that are easy to work with.

![strong problem-solving skills](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdha2yjdyww0qeeswtc0.jpg)
In addition to technical skills, good developers also possess strong problem-solving skills. They are able to take a complex problem and break it down into smaller, more manageable pieces. They are also able to think logically and systematically, and use their knowledge of programming languages and frameworks to come up with solutions that are both effective and efficient.

![team work](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltgtwoti7eaa7iu1qhae.jpg)
Good developers are also able to work well in a team. They are able to communicate effectively with other members of the team and are willing to collaborate and share their knowledge in order to find the best solution to a problem. They are also able to take direction and feedback from others in order to improve their own skills and the overall quality of the project.

![handle criticism and failure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4t8m56cvtmwsnt4a8lg.jpg)
Finally, good developers are able to handle criticism and failure in a constructive manner. They are able to learn from their mistakes and use them as opportunities for growth and improvement. They are also able to accept feedback from others and use it to improve their skills and their work.

![keep up the good work](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1x5v5qzrupdnnb9iht0.jpg)
In short, if you are a developer who is constantly learning, writes clean and well-documented code, has strong problem-solving skills, works well in a team, and is able to handle criticism and failure, then you are likely a good developer. Keep up the good work!
You need to know about Neubrutalism Style
Tags: webdev, tutorial, css
Published: 2022-12-12 13:19:03

I recently came to know about Neubrutalism. Well bear with me for a minute. I'll let you know the thing I'm talking about.

## What is Neubrutalism ?
For short, Neubrutalism is an architectural style that emerged in the 1950s, characterized by its use of raw, unadorned concrete construction. Buildings in this style often have a blocky, geometric appearance, with a focus on functionality and simplicity.

## How did it come to web design?
A few popular websites, like Gumroad and Figma, popularized it in some way. And lots of websites are using it. 

> See Below

![Gumroad](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnifvpbxzhw0loxmfp9y.jpg)

![Mozilla](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbuubu0bzct0bt4xqscu.jpg)

## Why I Got Excited to Tell You About this?

Because I've done it with my website too! And I transformed it from a normal design to a neubrutalism style in just 4-5 hours.

> 
![anas dew website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu5bn8tfq6i9yda7igbr.jpg)

## This is what I did.
Here are a few things that I did to make it look neubrutalism style.

- Used Headings in CAPITAL LETTER
- **Bold fonts**
- High Contrast Colors
- High Contrast Shadows
- Sharp Edges (In some elements)

And the result that came out was BEAUTIFUL. Although I'll make some changes in a few days and make it more BRUTAL. And I'm planning to add some animations too.

**🍕 Check Out** -> [http://anasdew.tech/](http://anasdew.tech/)

**Thanks for reading this post! I'll see you in the next one!**

Your Next Read -> [I Built a REDDIT BOT](https://dev.to/anasdew/i-built-a-reddit-bot-which-downloads-top-videos-in-seconds-3eko)
How is this dirty code
Tags: javascript, programming, devops, typescript
Published: 2022-12-12 13:09:23

I started writing code in Swift, now when the application is launched, its functionality does not work well. I surfed the Internet for possible causes and came across information about dirty code and its refactoring. Who did the refactoring for the source code? Does this help solve the issue with the functionality?
Here is the code:
`//
//  proSwift.ru
//
//  Swift 3
    
    init?(brand: String) {
        if let oil = MotorOil(rawValue: brand) {
            self.oilBrand = oil
        } else {
            return nil
        }
    }`
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: 'Unknown Error', url: 'my_url', ok: false, …}
Tags: angular
Published: 2022-12-12 13:08:05

Hey there, 
I'm trying to get response from POST_API. But I can't get that inside my component.ts
Here's my code:

```
roomtypes: any;
  errorMessage: String = "";
  ngOnInit(): void {
    this.http.post<any>('https://backend.revroo.io/api/v1/booking-engine/get-hotels', { title: 'Angular POST Request Example' }).subscribe({
        next: roomtype => {
            this.roomtypes = roomtype.id;
        },
        error: error => {
            this.errorMessage = error.message;
            console.error('There was an error!', error);
        }
    })
  }
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2j8hikt1tx9py31yprg.png)
Seeking Help!
About Nuvolaris and other similar Platforms
Tags: cloud, cloudnative, aws, azure
Published: 2022-12-12 13:07:46

A question I've been asked several times: what's the difference between your Nuvolaris and the other X-Platforms and Y-Distribution for Kubernetes that are out there?

My answer is that they are a Web Agency with an ad hoc platform, and we are doing WordPress.

The thing is certainly not very clear if one does not put one's mind to what happened when the Web exploded (and a similar process occurs punctually in every industry where there is a novelty).

When there is big news, as there was when the Web exploded, there are customers who want to go to the Web. You, entrepreneur sniffing the air, what do you do? Well, you open your own company that makes Web sites and set yourself up for customers who want to go on the Web.

The problem is that the moment you approach the market in this way, to give customers what they want, you sell "work" and use what you can find to do it, raking in what is available. Which generally means building custom websites. Handmade. Handcrafted. In short, you make a web agency.

Generally, then the WebAgency moves forward a bit, bundles the solutions it has provided to a few clients, renames them "standard solution," and starts selling its "CMS," its "platform".

Which then is usually not CMS, but is instead a semi-finished product, some reusable code, and the people who know how to do the work. And that is exactly what the various X-Platform and Y-Distribution companies are doing in the cloud today.

The fact is that this approach doesn't last much longer. Any domain tends toward standardization. Some products emerge, and gradually the various "ad hoc" solutions of the web agencies are set aside.

Those companies that 10 years ago had their own homemade CMS now use WordPress. Or Drupal. Or Adobe AEM. But they basically didn't make the product, they adapted it to someone else's product.

Those who have thought about a big market, on the other hand, have built a product. They invested (and a lot). They created a generic solution and evolved it on the demands of not three but 300 or 3000 customers at the same time.

This is the difference between Nuvolaris and other cloud companies with their platform. They are a "cloud agency" with a platform but in fact, they are 80% service and 20% product.

Nuvolaris builds on an open-source product, serves many customers at once with its deployment, and is 80% product and 20% service.
How to build a Go microservices backend in 5 minutes
Tags: go, cloud, programming, microservices
Published: 2022-12-12 13:03:16

{% embed https://www.youtube.com/watch?v=IwplIbwJtD0 %}
In this video André shows you how to build your own Go backend and deploy it to the cloud, in just 5 minutes.

Using [Encore](https://encore.dev), it's easy to get a microservices backend up and running, without worrying about infrastructure configuration or management. Encore automatically provisions local, preview, and cloud environments based on understanding your app's infrastructure requirements directly from your business logic.

The framework is [Open Source](https://github.com/encoredev/encore) and the [Encore platform](https://encore.dev) provides free cloud hosting for hobby projects.

Don't just start your next project today – finish it!
Navigating Your New Tech Job: Tips for a Seamless Transition
Tags: career, productivity, beginners, tutorial
Published: 2022-12-12 13:02:01

[facebook.com/Trinwhocode](https://facebook.com/Trinwhocode)

So, you’ve just landed a new job. Congratulations! You’re excited, but you’re also a little apprehensive about the transition into a new environment, culture, process, policies, and people. As a tech guy, it can be especially challenging to adjust to a new job.

But don’t worry. I’ve got you covered with the best and most practical strategies to make the transition smoother and help you get up to speed quickly. Here are some things to consider when entering your new job:

1. Get to Know the Office Culture: Every workplace has its own unique culture. Take the time to observe and understand the norms and expectations. Ask questions to get familiar with the way things are done.

2. Do Your Homework: Before you start your new job, make sure you understand the process, policies, and technology associated with it. Research the company, its products and services, and its clients. This will help you hit the ground running. This includes things like vacation time, dress code, and other rules. Knowing the policies will help ensure that you don’t make any mistakes and that you are working in the most efficient manner.

3. Learn the tools. Familiarize yourself with the tools that your team uses. This could include anything from software, hardware, and coding languages. Understanding the tools will help you get up to speed quickly and be able to contribute to the team.

4. Get to Know the People: Introduce yourself to your new colleagues and build relationships. A warm welcome can go a long way. Show an interest in what they do and take time to learn about them.

5. Show Off the Right Skills: When it comes to your new job, focus on your strengths and what you can bring to the table. Showcase your skills and be confident in your abilities. it’s important to show your enthusiasm and ambition. But be sure to avoid boasting about your skills. Instead, be humble showing your willingness to learn. This will show that you’re a team player and will help you gain the respect of your colleagues. This will help you make a positive impression and prove your value to the team.

6. Ask questions. Don’t be afraid to ask questions. If you don’t understand something, voice your concerns and ask for clarification. This will not only help you understand the task at hand, but it will also help build trust with your team.

These are just a few things to consider when entering your new job as the new tech guy. We’d love to hear your thoughts on what worked for you and what didn’t. Share your experiences in the comments and help others make the transition smoother.

[linkedin.com/in/trinmar](https://linkedin.com/in/trinmar)
How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer
Tags: aws, cloud, bigdata, dataengineering
Published: 2022-12-12 12:39:57

This Edureka video "𝐇𝐨𝐰 𝐭𝐨 𝐛𝐞𝐜𝐨𝐦𝐞 𝐚 𝐃𝐚𝐭𝐚 𝐄𝐧𝐠𝐢𝐧𝐞𝐞𝐫" will guide you through the steps to learn and have a successful career in Data Engineering. This video will help you to become a Data Engineer in 2023.
00:00 Introduction
01:14 Why become a Data Engineer
02:40 Who is a Data Engineer
03:57 Data Engineer Job Description
04:38 Data Engineer Skills
05:15 Roles and Responsibilities
06:00 How to become a Data Engineer

{% embed https://www.youtube.com/watch?v=wkc94BhbG60 %}