teleren/devto huggingface dataset:
Pairwise Linked List Swap
Tags: 100daysofcode, programming, java, algorithms
Published: 2021-12-19 12:32:15

# [Description](https://binarysearch.com/problems/Pairwise-Linked-List-Swap/solutions/7076618)

Given a linked list, swap every two adjacent nodes and return its head.

## Example 1:


```
Input: head = [1,2,3,4]
Output: [2,1,4,3]
```

## Example 2:

```
Input: head = []
Output: []
```

## Example 3:

```
Input: head = [1]
Output: [1]
```

## Constraints:

- The number of nodes in the list is in the range `[0, 100]`.
- `0 <= Node.val <= 100`

---

# 解题

## 方法一

### 思路

非递归

### 代码

```java
public ListNode swapPairs(ListNode head) {
    ListNode dummy = new ListNode(0);
    dummy.next = head;
    ListNode current = dummy;
    while (current.next != null && current.next.next != null) {
        ListNode first = current.next;
        ListNode second = current.next.next;
        first.next = second.next;
        current.next = second;
        current.next.next = first;
        current = current.next.next;
    }
    return dummy.next;
}
```

### 复杂度分析

- 时间复杂度: O(n)
- 空间复杂度: O(1)

---

## 方法二

### 思路

draw a graph

1. dummy = new node
2. curr = head
3. prev = dummy
4. prev.next = curr

---

1. prev.next = curr.next
2. curr.next = curr.next.next
3. prev.next.next = curr

---

1. prev = prev.next.next
2. curr = curr.next

**Implementation**

you need to draw a graph like below

- d -> 1 -> 2 -> 3
- d->2
- 1->3
- 2->1
- d -> 2 -> 1 -> 3

### 代码

```java
import java.util.*;

/**
 * class LLNode {
 *   int val;
 *   LLNode next;
 * }
 */
class Solution {
    public LLNode solve(LLNode node) {
        LLNode dummy = new LLNode();
        LLNode prev = dummy, curr = node;
        dummy.next = curr;
        // d -> 1 -> 2 -> 3 (prev=d,curr=1)
        while (curr != null && curr.next != null) {
            // d -> 2
            prev.next = curr.next;
            // 1 -> 3
            curr.next = curr.next.next;
            // 2 -> 1
            prev.next.next = curr;
            // prev = 1 (d -> 2 -> 1 -> 3)
            prev = prev.next.next;
            // curr = 3 (d -> 2 -> 1 -> 3)
            curr = curr.next;
        }
        return dummy.next;
    }
}
```

### 复杂度分析

- 时间复杂度:  O(n)
- 空间复杂度:  O(1)

---
Leet Code - Remove Duplicates from Sorted Array
Tags: java, solution, beginners, learn
Published: 2021-12-19 12:10:18

**`Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.

Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements of nums should hold the final result. It does not matter what you leave beyond the first k elements.

Return k after placing the final result in the first k slots of nums.

Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.`**

**Custom Judge:**

**The judge will test your solution with the following code:**

```
int[] nums = [...]; // Input array
int[] expectedNums = [...]; // The expected answer with correct length

int k = removeDuplicates(nums); // Calls your implementation

assert k == expectedNums.length;
for (int i = 0; i < k; i++) {
    assert nums[i] == expectedNums[i];
}
```

`If all assertions pass, then your solution will be accepted.`

`Example 1:

Input: nums = [1,1,2]
Output: 2, nums = [1,2,_]
Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).
Example 2:

Input: nums = [0,0,1,1,1,2,2,3,3,4]
Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]
Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).`

**Java Solution -**

```
import java.util.*;

class Solution {
    public int removeDuplicates(int[] nums) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i < nums.length - 1 && nums[i] == nums[i + 1]) {
                continue;
            }
            nums[count] = nums[i];
            count++;
        }
        return count;
        
    }
}
```
Laravel Console: Options for your Seeders
Tags: laravel, php, softwareengineering, softwaredevelopment
Published: 2022-01-05 10:00:29

---
title: Laravel Console: Options for your Seeders
published: true
date: 2021-12-19 12:01:10 UTC
tags: laravel,php,softwareengineering,softwaredevelopment
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/0*vMRId1SpuIrMGY_U)
_Photo by Nikola Jovanovic on Unsplash_

Seeding the Laravel database can often be a bit of a chore. It’s fine for small projects but it becomes a pain when you want some flexibility or more complex examples. For instance maybe you want a command option to set an initial size for how many users should be added when running a seeder.

For example maybe we want this code to work:

{% gist https://gist.github.com/peterfox/2fbe84dd9bd1d966b598a58ff419c730 %}

But then when we run it we get the following error:

![](https://cdn-images-1.medium.com/max/1024/1*lXKS8RTcNt9w--7GauNyWw@2x.png)

Well it’s actually surprisingly simple to fix this and make it work and only requires an extra bit of code to our app/Providers/AppServiceProvider.php.

Let’s do the following to our AppServiceProvider.

{% gist https://gist.github.com/peterfox/018c91b8b3ef6387521c4459841d410f %}

As you can see we’ve played with the command as accessed via the service container so when the seeding command is created we add the additional options that will then be equally available to our seeders.

From now on our seeding code behaves as expected.

![](https://cdn-images-1.medium.com/max/920/1*idbmze1X_gGCu3jPc3sSgg@2x.png)

There is sadly, one draw back, currently adding such changes to migration commands would work the same way but would equally require you to then extend the command completely to provide the code to pass these new options into the seeding command at the time of running, which is not overly hard but I won’t be covering it here.

### Conclusion

This trick can be quite useful at times as it adds an extra layer of flexibility to your Laravel app. Seeding is quite a complex process at times and different apps require different things so it’s good to make use of this to customise as your needs change.

I’m Peter Fox, a software developer in the UK who works with Laravel among other things. Thank you for reading my article, I’ve got several more on both medium and dev.to. If you want to know more about me, head over to [https://www.peterfox.me](https://www.peterfox.me/). I’m also now also [Sponsorable on GitHub](https://github.com/sponsors/peterfox?frequency=one-time&sponsor=peterfox). If you’d like to encourage me to write more articles like this please do consider dropping a small one off donation.
How to install tarball (.tar) files in linux
Tags: linux, ubuntu, tutorial, tar
Published: 2021-12-19 06:04:10

Does it happen to you that you that whenever you want to install a piece of software you're give either a `.deb` file or a `.tar` file. Installing `.deb` files is easy, it's just like how you do in windows, but `.tar` files are a pain specially for beginners. 
In this simple tutorial we'll learn how to download and install `.tar` file. I'll use Ubuntu but it should work in most Linux distros. I'll install **waterfox web browser ** but the process is similar for all the tarball (.tar) installation files.

##tldr;

1. download the tar file
2. extract it to some location
3. create a desktop entry for running the application

##Detailed method
###Step 1 :download the `.tar` file and then move it to the directory where you want to install it.
After downloading the file open the terminal in current directory to move the file to `/opt` directory using the following command.
you can change the filename and target directory accordingly.

```
sudo mv  waterfox-G4.0.5.en-US.linux-x86_64.tar.bz2 /opt
```

###Step 2: Extract the `.tar` file
first goto the directory where you moved the `.tar` file.

```
cd /opt/
```

To extract the `.tar` file present in the current directory to use the following command

```
sudo tar xjf waterfox-G4.0.5.en-US.linux-x86_64.tar.bz2
```

you can replace the `.tar` filename i.e. `waterfox-G4.0.5.en-US.linux-x86_64.tar.bz2` as per your filename.

###Step 3: Create desktop entry with appropriate permissions

make yourself owner of the extracted repository

```
sudo chown -R $USER /opt/waterfox
```

Create a desktop entry so that you don't need to come to this directory to launch the application. 
run the following command

```
gedit ~/.local/share/applications/waterfox.desktop
```

it'll open gedit text editor where you need to insert the specifications of the desktop entry.
paste the following in the editor and save.

```
[Desktop Entry]
Name=Waterfox
Exec=/opt/waterfox/waterfox %u
Terminal=false
Icon=/opt/waterfox/browser/chrome/icons/default/default128.png
Type=Application
Categories=Application;Network;X-Developer;
```
Again, change the various parameters and paths according to your setup.
The path can be directly under the first directory or inside bin directory, make sure you specify correct path.

Desktop entry has many parameters but only a few are required but you should add at least these. You can read more at [Desktop Entry Standard](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.3.html)

Finally you need to make your desktop entry executable using the following command.

```
chmod +x ~/.local/share/applications/waterfox.desktop
```
you can change the name of desktop entry accordingly.

finally you can remove the `.tar` file using the following command

```
sudo rm -rf waterfox*.tar.bz2
```
5 factors to consider before making your next career decision
Tags: career, tech, developers, hiring
Published: 2021-12-19 11:49:06

---
title: 5 factors to consider before making your next career decision
published: true
description: Career decisions are life changing. Evaluate opportunities using 5 factors which will help you in making a better career decision.
tags: career, tech, developers, hiring
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ivr17ajk8a5dbupxvsu.png
---

With booming startups and a crazy hiring market, here are 5 things to consider before making your next career decision.


## Market 🚀

What are the growth opportunities in the space? Is it the next big thing or just a new wave? 

Find a domain you're excited about. You'll be investing in them with your time. Choose it wisely!

---

## Learning 💡

Does this help in growing your skillset? Avoid doing the same work for a longer time. Learn new stuff. Get out of your comfort zone!

Learning is a lifelong process.

---

## Impact ✅

What is the kind of impact you'll be creating with this new role? Are your contributions significant and impact at scale? 

You should be proud and have content about what you work on.

---

## Network 🌐

Most people don't really think of this in their career move. Research about the current employees and teams at that company.

Get in a good network. Grow it! Network effects will kick in later if not now.

---

## Compensation 💸

Most people focus too much on this part. It is definitely an important aspect but shouldn't be the deciding factor. 

Over a longer period, your growth matters. Great companies invest in your career and reward you highly over a longer period.

---

Check out more blogs related to programming, tech and productivity at [mohitkhare.com](https://mohitkhare.com/). 

I share regular updates on [Twitter](https://twitter.com/mkfeuhrer). Let's connect!
WHY I STARTED CODING?
Tags: webdev, programming, css, html
Published: 2021-12-19 11:32:03

FIRST OF ALL A BIG THANKS TO @siddharthshyniben FOR ALL YOUR HELP... HE WAS FIRST MY CLASS-MATE THEN MY FRIEND AND THEN MY BESTEST BEST BUDDY :). HE TOUGHT ME EVERYTHING IN THE PROGRAMMING HUB. HE TOUGHT ME HTML CSS AND A BIT OF JAVASCRIPT.HE EVEN ENCOURAGED ME TO WRITE MY FIRST BLOG.IF I EVER BECOME SOMETHING BECAUSE OF PROGRAMMING, I WOULD FIRSTLY THANK HIM (IF HE IS NOT DEAD BY THAT TIME). SO LETS COME TO THE POINT. THE FIRST TIME I EVER CAME TO KNOW EVEN A WORD OF PROGRAMMING, I WAS LIKE A BIG FAN OF IT. I DIDNT HAVE GOOD MATERIALS LIKE A PC AT THAT TIME, BUT SOMEHOW I GOT A PC. AFTER THAT IT WAS A MATTER OF TIME UNTIL I STARTED LEARNING CODING.  AS SAID IN FIRST SIDDHARTH TOUGHT ME THE HTML AND CSS AND I WOULD SAY IT WAS WORTH IT. TOUGH I ONLY MADE SOME QUITE IMPRESSIVE WEBSITES, MY PARENTS LOVED IT. THIS IS MY FIRST BLOG AND THIS IS KINDA WIERD BUT YEAH THIS IS THE END. HOPE YOU LIKED THE "**NOT SOO IMPRESSIVE**" BLOG,  HAVE A GREAT DAY TO ALL!
Free nextjs template for portfolios and personal blogs
Tags: nextjs, mui, typescript, react
Published: 2021-12-19 11:01:49

preview [here](https://the-bag.vercel.app/)
source code [here](https://github.com/hajhosein/theBag)

## Why should you create your blog or portfolio?

If you have the ability in all areas of the world, without properly introducing your abilities, you did not use them at all. It does not matter if you are a programmer or an architect, or a designer or ..., having a portfolio increases your chances of a better and more comprehensive introduction. So if you are going to apply for a job or a university field or a suitable position that you are considering, you should use a blog or portfolio to introduce yourself and your abilities and activities well.

## What is theBag?
theBag is a multipurpose template created with Nextjs and MUI V5 which can be used for Portfolios, Resumes, CVs, and Personal websites and blogs.

check it out [here](https://the-bag.vercel.app/)

## About 
This project is created by [NextJs](https://nextjs.org/), [Mui v5](https://mui.com/) (formerly Material-UI) using typescript.

- More than 30 reusable components
- 5 custom icon component 
- 9 section component
- 1 layout

## Some features

- Images will be optimized because of using nextjs Image component
- Mui Skeleton for images while loading
- Links are wrapped by nextjs Link component
- Smooth scrolling
- Mui Grow effect
- Typing effect
- Swiperjs custom slider for showing recent projects or anything else that you want.
- Custom image carousel using swiperjs
- Formik for forms
- Yup for form validation
- Dynamic page for an individual project
- Dynamic page for a blog post
- Completely responsive for all devices

## License
Well, theBag is a completely free template to use for both personal and commercial purposes. Actually there is no limit.

## How to use it?
Project source code is available on [github](https://github.com/hajhosein/theBag) and you can check it out from this link. You can download it or fork it in case you wanna get notified on changes.

## Some of lighthouse results

- home page

![a screenshot of lighthouse result of theBag home page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f7nk2zlarn82ecosnbo.png)

- hire me page

![a screenshot of lighthouse result of theBag hire me page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bab90b9cr1zmh0nqkks.png)

- my projects page

![a screenshot of lighthouse result of theBag my projects page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oufj06dixg6t51ncpwd9.png)

## Conclusion
Although this is a free template, I have provided it with great care and time so that you can make the most of it. Let me know your comments, suggestions, and criticisms.



---

[![A banner of become a backer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fnb2hbuk8abtl1amqxhi.jpg)](https://hpouyanmehr.com/backers#donate)

Hi! I'm **Hosein Pouyanmehr**. I enjoy sharing what I learn and what I find interesting. Let's connect on [LinkedIn](https://www.linkedin.com/in/hpouyanmehr/).

See my code interests on [GitHub](https://github.com/HPouyanmehr).
Day 95/100 The Internet
Tags: 100daysofcode, programming, design, motivation
Published: 2021-12-19 10:48:15



![banner](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2j7a17h0cq72fr2i3508.png)

## The Internet, Explained

**What is the difference between the internet and the world wide web?**
- What is the difference between the internet and the world wide web?
- The web has become so popular that many people now regard it as synonymous with the internet itself; but this is a misconception.

**Where is the internet?**
- The internet is compromised of data centers, long fiber optic cables, and cable companies that ensure distribution to paying customers via cables, towers and DSL service.

**What is a web browser?**
- A computer program that allows users to download and view websites.
- A computer program that allows users to download and view websites.

## Cover Background 
Someone commented that the background cover I used the entire challenge is funny. I hope that person visit museums and admire the painting for a minimum of 2 mins at least. I could accept that, but in every art piece there is a story. My story, I'm heartbroken, I quit my job and drop out at school. I have no friends and nobody wants to help me. Instead of whipping and making myself sad, I used the internet to do something. That's when I started coding, others view it as pretty boring and needs a lot of time solving problems. I thought it would be perfect for me, since I'm devastated and all. I got nothing to loss, it was a perfect excuse for me to cope with the pain. Then until, the man I meet 2 years ago, keep on hunting me. I'm not sure what's his purpose, but I'm entirely sad that he left me heartbroken and doesn't want me to forget him. Learning to code has become my way of letting go.

## Summary
This probably my last day posting, I could not afford to pay the internet and electricity bills. I only have 40% left in my battery, I won't know when I can pay the bills. Today, I cowardly shared my feelings and sentiments through the Internet. 

[
![resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sar5mxsnqoqz8csu7v6.png)](https://www.vox.com/2014/6/16/18076282/the-internet)
Log4j 2: DoS に関わる新たな脆弱性 (2.16.0 とそれ以前のバージョン)
Tags: log4j, vulnerability, security, dos
Published: 2021-12-19 10:45:58

[Log4j](https://logging.apache.org/log4j/2.x/) 2.17.0 がセキュリティ向け更新のためにリリースされました。2.16.0 とそれ以前の 2 系のバージョンに存在する DoS 脆弱性を修正します。

この新たな DoS (denial-of-service) 脆弱性について、次の場合は安全です: ログ設定で、`$${ctx:loginId}` のような Context Lookup 設定が使われていない、デフォルトの Pattern Layout の場合。
そうでない場合は、CVSS スコアが 7.5 であり、深刻度は高いです。

Log4j 2 で、`$${ctx:loginId}` のような Context Lookup 設定を持つ、カスタマイズされている Pattern Layout のものに関しては、バージョンを 2.17.0 に更新することが推奨されています。[CVE-2021-45105](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45105) と呼ばれる本脆弱性を修正するためです。サービスダウンを引き起こされる危険があります。

それが難しい場合は、次の方法で緩和することが可能です。Log4j 2 の非デフォルトの Context Lookup 設定を Thread Context Map パターン (%X, %mdc, or %MDC) に置き換える、あるいは、設定の中でそれらの設定への参照を削除します。
[The Apache Software Foundation](https://www.apache.org/) から情報が提供されています:
https://logging.apache.org/log4j/2.x/security.html

---

本記事は[小社のツイート](https://twitter.com/scqrinc/status/1472517127722926085)をもとにしています。
Praise for the Pomodoro Timer
Tags: productivity
Published: 2021-12-19 10:34:34

Until earlier this year I didn't really think about the pomodoro timer. It was something that came up a lot in programming challenges and there were tons of them on the internet and in app stores. But then I discovered how useful it was at work. Here's why.

## Makes you take a break
It took me a while to notice, but I eventually realised that the trouble with working from home was that I didn't get distracted. At work I'd have people coming to my desk to ask questions, there'd be something going on in the office that I'd tune into. People brought dogs in that would want attention. Even going to the kitchen for a drink could end up turning into a chat.

At home there's none of that. There is some: there might be something interesting going on outside, the postman might deliver a parcel, but it's not as much. Colleagues trying to reach you will have to use email or messaging and that's easier to ignore than a person at your desk.

As a result I quite often got into something and only realised how long I'd been doing it until something hurt and I looked at the clock. The Pomodoro timer makes me take a break every 25 minutes (unless I ignore it...).

## Makes something boring less long
There are days where you have to do something boring or that you hate. It needs doing, it has to be done and it's hard to contemplate the next n hours of it. With the Pomodoro timer, you only have to contemplate 25 minutes of it at a time. 25 minutes is an amount of time it's possible to get through and makes the task less daunting.

## Taking breaks helps you think
When you're stuck on a problem sometimes the best thing to do is to take a break. When in the office I used to find that going to the toilet worked well. It was a bit of a walk, so by the time I'd got there, I'd generally come up with an idea.

I'll sometimes spend my 5 minute break playing around on my phone or I'll do some job around the house, like a bit of tidying or putting some washing away. It's spending some time away from my desk that really helps.

## It's hard to concentrate for a long time
It just is. I initially thought that effectively only working for 50 minutes every hour would mean I'd get less done. But actually I get more done. Because I know I have to spend 25 minutes focussing on work and then spend 5 minutes doing something else. I'm more efficient in that 25 minutes than I would be in a half an hour spent sometimes focussing and sometimes drifting off.
🏆 MiroTalk - WebRTC - SFU - Open Source - alternative to Zoom - Microsoft Teams - Google Meet
Tags: webrtc, showdev, opensource, github
Published: 2021-12-19 10:26:00


**GitHub**: https://github.com/miroslavpejic85/mirotalksfu
**Demo**: https://sfu.mirotalk.com

![MiroTalk SFU](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pvv0qrsp08gc0mgw3o1.png)

_Nothing is really ours until we share it.
(C.S. Lewis)_