teleren/devto huggingface dataset:
Spring - Dependency Injection
Tags: spring, java, oop, interview
Published: 2022-04-17 14:04:34

Dependency Injection is the most important feature of Spring framework. It is a design pattern where the dependencies of a class are injected from outside. It ensures loose-coupling between classes. 

In a Spring MVC application, the controller class has dependency of service layer classes and the service layer classes have dependencies of DAO layer classes. Suppose class A is dependent on class B. 


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

In normal coding, you will create an object of class B using ‘new’ keyword and call the required method of class B. However, what if you can tell someone to pass the object of class B in class A? Dependency injection does this. You can tell Spring, that class A needs class B object and Spring will create the instance of class B and provide it in class A. In the above example, we can see that we are passing the control of objects to Spring framework, this is called Inversion of Control (IOC) and Dependency injection is one of the principles that enforce IOC.

```java
class ClassA {
  ClassB classB = new ClassB();

  int doCalculation() {
    return classB.calculate();
  }
}
```

## Here comes the @Autowired keyword

❗Before Spring 4.3, we had to add an @Autowired annotation to the constructor. With newer versions, this is optional if the class has only one constructor.

Thanks to the @Autowired annotation, we can inject the values ​​in a bean into another bean and use them while preserving their values in Spring. There are multiple ways inject but among "Property Based", "Setter Based" and "Constructor Based" we will use "Constructor Based" to benefit from Dependency Injection. You may google them for further details and the see the differences.

> This is why we use constructor based injection "All required dependencies are available at initialization time"

## Code please...

We'll see that an instance of MyBeanToInject is injected by Spring as an argument to the MyService constructor:

```java
public class MyService {
    private MyBeanToInject myBeanToInject;
    @Autowired
    public MyService(MyBeanToInject myBeanToInject) {
        this.myBeanToInject = myBeanToInject;
    }
}
```

## To sum up 🏁

**Advantages**:

- A basic benefit of dependency injection is decreased coupling between classes and their dependencies.
- By removing a client's knowledge of how its dependencies are implemented, programs become more reusable, testable and maintainable.
- Dependency injection reduces boilerplate code, since all dependency creation is handled by a singular component

**Disadvantages**:

- Overuse can cause management problems and other problems.
- Many compile time errors are passed to runtime
WWDC22 | iOS16?
Tags: ios, mobile, discuss, apple
Published: 2022-04-17 13:48:40


Apple announced in April that WWDC 2022 will be held in early June. From June 6th through to June 10th. 

Apple is expected to introduce iOS 16 at this event. 

What features would you like Apple to include and introduce on iOS16 and what does this mean for development? 

Let me know your thoughts and wether you will be watching WWDC22.
Bend your Brain towards learning!
Tags: beginners, tutorial, discuss, career
Published: 2022-04-17 13:41:11

Listen to your brain and figure out what works for you and what doesn’t. Try new things.

## *1. Slow down. The more you understand, the less you have to memorize.*

Don’t just read. Stop and think. When the book asks you a question, don’t just skip to the answer. Imagine that someone is asking the question. The more deeply you force your brain to think, the better chance you have of learning and remembering.

## *2. Do the exercises. Write your notes.*

We put them in, but if we did them for you, that would be like having someone else do your workouts for you. And don’t just look at the exercises. Use a pencil. There’s plenty of evidence that physical activity while learning can increase learning.

## *3. Read the “There Are No Dumb Questions”*

That means all of them. They're not optional side-bars — they’re part of the core content Sometimes the questions are more useful than the answers.

## 4. Don’t do all your reading In one place.*

Stand-up, stretch, move around. change chairs, change rooms. It’ll help your brain feel something, and keeps your learning from being too connected to a particular place.

## *5. Make this the last thing you read before bed. Or at least the last challenging thing.*

Part of the learning (especially the transfer to long-term memory) happens after you put the book down. Your brain needs time on its own, to do more processing. If you put in something new during that processing time, some of what you just learned will be lost.

## *6. Drink water. Lots of It.*

Your brain works best in a nice bath of fluid. Dehydration (which can happen before you ever feel thirsty) decreases cognitive function.

## *7. Talk about It. Out loud.*

Speaking activates a different part of the brain. If you’re trying to understand something, or increase your chance of remembering it later, say it out loud. Better still, try to explain it out loud to someone else. You’ll learn more quickly, and you might uncover ideas you hadn’t known were there when you were reading about it.

## *8. Listen to your brain.*

Pay attention to whether your brain is getting overloaded. If you find yourself starting to skim the surface or forget what you just read, it’s time for a break. Once you go past a certain point, you won’t learn faster by trying to shove more in, and you might even hurt the process.

## *9. Feel something!*

Your brain needs to know that this matters. Get involved with the stories. Make up your captions for the photos. Groaning over a bad joke is still better than feeling nothing at all.

## *10. Type and run the code.*

Type and run the code examples. Then you can experiment with changing and improving the code (or breaking it, which is sometimes the best way to figure alit what’s happening).
Javascript Set data structure
Tags: javascript, set, datastructure, programming
Published: 2022-04-17 13:40:37

**Set**: Set data structure allow to add data to a container.

Here is an example of set internal implementation.

```
const Set=function(){
  let collection=[];
  this.size=function(){
    return collection.length;
  }
  this.has=function(item){
   return collection.indexOf(item)!==-1
  }
  this.add=function(item){
    if(!this.has(item)){
      collection.push(item)
      return true;
    }
    return false;
  }
  this.delete=function(item){
    if(!this.has(item)){
      return false;
    }else{
      let index=collection.indexOf(item);
      collection.splice(index,1);
      return true;
    }
  }
  this.clear=function(){
    collection=[];
  }
  this.values=function(){
    return collection;
  }
}
let set=new Set();
console.log(set.size());
console.log(set.add(1));
console.log(set.add(2));
console.log(set.size());
console.log(set.delete(2));
console.log(set.delete(2));
console.log(set.size());
```

> _Any comments or suggestions are welcome._
Day 12: React & Redux
Tags: 100daysofcode, beginners, javascript, react
Published: 2022-04-17 13:39:31

*The Feyn- oops, too lazy today lol*

## `react-redux` Package

We can finally use Redux with React after this long journey (of a few days 🤣), using the `react-redux` package. This package includes several tools to improve the integration of Redux in React.

## Why?

React's state is a mess when things get complex (remember that even if *one* state updates, we have to write a boilerplate for ALL the other state). Redux is library that can manage state. You see where this is going?

## Initiate the integration 🚀!

First, we have to create a `Provider`:
```js
const Provider = ReactRedux.Provider;
```
Provider is a Redux wrapper for React that basically says: "I'm in charge of everything under here.". Simply wrap them around your *whole* React app and you're set!
```js
let store = Redux.createStore(reducer);

// In a render() method...
<Provider store={store}>
  <App />
</Provider>
```

## This state only!

We can restrict component's access to certain state only with the `mapStateToProps()` function:
```js
const mapStateToProps = state => ({
  light: state.brightness
});
```
We can then access `brigtness` inside state.

## Afterwords

Today's blog is short cause most of the time I tried to revise what I have learned about React, and they really put it to the test. Hopefully after getting my hands messy on them, the knowledge stuck.

Anyway, good luck to others who are completing this challenge!

Follow me on [Github](https://github.com/Kemystra)!
Also on [Twitter](https://twitter.com/kemystra)!
A self-dismissing dialog in Groovy
Tags: groovy
Published: 2022-04-17 13:26:27

---
title: A self-dismissing dialog in Groovy
published: true
description: How to display a dialog that is displayed for a duration in Groovy
tags: #groovy
cover_image: ![Popup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1ochup8hn0aogldu91p.png)
---
During the running of your program, you may want to display a dialog. It is easy with:

```
import javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, "Message", "Title", JOptionPane.INFORMATION_MESSAGE)
```

However, it needs manual intervention to be dismissed. If you are running an automated test and want to display some kind of progress, the following works well:

```
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.SwingConstants

(1..5).each { testCase ->
	popup("Attention", "test case ${testCase} is currently running", 3)
	// call test case
}


def popup(String title, String message, int duration) {
	String markup = "<html><font color='blue'><b>Progress: <b><i>" + message + "</i></font></html>"
	JLabel l = new JLabel(markup)
	l.setHorizontalAlignment(SwingConstants.CENTER)
	JPanel p = new JPanel(new java.awt.GridLayout(0, 1))
	p.add(l)
	JFrame f = new JFrame(title)
	f.setContentPane(p)
	f.setSize(300, 100)
	f.setLocationRelativeTo(null)
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
	long startTime = System.currentTimeMillis()
	while (System.currentTimeMillis() < (startTime + (duration * 1000))) {
		f.setVisible(true)
	}
	f.setVisible(false)
	f.dispose()
}
```
The message is in HTML and can be edited however you want with HTML tags.
I started recording programming videos?
Tags: swiftu, mobile, youtube, beginners
Published: 2022-04-17 13:21:43

It's currently **Sunday 17th April** (Happy Easter!) I woke up this morning and decided I wanted to try and do something different. 

So, I made a coffee, had my porridge and booted up my MacBook with the idea of recording a couple of videos covering SwiftUI and the process of integrating Firebase. For experienced developers this is a breeze but for newbies just starting their adventure in Swift and mobile development it can be daunting. 

The first video I recorded and released covers the process of setting up an Xcode project, setting up Firebase, adding and initialising the Firebase SDK. Pretty simple right?..

The reason behind the sudden desire to release a few videos here and there, is mainly to be more active in the community and offer help to people just starting out. 

I plan on recording setting up Auth, managing users , signing in etc. Next week.

If you have a spare couple of minutes and wish to check out the video here it is: [Video Link](https://www.youtube.com/watch?v=e0z6be-sQfQ)

Thank you for reading!
Happy Coding!
Django, Python Demand
Tags: python, django, webdev
Published: 2022-04-17 13:12:48

Hello guys, happy to be here.
So  I'm planning to start my Django and Python Courses for the sole purpose of web development and backend specifically. But i noticed there are not alot of demand on django and python. I know there is a possibility i might not be searching well but i'll like to know if learning those 2 skills is worthwhile.


Thanks
Django Tutorial Part 7 -- template を使う
Tags: django
Published: 2022-04-17 13:01:32


## 何をするのか

Django Tutorial の template 編

https://docs.djangoproject.com/en/4.0/intro/tutorial03/#write-views-that-actually-do-something

projectName/settings.py の TEMPLATES/'APP_DIRS' を False にしていると

> TemplateDoesNotExist at /polls/

で読み込めなくなる。

---

## views.py の index で template と context(Question) をセットする

```py
from django.http import HttpResponse
from django.template import loader
from .models import Question

def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
        'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))
```

* HTTP レスポンスを返すための HttpResonse
* template を読み込むための loader
* Question テーブルを読み込むための .models

これらをインポート

Question テーブルの中身をリストで取ってきて、日付で並べ替え、5つまでに制限して
(polls/template/の) polls/index.html を読み込み
context として上記のリストをオブジェクトとしてセットする
そして、テンプレートで context と共に request の response を返す。

https://docs.djangoproject.com/en/4.0/intro/tutorial03/#a-shortcut-render

loader の代わりのに render を使うやり方もある。

```py
from django.shortcuts import render
...
render(request,'polls/index.html', context)
```

render のライブラリを使って、
直接 template 配下のファイルを読み込んで template として渡すことができる。request と context は同じ。

---

## template フォルダを作って index.html を作成する


polls アプリに

`polls/templates/polls/index.html`

として html ファイルを作る

```py
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
```

Django は `{% %}` のブロックでロジックをかける。
if と else で条件の True False によって見せる方を変えられる
for と endfor で context で渡されたリストをリンク当てて展開する。

---

## ブラウザで確認する


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5po9ay1w9pbw99yn0fc9.png)


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

template が表示されて、詳細にも飛べた。
What is Jira?
Published: 2022-04-17 12:55:56


    
    Jira is a tool developed to help teams for project management, bug tracking, and issue tracking. In simple terms, it is an issue tracker. Jira is widely used by big companies in software development and software testing.

- Which hosting options are available for Jira Software?
    
    There are three hosting options available: Atlassian Cloud, Server, and Data Center (Amazon Web Services (AWS) and Microsoft Azure).

- What is project key in Jira Software?
    
    A project key is a unique code for your project. Jira Software will automatically generate a short project key in accordance with your project name. However, if you want to specify this auto-generated key yourself, you can change it.
    
    **💡Tips:**
    
    - A project key is a unique code for your project.
    - Jira Software will automatically generate a short project key in accordance with your project name.
    - However, if you want to specify this auto-generated key yourself, you can change it.
- Explain briefly what is backlog.
    
    A backlog is a list of issues that can be created for your project. You can create issues and sprints in the backlog. Then, you can add issues to a sprint so that your team can work on it.
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lc2qigd3pes7f2pi7yxg.png)
How to combine animation and mask effect using a specific SVG image
Tags: html, css, help
Published: 2022-04-17 12:40:36

I have an image with an overlay background color which has some opacity, and I want to create a "hole" effect on this image.

I want the "hole" to be a specific SVG image that I have, and I want this image to rotate.

I have created 2 examples in Codepen to help you understand what I want:

1) Hole effect without animation: https://codepen.io/Giordanidis/pen/qBpQGVd

2) Hole effect with animation (but without the "hole"): https://codepen.io/Giordanidis/pen/OJzaYZz

In the 1st example, you can see the background image, the background (black) color which has a 75% opacity, and also the SVG image (the heart icon) which acts like a "hole" and you can actually see "behind" the black color. What is missing here is the animation part that you can see in the 2nd example.

In the 2nd example, you can also see the background image and the background color, and also the SVG image, without the "hole" effect, but with the animation (rotation) I want.

My problem is that I cannot combine these two. As already mentioned I just want to somehow add the rotating animation (which you can see in the 2nd example) to the 1st example.

Is there any way I can do it with CSS or JS?

I appreciate your help! Thanks in advance!
STEPS IN CREATING DASHBOARDS IN CLOUDWATCH
Tags: beginners, webdev, tutorial, aws
Published: 2022-04-17 12:37:15

CloudWatch is an amazon service that is used to monitor your AWS resources. To be able to use CloudWatch effectively, you should have a resource in place, for instance, an Ec2 instance. In this demonstration, we will be creating a dashboard to monitor our Ec2 instance. 

The steps involved are as follows

- Log in to your AWS console 

- Use the search bar to search for CloudWatch and click to open the CloudWatch console.

![A shot of searching CloudWatch in the search bar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mw7u840ww2jz3shsj8v0.png)

- On the left pane of the console, click on the dashboard

![click on Dashboard on the left pane](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxt6zbybtggjsrs8xzxx.png)

- Click on create Dashboard to create a new Dashboard

![create Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nt40nzfmdr9h42rv17qk.png)

- Name your dashboard and click on create Dashboard.

![Name your Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zj5k374wpjxn6hitmhm.png)

- Select a widget to add to your widget. (for the purposes of demonstration we will be selecting pie as our widget.

![Select widget](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9cqehwr558tbvzohj2o.png)

- Select the data source for your Widget. ( for demonstration purposes we will be using metrics)

![Widget data source](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/finq9oz5vi4jfro6m1be.png)

- Then go ahead to select any of the metrics. ( I will be selecting Ec2 for this demonstration and go ahead to select Pre instance metrics)

![Select any of the metric](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqvljdbkhdgb1ihhlnet.png)

- Select any instance as your Widget data source.

![Select any of the Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nj7n3opkc09drys9wqnt.png)

- Click on create Widget and save Dashboard after that.

![Final look of our dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szq3nm6gwk54udmlid06.png)

**In the Next writeup, I am going to explain the use alarms in cloudWatch and how to set them up.**
The Real Reason You Can't Find Dislike Counts on Social Media
Tags: freedomofspeech, antitrust, liberty, freedom
Published: 2022-04-17 12:36:08

YouTube,LinkedIn and other mainstream social networking platforms that are known for suppression of freedom of speech either do not include a dislike button or do not display the dislikes' count.

YouTube provided a weak argument on why they removed the dislike count saying that certain creators were being targeted with dislikes. However, many people across the web found this to be unconvincing and poor argument since we know that YouTube hates creators and is ready to ban/demonetize the creators for the silliest and most ridiculous reasons given YouTube is a wealthy corporation with a revenue of 28.84 billion US dollars. (Source: [https://www.statista.com/statistics/289658/youtube-global-net-advertising-revenues/](https://www.statista.com/statistics/289658/youtube-global-net-advertising-revenues/)). However, what no body mentioned is the fact that this is nothing more than another psychological trick to make controversial topics including hate speeches seem acceptable to the public. Imagine if there was a dislike count while someone was trying to convince you that racism and violence are Ok. 

The majority of people who don't pay attention to details are more likely to be deluded that the contents of a video or a post are Ok and acceptable if it has 100s of likes but no one pays attention to whether or not the message of the video are morally acceptable or something that goes against all human ethical moral values. Here, we are not arguing about LBGT or feminism but rather, we are arguing about very fundamental human right violations where certain political parties promote hatred against innocent people on those platforms with pure impunity. Most of those politicians have a leverage of maybe owning a huge amount of stocks in that platform or have an influence on the rules that could make or break the corporation; I'm not talking about Elon Musk since Elon Musk proved to be in favor of freedom of speech at certain occasions.

You, as a human being with a mind and soul should not accept being treated as a puppet; you should not accept being programmed against your own freewill.

We may not be able to defeat the multi billion corporations, but we are able to change the battlefield by simply not using their platforms, not signing up and not investing/uploading videos on their platforms.

It is ok to watch a video or a post if it's something educational posted by someone with good intentions; but we need to let go of those platforms and consider as if they don't exist. There are plenty of alternatives that have more respect for us as human beings than those platforms:
The best YouTube alternatives: (Source: [https://nordvpn.com/blog/youtube-alternatives/](https://nordvpn.com/blog/youtube-alternatives/)

    1. Vimeo
    2. DTube
    3. Internet Archives Video Section
    4. Metacafe
    5. 9GAG TV
    6. Dailymotion
    7. Vevo
    8. Twitch
    9. TED
    10. Crackle