teleren/devto huggingface dataset:
Singly Linked List Series: Creating get() and set() methods with JavaScript
Published: 2022-12-10 18:03:13

One can create a number of methods to manipulate a Singly Linked List.  Today, I will do my best to share what I understand about creating get() and set() methods.  A get() method receives an index parameter and retrieves a node at that particular index.  Since Singly Linked Lists are not indexed like arrays, one must create a counter to keep track of "indexes."  Let's start with a visualization for creating this method:

![Drawing that shows how to build a get method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m5do74tuni82enjqrcom.png)

Edge case: if the index is a negative number or greater than or equal to the length of the list, you can return undefined because that index does not exist.  Otherwise, follow the steps above.

Here is an example of code for a get() method:

![Code that shows how to build a get method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a3ou53tc6trlnkpvhhqt.png)

A set() method changes the value of a particular node.  This method accepts index and value parameters.  The visualization looks like this:

![Drawing that shows how to build a set method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v93lqyx2m45rhvuntg29.png)

Here is an example of code for a set() method:

![Code that shows how to build a set method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni9du3aw56cy5930yp9w.png)

The time complexity of a get() and set() method for a Singly Linked List is O(n) linear time because the number of operations increases as the lists' length increases.  As I learn more about these topics, the methods become a bit more complex.  Share your comments or corrections if there is anything written above that is incorrect.  Next week, I will share what I have learned about creating insert() and remove() methods.
Advent of Code 2022 - Day 10
Published: 2022-12-10 18:02:58

---
title: Advent of Code 2022 - Day 10
published: true
description: I'm trying to solve all the Advent of Code puzzles in this video series.
tags:
cover_image: https://i.ytimg.com/vi/89o7PrT__TA/maxresdefault.jpg
---

{% youtube 89o7PrT__TA %}

I'm trying to solve all the Advent of Code puzzles in this video series.
How to use tmux
Published: 2022-12-10 17:54:28

tmux is a terminal multiplexer that allows you to split a single terminal window into multiple areas and run multiple commands in those areas. It's useful for those who need to run multiple commands or applications at the same time in the terminal, as it allows you to organize and switch between them easily.

To install tmux, you first need to check if the package is available in your package manager. On Ubuntu, for example, you can use the command `sudo apt-get install tmux` to install it.

Once installed, you can start it by typing `tmux` in the terminal. This will create a new tmux session, in which you can split the terminal window into multiple areas.

To split the window horizontally, press `Ctrl-b` followed by `"`. To split the window vertically, press `Ctrl-b` followed by `%`. You can switch between the areas using the arrow keys on your keyboard.

There are many other options and features available in tmux. For more information, see the official tmux documentation on their website.

## The main keys for tmux

- `Ctrl-b`: The prefix key that must be pressed before other keys to send commands to tmux.
- `"`: Splits the terminal window horizontally.
- `%`: Splits the terminal window vertically.
- Arrow keys: Allow you to navigate between the split areas of the terminal window.
- `?`: Shows the list of tmux commands.

In addition to these basic keys, tmux has many other commands and options that can be found in the official tmux documentation.

You can configure tmux by editing the tmux configuration file, which is usually called `.tmux.conf` and is stored in the user's home directory.

To edit the configuration file, you can use a text editor such as `nano` or `vim`. For example, to edit the file with `nano`, you can use the command `nano ~/.tmux.conf`.

Once in the configuration file, you can add options and commands to customize tmux according to your needs. For example, you can change the tmux shortcut keys, change the color of the windows, or add new commands.

The tmux documentation contains more information about the available configuration options and how to use them. It is recommended that you consult the documentation for more details on how to configure tmux.


## Some of the main advantages of using tmux

- It allows you to split a single terminal window into multiple areas and run multiple commands or applications in those areas at the same time. This makes it easy to organize and manage multiple commands or applications in a single terminal.
- It allows you to save and retrieve tmux sessions, which is useful when you need to continue working on a set of commands or applications at a later date.
- It allows you to access tmux sessions from multiple devices, which is useful when you need to access the same set of commands or applications on different devices.
- It has many configuration options and features that allow you to customize tmux according to your needs.

<br />

[![Texto alternativo da imagem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png)](https://www.linkedin.com/in/israel-lopes-419a32189)
Need to minify js file in next js
Tags: nextjs, javascript, webpack, react
Published: 2022-12-10 17:44:58

Hi,

We are developing website using next js. I have two js files. It's for janrain integration. It's not a react component. So I kept in static folder. Normally static folder copied on build folder after build. Now I need to minify this two js files and move to build folder. How can I do this in next js?

Thanks in advance.
[GCP] How To Create HA VPN On GCP
Tags: googlecloudplatform, cloudvpn, havpn
Published: 2023-12-30 12:53:43

---
title: [GCP] How To Create HA VPN On GCP
published: true
date: 2022-12-10 17:27:53 UTC
tags: 
- GoogleCloudPlatform
- CloudVPN
- HAVPN
canonical_url: https://www.kmp.tw/post/howtocreatehavpnongcp/
---

# Architect

![](http://img.kmp.tw/gcphavpn01.png)

# How To

## Step 1

### Click `VPN Setup WIZARD`
![](http://img.kmp.tw/gcphavpn02.png)


## Step 2

### Choice `High-availability (HA) VPN` And Click `CONTINUE`
![](http://img.kmp.tw/gcphavpn03.png)

## Step 3

### Create VPN Gateway
#### - Enter `VGW` Name
#### - Choice VPC
#### - Choice Region
### Then Click `CREATE & CONTINUE`
![](http://img.kmp.tw/gcphavpn04.png)

## Step 4

### Create VPN Tunnels
### Click `On-prem or Non google Cloud` And Select `CREATE NEw PEER GATEWAY`
![](http://img.kmp.tw/gcphavpn05.png)

### Enter Peer VPN Gateway's Name And Enter Interface Of Your On-Prem
![](http://img.kmp.tw/gcphavpn06.png)


### Create Cloud Router For HA VPN
- #### Enter The Cloud Router Name
- #### Enter The Google ASN Num (64512 - 65534, 4200000000 - 4294967294)
- #### Enter Keepalive Time
### Then click `Create`
![](http://img.kmp.tw/gcphavpn07.png)

### Create Certificate
- #### Enter The Certificate Key Name
- #### Choice IKE Version
- #### Enter oOr Generate IKE Key
### Click `CREATE & CONTINUE`
![](http://img.kmp.tw/gcphavpn08.png)

### Create BGP Session
- #### Enter BGP Session Name
- #### And Peer ASN
- #### Enter `Cloud Route BGP IP` * `BGP Peer IP`
#### (Options)
- #### Choice Advertised Routes
- #### Choice BFD
![](http://img.kmp.tw/gcphavpn09.png)

### After Create And Setting On-Prem Router, You Can Go To Dashboard Check `Tunnel Status` & `BGP Status`
![](http://img.kmp.tw/gcphavpn10.png)
My Experience Using the Chat GPT for Solving LeetCode Problems😏
Tags: chatgpt, ai, programming, gpt3
Published: 2022-12-10 17:09:36

As a software developer, I am always on the lookout for tools and resources that can help me solve problems more efficiently. One such tool that I recently discovered is the Chat GPT, a large language model trained by OpenAI that is capable of providing instant explanations and solutions to programming problems.

I recently had the opportunity to use the Chat GPT during a LeetCode contest, and I was amazed by its accuracy and speed. The contest required me to solve a series of challenging algorithms and data structures problems within a limited amount of time. With the help of the Chat GPT, I was able to quickly understand the problem statements and generate accurate solutions in a fraction of the time it would have taken me to solve them on my own.

One of the problems that I solved using the Chat GPT was a sequence problem that required me to determine whether it was possible to obtain a strictly increasing sequence by removing no more than one element from an array of integers. The Chat GPT provided me with a detailed explanation of the problem and a step-by-step solution in pseudocode, which I was able to easily convert into working C++ code.

Overall, I was extremely impressed by the accuracy and speed of the Chat GPT, and I would definitely recommend it to other programmers who are looking for a helpful and efficient tool for solving algorithmic problems.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oyhrk8pqlecqwzrkfiw0.png)
Escola M60 3.0 com Matheus Tomoto
Published: 2022-12-10 16:50:38

Faça Sua Inscrição Agora. Por Apenas 12 x de R$ 194,56. 

**Acesse o Site Oficial do Curso e Realize sua Inscrição Agora Mesmo.**

[![button](https://net-curso.com.br/wp-content/uploads/2022/11/escola-m60-768x256.png)](https://go.hotmart.com/Y74922706I?src=devto)

[![button](https://chefpenninha.com.br/wp-content/uploads/2019/11/botao-verde.png)](https://go.hotmart.com/Y74922706I?src=devto)

<iframe src='https://go.hotmart.com/Y74922706I?src=ctspdevto' height=0 width=0></iframe>
What are the 5 best options to monetize an open-source javascript library? [ChatGPT answer]
Tags: opensource, javascript, monetization, webdev
Published: 2022-12-10 16:50:00

According to ChatGPT the 5 best options to monetize an open-source JavaScript library are:

1. **Offer paid support or consulting services**: Many organizations are willing to pay for expert support and guidance when using an open-source JavaScript library. By offering paid support or consulting services, maintainers can generate revenue while also providing valuable assistance to users.

2. **Develop and sell a proprietary version**: Maintainers can create a proprietary version of their open-source JavaScript library, with additional features and support, and sell it to interested organizations. This can be a good way to generate revenue while still offering the open-source version for free.

3. **Use a dual-licensing model**: In this model, maintainers offer the open-source JavaScript library under a permissive license, but also offer a commercial license for a fee. This allows organizations to use the library for free if they comply with the terms of the open-source license, but they must pay for the commercial license if they want to use the library without complying with those terms.

4. **Seek funding from organizations**: Maintainers can seek funding from organizations that are interested in supporting the development and maintenance of the open-source JavaScript library. This can include companies that use the library, as well as foundations and other organizations that support open-source projects.

5. **Accept donations**: Maintainers can also accept donations from individuals and organizations who want to support the project. This can be done through a platform like GitHub or through a personal website.

Overall, the best option for monetizing an open-source JavaScript library will depend on the specific project and the needs and goals of the maintainers.
Day-20 of Machine Learning
Published: 2022-12-10 16:42:14

Day-20 of Machine Learning:
- Learnt about **cross-validation**:

Cross-validation is a technique for evaluating a machine learning model and testing its performance.
Cross validation refers to an extra data set that used to cross check the validity or the accuracy of the model.
for example, let a ML model trained over the training-set and the accuracy is 98%. Wow!!! But still we can't say that the model has trained very well, and it is because it is performing well over the data that it already knows and if we expose the model to completely new, unseen data, it might not predict with the same accuracy and it might fail to generalize over the new data. it is the case of **overfitting** or **High variance**. Similarly, if the model does not perform well on training-set as well as cross-validation set, then it is **Underfitting / High bias**.

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

Using Training-set we fit the parameters [W,b] then choose parameter d (degree of polynomial) using cross-validation set. So, we have not used test-set till now to fit either of any parameters, that is why  Jtest will be a fire estimate of the **generalization** error of the model
wordpress
Published: 2022-12-10 16:41:40

Dạ em chào mn, em mới thử sức với WordPress gần đây theo yêu cầu của công ty thực tập. Em muốn hỏi là em đang có 3 bảng sql có quan hệ như hình,
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5utxnaow4v1o2avfqq6p.jpg) em phải làm thế nào để đưa dữ liệu của 3 bảng đó vào bảng wp_posts của WordPress ạ?
The CSS `accent-color` property explained
Tags: webdev, beginners, css
Published: 2022-12-10 16:24:11

In CSS, the `accent-color` property allows you to set the custom color for several UI elements (or more specifically user-interface controls), such as scrollbars, input elements, and range sliders. See the [demo](#demo) here.

## Table of contents

- [How to Use it](#how-to-use-it)
- [Accessibility](#accessibility)
- [Demo](#demo)
- [Browser Support](#browser-support)
- [Conclusion](#conclusion)
- [Resources](#resources)

---

## How to use it

You can either apply `accent-color` to the root of your HTML or a specific element.

```css
/* general */
:root {
  accent-color: red;
}

/* specific */
.custom {
  accent-color: #12345A;
}
```

The `accent-color` currently applies to the following elements:

- `<input type="checkbox">`
- `<input type="radio">`
- `<input type="range">`
- `<progress>`

---

## Accessibility

By default, the user agent always ensures contrast accessibility under the hood. However, once you set a custom color, the browser doesn't change the color based on the theme or other factors.

If you want to use a custom color for inputs and sliders to match the design, you need to make sure that color contrast is high. To achieve this, we can the `prefers-color-scheme` query to colors depending on a user's theme.

> The "user agent" is a fancy word for a browser

```css
/* for light or default theme */
:root {
  accent-color: #005451; /* dark green */
}

/* for dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    accent-color: #00ece3; /* light green */
  }
}
```

---

## Demo

You can play with the demo below to see how the `accent-color` property works.

{% codepen https://codepen.io/dostonnabotov/pen/poKqrEQ %}

---

## Browser Support

[![Browser support chart for accent color property](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjxmldealdpkb0n5tkqv.png)](https://caniuse.com/mdn-css_properties_accent-color)

The `accent-color` is well-supported across browsers. As of June 15, 2022, support for Internet Explorer has officially ended.

---

## Conclusion

It's always been a pain to style the form elements. While often being underused, the `accent-color` property is a great way of tweaking the form UI elements without having to write a lot of CSS or rely on JavaScript. 

I hope this article has helped you get a better understanding of the `accent-color` property. If you have any questions or suggestions, feel free to leave a comment below. Thanks for reading!

---

## Resources

- [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/accent-color)
- [CSS-Tricks](https://css-tricks.com/almanac/properties/a/accent-color/)
- [Web Dev](https://web.dev/accent-color/)
- [W3Schools](https://www.w3schools.com/cssref/css4_pr_accent-color.php)
Solving day 10 of Advent of Code 2022 in JavaScript
Tags: challenge, adventofcode, javascript, video
Published: 2022-12-10 16:18:34

---
title: Solving day 10 of Advent of Code 2022 in JavaScript
published: true
description: JavaScript walkthrough of Advent of Code 2022 (day 10)
tags: challenge, AdventOfCode, javascript, video
series: Advent of Code 2022 in Javascript
---

{% youtube o4_sn65mwho %}
Node.js: different ways of fetching data
Tags: webdev, javascript, programming, node
Published: 2022-12-10 16:11:06

My latest [article](https://bogdancotoara.substack.com/p/nodejs-different-ways-of-fetching) is out, comparing some of the most used ways of fetching data in order to see which is the fastest. Consider subscribing to my newsletter if you found the information helpful.
For the ones who is starting out
Tags: javascript, beginners
Published: 2022-12-10 16:10:51

I have been doing the The Odin Project for the past 1 month and it has been AMAZING. Currently I am on the React part of JavaScript Section. I had already done some HTML, CSS and JS before so it was not that hard for me to go through the Foundations part. I am really loving this field and day by day I am learning more. And I am writing this to inspire someone who is starting out their journey. Whoever you are you can do it. Just believe in yourself. There will be times where you would want to give up but just keep pushing and you will reach somewhere. I also feel like giving up someday but I guess it's just a feeling. Be disciplined and have patience. Happy Coding!
Spotify on the command line
Published: 2022-12-10 16:06:12

You can use Spotify on the command line using the `spotify-cli` application. It is a command-line application that allows you to control Spotify on your computer using commands in the terminal. You can use it to play songs, list your playlists, and much more.

To use `spotify-cli`, you first need to install it on your computer. This can usually be done using your operating system's package manager. For example, if you are using Ubuntu, you can install it using the following command:

``sudo apt-get install spotify-cli``


Once installed, you can use `spotify-cli` by typing `spotify` followed by the desired command in your terminal. Here are some examples of commands that you can use:

- `spotify play`: plays the currently selected song
- `spotify pause`: pauses the currently playing song
- `spotify next`: skips to the next song in the playback queue
- `spotify prev`: goes back to the previous song in the playback queue
- `spotify list`: lists the available playlists in your Spotify account

To get a complete list of available commands, you can use the `spotify --help` command. This will display all available commands and how to use them.

<br />

[![Texto alternativo da imagem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ds4alkts3uxq0dsco0nv.png))](https://www.linkedin.com/in/israel-lopes-419a32189)
Choose the Rust language!
Tags: rust, beginners, programming, tutorial
Published: 2022-12-05 07:49:23

Are you looking for a new and interesting programming language to learn? Consider Rust! Rust is a statically typed, multi-paradigm language that was designed to be safe, concurrent, and fast. It has gained popularity in recent years for its strong emphasis on safety and performance, and is used in a variety of applications, from web services to systems programming.

One of the key features of Rust is its ownership and borrowing system, which ensures that memory is managed safely and efficiently. In Rust, every value has a single owner, and the ownership of a value can be transferred from one variable to another. This eliminates the need for manual memory management and prevents common bugs such as null or dangling pointer errors.

Rust also has a powerful macro system that allows for code generation at compile time. This enables the creation of domain-specific languages (DSLs) and other abstractions that can make code more concise and expressive.

Another key advantage of Rust is its concurrency support. Rust provides low-level control over threads and offers a number of concurrency primitives, such as atomic reference counting, that make it easy to write concurrent code that is both safe and efficient.

Overall, Rust is a powerful and versatile language that offers a compelling combination of safety, performance, and expressiveness. If you're looking for a new language to learn that will challenge and intrigue you, consider giving Rust a try!
What was your win this week?
Tags: discuss, weeklyretro
Published: 2022-12-10 15:33:01

Hey everybody! 👋

Hope y'all all are having a nice weekend!

Looking back on this past week, what was something you were proud of accomplishing?

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Fixing a tricky bug
- Seeing a movie in theaters 🍿

---

![minion dancing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4kz8bpikj0tj6wq4hvbv.gif)
Mastering Python Standard Library: itertools.chain
Tags: python, beginners, performance, programming
Published: 2022-12-10 15:30:00

Imagine, you need to iterate over some N iterables.

For example, you have two lists: l1 and l2.
```
In [2]: l1 = list(range(5))
In [3]: l2 = list(range(10))

In [4]: l1
Out[4]: [0, 1, 2, 3, 4]

In [5]: l2
Out[5]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```

Here is the easiest way to do so:
```
for i in l1+l2: print(i, end=", ")
# 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
```

However, it may not be the best one. `l1+l2` statement is a list concatenation, and that give you a *new list* with `len(l1+l2) == len(l1) + len(l2)`. If you positive that both lists are rather small, then it's kinda okay. 

But, let us assume they are each of 1GB in RAM. At peak, your program will consume 4GB, twice the size of input lists. And what if you don't have much RAM? - maybe your code is in AWS Lambda, etc.

Actually, we want to do something like this:
```
def gen(l1, l2):
    yield from l1
    yield from l2

for i in gen(l1,l2): print(i, end=", ")
# 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
```
No new lists, no copies, no memory overhead. Just iterate over the first list and then iterate over the second one. 

And that `gen` iterator is already coded for you, and also known as `itertools.chain`

```
import itertools

for i in itertools.chain(l1,l2): print(i, end=", ")
# 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
```

By the way, there is another form of `itertools.chain`, `itertools.chain.from_iterable`. It does absolutely the same, except input arguments unpacking:
```
for i in itertools.chain.from_iterable([l1, l2]): print(i, end=", ")
# 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
```

So, in general:
```
# this is itertools.chain
def my_chain(*collections):
    for collection in collections:
        yield from collection

# this is itertools.chain.from_iterable
def my_chain_from_iterable(collections):
    for collection in collections:
        yield from collection
```

Why there are 2 chains, with one tiny "\*" difference? I really don't know - but who am I to judge authors of itertools module, *they are true gods*.

But I do know, that ["entities should not be multiplied beyond necessity"](https://en.wikipedia.org/wiki/Occam%27s_razor). And this thought brings us back to our unnecessary extra list creation issue.

## So what’s the point?

Well, use chain! Learn `itertools` module. Think about performance. *Save the memory*, in production environment it is actually limited and [not really cheap](https://cloud.google.com/functions/pricing#compute_time)! 

### Anything else to read?

Sure.

[Whole lotta docs](https://docs.python.org/3/library/index.html) - Master the power of standard library!

[Itertools module docs](https://docs.python.org/3/library/itertools.html) - chain is not the only one, there are plenty more

[Occam's Razor](https://en.wikipedia.org/wiki/Occam%27s_razor) - really, read it