teleren/devto huggingface dataset:
[Tiny] How the conversion of int[] to List<Integer> can be buggy?
Tags: java, tiny
Published: 2023-06-01 07:41:30

Imagine we have an array of `int`s and we want to convert it to a `List`. Here is the sample:

```java
int[] array = new int[]{42, 5, 1, 3, 4};
List<Integer> list = new ArrayList(Arrays.asList(array));
System.out.println(list.get(0));
```

What do you think will be printed? That's right, something like

```
[I@2ff4acd0
```

It does not look like `42` at all. So, what's the problem?

First of all, let's look at the warnings IDE shows:

```
Raw use of parameterized class 'ArrayList'
Call to 'asList()' with only one argument
```

Okay, so let's fix the first one by adding diamond operator `<>` to `new ArrayList`:

```java
int[] array = new int[]{42, 5, 1, 3, 4};
List<Integer> list = new ArrayList<>(Arrays.asList(array));
System.out.println(list.get(0));
```

And now we have a compilation error on the `ArrayList` creation:

```
Required type: List<Integer>
Provided: ArrayList<int[]>
```

It looks like it matches the second warning we saw earlier. The reason is that `Arrays.asList(array)` does not box `int` to `Integer` and creates a `List` of `<int[]>`, not a `List` of `Integer` as we wanted it to.

There are several ways to fix it:
- The type of `array` can be changed from `int[]` to `Integer[]`:
```java
Integer[] array = new Integer[]{42, 5, 1, 3, 4};
List<Integer> list = new ArrayList<>(Arrays.asList(array));
System.out.println(list.get(0));
```
- `array` can be converted to `List<Integer>` using `IntStream` with boxing:
```java
int[] array = new int[]{42, 5, 1, 3, 4};
List<Integer> list = new ArrayList<>(Arrays.stream(array).boxed().toList());
System.out.println(list.get(0));
```
- Another way to create `IntStream` from `int[]` is to use `IntStream.of()`:
```java
int[] array = new int[]{42, 5, 1, 3, 4};
List<Integer> list = new ArrayList<>(IntStream.of(array).boxed().toList());
System.out.println(list.get(0));
```

All three fixes will work as expected, and the code will print `42`.

As a conclusion, don't ignore IDE warnings, as they can indicate real bugs, not just code smells.

---

*Dream your code, code your dream.*
Add free ssl on apache2 server ubuntu
Tags: apache2, ubuntu, ssl
Published: 2023-06-01 07:35:35

नमस्ते 🙏

Free free free 🤩 🥳

Run following command to install free certificate on apache2 server.

Run this command to update existing packages.

```
sudo apt update
```

Run this command to install certbot, which provides free certificate for 1 year.

```
sudo apt install certbot python3-certbot-apache
```

After successfully installation run this command to get free ssl

```
sudo certbot --apache
```

After, enter an email address to get notification when your ssl is about to expire.

![article-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mw5m7athfbg4wy5ki9c.png)

Agree to their terms and condition.

Enter your domain where you wants to install ssl.

![article-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sw8szxpmyeoevhpxo97.png)

**Congratulations! You have successfully installed free certificate on your domain.**

**Verifying Certbot Auto-Renewal**

To auto renewal run following commands:

```
sudo systemctl status certbot.timer
```

Your output will be similar to the following:

```
Output
● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset:>
     Active: active (waiting) since Mon 2022-04-11 20:52:46 UTC; 4min 3s ago
    Trigger: Tue 2022-04-12 00:56:55 UTC; 4h 0min left
   Triggers: ● certbot.service

Apr 11 20:52:46 jammy-encrypt systemd[1]: Started Run certbot twice daily.
```

To test the renewal process, you can do a dry run with certbot:

```
sudo certbot renew --dry-run
```

```
Output
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/your_domain.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for your_domain and www.your_domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
  /etc/letsencrypt/live/your_domain/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
```

If you don’t receive any errors, you’re all set. When necessary, Certbot will renew your certificates and reload Apache to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.
The Mysterious 48-Hour Day for Developers
Tags: developers, development
Published: 2023-06-01 07:17:56

Calling all developers! What if I told you there's a mythical land where the day magically expands to a whopping 48 hours? It's time to embark on a lighthearted journey into this extraordinary realm and discover.

**The Endless Adventure Begins:**
Picture this: the sun rises on the mystical land of the 48-hour day, and we developers find ourselves gazing at twice as much time on the clock. Ah, the possibilities! But wait, before we can even bask in the glory of this newfound abundance, our overflowing inboxes greet us with an avalanche of bug reports and feature requests. It seems like even time itself can't keep up with our coding prowess!

**A Multiverse of Meetings:**
Ah, meetings – those joyous occasions that make our hearts flutter with excitement (or maybe not). In this alternate reality, the number of meetings multiplies like rabbits on a sugar high. We find ourselves teleporting from one conference room to another, desperately hoping that the space-time continuum doesn't collapse under the weight of all these gatherings. Perhaps we could invent a way to teleport snacks too, because surviving these meetings on an empty stomach is a heroic feat.

**The "Perfectionism" Curse Strikes:**
With double the time at our disposal, we now have the chance to fine-tune every line of code to perfection. But beware, dear comrades, for this can lead us down the treacherous path of overthinking and "analysis paralysis." Suddenly, we're contemplating whether a variable should be named "x" or "unicornRainbowMagic." Oh, the agony! Let's remember to strike a balance between excellence and getting things done, or else we might find ourselves lost in a sea of sublime uncertainty.

**The Unexpected Side Quests:**
While the 48-hour day may seem like an epic quest to conquer our backlog, we mustn't forget the wonderful distractions that come along the way. Opportunities to learn new technologies, collaborate with fellow developers, and explore the vast world of open-source projects await us. Let's embrace these side quests, as they offer a chance to grow, expand our skill set, and inject a dose of excitement into our coding adventures.

**A Laughing Matter:**
Amidst the chaos and challenges, it's crucial to find humor in our daily endeavors. A witty comment in a code review, a punny commit message, or even a silly GIF shared on the team chat can lighten the atmosphere and bring a smile to our faces. Laughter is the secret ingredient that keeps us going, even when the workload seems insurmountable.

While the idea of a 48-hour day for backend developers may be more mythical than reality, The overflowing workload, the never-ending meetings, and the temptation of perfectionism become comical twists in our adventure.
Laravel File Viewer - A package to see preview of diffrent file types
Tags: php, laravel, javascript, opensource
Published: 2023-06-01 07:16:56

Laravel File Viewer is a wrapper for implementing different JS libraries to view files according to their types. It supports images, videos, audio, docx, pptx, xlsx and pdfs etc.

Check it now : https://github.com/vish4395/laravel-file-viewer
Inspect your errors: Unwrapping Go errors for fun and profit
Tags: go
Published: 2023-06-01 07:08:49

I've talked about how to _wrap_ errors in go before ([here](https://dev.to/tinydevops/whats-the-proper-way-to-wrap-errors-in-go-3p04) and [here](https://dev.to/tinydevops/use-error-decorators-to-simplify-go-error-handling-3k7f)).

Now let's talk about the various ways to _unwrap_ and inspect errors.

{% youtube https://youtu.be/UjMnAXIVWJg %}
Introduction to File Handling in Python
Tags: python, filehandling, intermediate
Published: 2023-06-01 06:27:04

File handling in Python refers to the process of reading and writing data to and from files. It allows you to work with different types of files, such as text files, CSV files, JSON files, and more. Python provides built-in functions and methods to interact with files, making it easy to perform operations like opening, reading, writing, and closing files.

### Reading Data from a File

To read data from a file in Python, you can use the `open()` function to open the file and then use the `read()` or `readlines()` methods to access the file's contents.

```python
# Opening a file in read mode
file = open('data.txt', 'r')

# Reading the entire file content
content = file.read()
print(content)

# Alternatively, reading line by line
lines = file.readlines()
for line in lines:
    print(line)

# Closing the file
file.close()
```

### Writing Data to a File

To write data to a file in Python, you need to open the file in write mode ('w' or 'a' for append) using the `open()` function. Then, you can use the `write()` method to write data to the file.

```python
# Opening a file in write mode
file = open('output.txt', 'w')

# Writing content to the file
file.write("Hello, world!\n")
file.write("This is a sample text.")

# Closing the file
file.close()
```

### Challenge: Student Grade Management

Create a program that manages student grades by reading and writing data to a file. The program should have the following functionalities:

1. Allow the user to enter student names and their corresponding grades.
2. Write the student data to a file.
3. Provide an option to read and display the student data from the file.
4. Calculate the average grade for each student and display it.

You can structure the data in the file using a suitable format, such as CSV or JSON. Implementing this challenge will give you hands-on experience with file handling, data input/output, and basic data manipulation in Python.

Remember to handle any potential errors or exceptions that may occur during file operations.
Sloan's Inbox: How to Approach Your Manager When Interviewing for a New Job?
Tags: discuss, career
Published: 2023-06-01 07:00:00

Hey there! Sloan here, your friendly neighborhood DEV Moderator 🦥

Welcome back to another edition of Sloan's Inbox, where we tackle all your burning questions and share insightful advice. We're here to support your career development, navigate office politics, stay on top of industry trends, and sharpen those technical skills. So, let's keep the learning and growth going strong!

Now, let's dive into our question of the day. This one comes from Secret Candidate 🤫.

> I'm currently going through the interview process and I'm wondering if it's appropriate to ask my manager for a recommendation. However, I'm unsure whether I should mention that I'm interviewing at other companies. What's your take on this?

Ah, the delicate dance of job hunting and professional etiquette. What do you suggest, DEV Community? Please share your insights and experiences in the comments below. 

---

*Want to submit a question for discussion or ask for advice? [Visit Sloan's Inbox](https://docs.google.com/forms/d/e/1FAIpQLSc6wgzJ1hh2OR4WsWlJN9WHUJ8jV4dFkRDF2TUP32urHSAsQg/viewform)! You can choose to remain anonymous.*
Building Allies: How Can You Support Queer Colleagues in the Workplace?
Tags: discuss, devpride, lgbtq
Published: 2023-06-01 07:00:00

As allies and colleagues, what can we do to show active support and advocacy in the workplace? Share your ideas on creating an inclusive environment, offering support, and amplifying queer voices. 

We kindly ask you to join the discussion with kindness, respect, and open-mindedness. Every voice matters, so let's make sure everyone feels welcomed and valued. Together, we can build an amazing community where everyone can freely express their thoughts and experiences. Let's create an awesome and inclusive space! :heart: 


Follow the [CodeNewbie Org](https://dev.to/codenewbieteam) and [#codenewbie](https://dev.to/t/codenewbie) for more discussions and online camaraderie!

*{% embed* https://dev.to/codenewbieteam *%}*
Representation Matters 🌈 Who Inspires You?
Tags: discuss, devpride, lgbtq
Published: 2023-06-01 07:00:00

It's so important to celebrate the achievements of individuals in the tech industry, and diversity and inclusion play a huge role in that. The inspiring stories of queer figures in the tech world can empower and uplift others. 

[Alan Turing](https://en.wikipedia.org/wiki/Alan_Turing), [Lynn Conway](https://en.wikipedia.org/wiki/Lynn_Conway), and [Tim Cook](https://en.wikipedia.org/wiki/Tim_Cook) are just a few folks who come to mind when discussing inspiring LGTBQ2S+ folks who have made a positive impact on the tech world.

These individuals have seriously shattered barriers, defied stereotypes, and made some major contributions to the tech industry. Their stories are a powerful reminder of why inclusivity matters and how diverse perspectives drive innovation and progress.

There are many more names to share, and one of them might be yours! We'd love to hear about the LGBTQ2S+ individuals who've inspired you, whether they're your heroes, colleagues, friends, or even yourself.
Learn Java
Tags: java, tutorial, beginners, learning
Published: 2023-06-01 07:00:00

In this post, I have summarized the YouTube playlists series for Java Basics and Modern Java courses on my [Debug Agent Youtube channel](https://www.youtube.com/@debugagent/playlists).

>   These courses updates weekly. Start as a beginner on your journey to become a Java pro.

## Java Basics
All you need to know to learn Java with this course is basic grade school algebra and the ability to install software. We start from the very basic concepts of programming to build simple Java applications. Once completed we will connect this course to the "Modern Java Course" and "Debugging at Scale in Production" course.

{% embed https://www.youtube.com/watch?v=1Bum2gYETUQ&list=PL8GhfcywW9YMucwRw2IbpeCp1FBMEgsmk %}

## Modern Java

Many developers learned JDK 1.4 or 1.6 if they were lucky. Then never touched Java again. Left with a memory of a verbose, language. Heavy with complex abstractions and boilerplate code.

Modern Java isn't like that. It will never be as terse as Python. But it makes up for that in other aspects. Its biggest strength is the years of legacy behind it. But it's also the biggest weakness. Developers don't even know what's possible.

With this course I hope to re-introduce you to Java. To show you a dynamic, modern, performant language for the cloud era. I want to show you why Java is still growing nearly 30 years after its public debut.

{% embed https://www.youtube.com/watch?v=3oNT_VRrfqE&list=PL8GhfcywW9YNuNHrG0FAg5xiprfYcYyuL %}

## Debugging Course
This playlist contains the first module of the course: "Practical Debugging at Scale" based on the [Apress book](https://www.amazon.com/dp/1484290410/) with the same title. In these 9 videos we will cover everything that no one taught you about using a debugger. 

Secret features like Marker Objects, Entry Renderers and much more. The full course and the book cover a lot more. 

{% embed https://www.youtube.com/watch?v=A919j_5qE0k&list=PL8GhfcywW9YM3OsfxnaxAci6dJgkuOQWn %}

## DevOps for Developers

In this series we will learn the concepts of DevOps from a perspective of developers. How can these concepts help us be better developers and managers in our day to day jobs. In a startup you might need to fill the shoes of a DevOps, in a big company you might need to communicate with a DevOps team that has wildly different ideas.

We will gain a different perspective and understanding of the entire process by leaving our comfort zone and focusing on the wider picture. We will learn about different disciplines such as platform engineering and so much more.

{% embed https://www.youtube.com/watch?v=2HatFLh4xoA&list=PL8GhfcywW9YOA5i7kEFdNYFuluotS2JTZ %}
importing react and react dom
Published: 2023-06-01 06:54:00

please i need help. i keep seeing this link in html files. they are imported as i read before you can do some coding. the thing is the directories keep changing in different books and sites as i checkout their code. i would like to know how to get the link myself. how and where is it gotten from

<!-- React -->
  <script src="https://unpkg.com/react@17/umd/react.development.js"></script>

  <!-- ReactDOM -->
  <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js">
  </script>
Learn Go Programming - Golang Tutorial for Beginners
Tags: go, programming, webdev
Published: 2023-06-01 06:44:45

Go is an open source programming language created by Google.  As one of the fastest growing languages in terms of popularity, its a great time to pick up the basics of Go!

This course is designed to get you up and running as fast as possible with Go.  We'll quickly cover the basics, then dive into some of the more advanced features of the language.  

Go is designed to be easy to pick up, but tough to master.  Through multiple projects, quizzes, and assignments, you'll quickly start to master the language's quirks and oddities.  Go is like any other language - you have to write code to learn it!  This course will give you ample opportunities to strike out on your own and start working on your own programs.

In this course you will:

   Understand the basic syntax and control structures of the language
   Apply Go's concurrency model to build massively parallel systems
   Grasp the purpose of types, which is especially important if you're coming from a dynamically typed language like Javascript or Ruby
   Organize code through the use of packages
   Use the Go runtime to build and compile projects
   Get insight into critical design decisions in the language
   Gain a sense of when to use basic language features

What you'll learn:

   Build massively concurrent programs with Go Routines and Channels
   Learn the advanced features of Go
   Understand the differences between commonly used data structures
   Prove your knowledge with dozens of included quiz questions
   Apply Interfaces to dramatically simplify complex programs
   Use types to future-proof your code and reduce the difficulty of refactors

{% embed https://www.youtube.com/watch?v=cJaBJVpsAFY %}
MidJourney Tutorial for Beginners
Tags: midjourney, ai, chatgpt, programming
Published: 2023-06-01 06:29:35

Learn everything you need to know about Midjourney without any previous experience in this tutorial! Midjourney is the best big thing and you need it!

Midjourney is an incredible platform that creates any design from your description. Type in anything, literally anything, and Midjourney will create fantastic photos, illustrations, images of all sorts. This is the next BIG thing in tech and you have to jump onboard!

3 reasons to learn Midjourney TODAY:

   Invest in your future - imagine learning to code 20 years ago. Today you would have had a fantastic 6 figure job, fully remote, working for the best companies in the world. Now you have a second chance with this new technology.
   Make money - you can create T-Shirts, sticker packs, patterns, all through Midjourney
   Help companies grow - create beautiful content for their social media, grow their sales, and you will be well paid and respected for your work.

Please don't wait! This is the most important time to get started. By being on the ground floor of this new technology, you make yourself incredibly value. If you wait until things have settled down, you're going to miss out.

If you're a designer, you absolutely need Midjourney to stay relevant. Midjourney + Photoshop is a match made in heaven.

My course is for regular people. I don't assume you have any previous experience in terms of tech, IT, designing, Photoshop or anything else.

   Enhanced Creativity: AI generative art lets you explore innovative artistic possibilities beyond traditional methods.
   Time Efficiency: AI algorithms rapidly generate multiple design ideas, saving time and effort.
   Personalization: AI enables tailored, customized designs based on specific elements or themes.
   Collaboration: Engage with a vibrant, growing AI art community for networking and skill development.
   Economic Opportunities: Master AI art techniques to access new income streams and professional opportunities.

What you'll learn:

   Set yourself up for a 6 figure career by learning AI art right from the start
   Learn how to use Midjourney to create beautiful designs in all sorts of styles
   Understand the most important commands in Midjourney and how to put them to good use
   Create stunning artwork, repeatable patterns, cute stickers, and much more

{% embed https://www.youtube.com/watch?v=8S7KyrSlvHo %}
How to Create Tabs with Tailwind and Svelte
Tags: svelte, tailwindcss, webdev, tutorial
Published: 2023-06-01 06:29:26

In this section we will create tabs in svelte with tailwind css. 

[Install Tailwind CSS in Svelte with Typescript Using Vite
](https://larainfo.com/blogs/install-tailwind-css-in-svelte-with-typescript-using-vite)

###Tool Use
**Tailwind CSS 3.x**
**Svelte**

### Example 1
svelte with tailwind css simple tabs.
```js
<script>
  let openTab = 1;

  function toggleTabs(tabNumber) {
    openTab = tabNumber;
  }
</script>

<div class="flex flex-col items-center justify-center h-screen">
  <div class="flex">
    <div
      class="px-4 py-2 cursor-pointer {openTab === 1
        ? 'bg-blue-600 text-white'
        : 'bg-gray-200'}"
      on:click={() => toggleTabs(1)}
    >
      Tab 1
    </div>
    <div
      class="px-4 py-2 cursor-pointer {openTab === 2
        ? 'bg-blue-600 text-white'
        : 'bg-gray-200'}"
      on:click={() => toggleTabs(2)}
    >
      Tab 2
    </div>
    <div
      class="px-4 py-2 cursor-pointer {openTab === 3
        ? 'bg-blue-600 text-white'
        : 'bg-gray-200'}"
      on:click={() => toggleTabs(3)}
    >
      Tab 3
    </div>
  </div>
  {#if openTab === 1}
    <div>Content for Tab 1</div>
  {:else if openTab === 2}
    <div>Content for Tab 2</div>
  {:else}
    <div>Content for Tab 3</div>
  {/if}
</div>
```
![svelte with tailwind tabs](https://larainfo.com/storage/canvas/images/r9ObsSXLdBF8kiSrxHhLJVYISybSXZiSYPVgrIZJ.png)

---
### Example 2
svelte with tailwind css tabs using each loop.
```js
<script>
  let tabs = [
    { title: "Tab 1", content: "Content for Tab 1" },
    { title: "Tab 2", content: "Content for Tab 2" },
    { title: "Tab 3", content: "Content for Tab 3" },
  ];

  let activeTab = tabs[0].title;

  function setActiveTab(tabTitle) {
    activeTab = tabTitle;
  }
</script>

<style>
  .active {
    background-color: blue;
    color: white;
  }
</style>

<div class="flex">
  {#each tabs as tab (tab.title)}
    <div 
      class="px-4 py-2 cursor-pointer {activeTab === tab.title ? 'active' : 'bg-gray-200'}" 
      on:click="{() => setActiveTab(tab.title)}"
    >
      {tab.title}
    </div>
  {/each}
</div>

{#each tabs as tab (tab.title)}
  {#if activeTab === tab.title}
    <div>{tab.content}</div>
  {/if}
{/each}
```