teleren/devto huggingface dataset:
How to decide the number of threads based on CPU bound/ IO bound
Tags: backend, programming, beginners
Published: 2023-03-04 23:04:25

#**How to decide the number of threads based on CPU bound/ IO bound**


###**Review/Preview words**

**CPU(Central Processing Unit)** is the device that interprets and executes the commands of a process.

**IO(Input/Output)** involves reading and writing files, sending and receiving data with a network, and interacting with input/output devices.

**Burst** is a phenomenon that occurs intensively within a short time.

**CPU burst** refers to the time a process is continuously executed on the CPU.

**IO burst** refers to the time a process waits for an IO operation to complete after requesting it.

The life of a process is a continuous sequence of CPU and IO bursts.

###**The frequency of CPU bursts depends on their length.**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv8l05kw12v8ck1urv3p.png)

**CPU bound process**
A process that has many CPU bursts.
ex) video editing software, machine learning programs

**IO bound process**
A process that has many IO bursts.
ex) typical backend API servers

##**If implementing a CPU bound program to run on a dual-core CPU, how many threads should be used?**
&rarr; The number of threads = The number of CPUs + 1
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4rgm52h563cwbiuilc0.png)

In actual execution:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khkmcmpxonrue2n8wmxa.png)
&rarr; Context switching(CS) is overhead, tasks that use the CPU.
In this picture, unnecessary context-switching occurs, the CPU usage increases. 

Dual-core & 2 threads:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xa5nfbj922ickb7fn2l4.png)
Since there is no context switching, CPU usage is not wasted, and the appropriate number of threads is one more than the number of CPU cores.



##**If implementing an IO bound program to run on a dual-core CPU, how many threads should be used?**
&rarr; It depends on the situation.


* If the API server is a thread-per-request model?
&rarr; The number of threads to be created in advance should be determined by considering various situations.



**This posting is just a study note which was written after watching youtube videos in Korean.**
[Youtube link](https://youtu.be/qnVKEwjG_gM)
I'm a professional pleaser, and developer.
Tags: webdev, productivity, programming, career
Published: 2023-03-04 22:55:54

###I have always been a people pleaser. It can be both positive and negative. As a professional developer, this can present some challenges. I think I have found a solution.###

Two of my strongest traits are a well-developed pleaser gene combined with a strong tendency to want to avoid conflict. This has made it difficult to say no and often resulted in what I was trying to avoid - conflicts.

###Turning professional developer.###

When I started as a professional developer three years ago, I soon discovered a new disadvantage to my pleaser trait. I was more or less subconciously underestimating my tasks, just to please my project managers. This meant that i was constantly low on time and had to ask for more - which then made me unpopular with the project managers.

###My solution###

My solution is to use an estimation tool. It sounds fancy but it is actually just a spreadsheet where i can choose my level of confidence and then the spredsheet will multiply my estimates by a factor.

It removed the estimation process from my head and made it more realistic and pessimistic.

If you find it hard to estimate tasks and find yourself constantly low on time - maybe this could help you too.
Final project review
Published: 2023-03-04 22:25:30

Tips:
- indirect associations, instead of `belongs_to` is `has_one`
- migrations after scaffold need to be updated manually

Links:
- [3.3.2 Creating Join Tables for has_and_belongs_to_many Associations](https://guides.rubyonrails.org/association_basics.html#creating-join-tables-for-has-and-belongs-to-many-associations)
CodePen.io
Tags: beginners
Published: 2023-03-04 22:12:35

CodePen.io is a popular online code editor and front-end development community where developers can experiment with different code snippets, prototypes, and projects in a sandbox environment. It is widely used by developers of all skill levels, from beginners to experienced professionals, for a variety of reasons.

One of the primary benefits of using CodePen.io is the ability to easily experiment with code. Developers can quickly write and test different code snippets and see the results in real-time. This allows them to try out new ideas and techniques without having to set up a local development environment, which can be time-consuming and complex.

Another benefit of CodePen.io is the ability to share and collaborate on code. Developers can share their code snippets and projects with others in the community, and receive feedback and suggestions on how to improve their work. This can help them learn new techniques and best practices, and also build their professional networks.

CodePen.io also offers a number of features that make it easy for developers to showcase their work. They can create custom portfolios and profiles, which they can use to highlight their skills and experience. They can also embed their CodePen projects on their personal websites or social media profiles, which can help them build their personal brand and attract potential clients or employers.

One of the most popular features of CodePen.io is the ability to participate in coding challenges and contests. These challenges can range from simple coding exercises to more complex projects, and often have specific themes or requirements. Participating in these challenges can be a fun and rewarding way for developers to hone their skills and showcase their creativity.

Another benefit of CodePen.io is its active and supportive community. Developers can connect with others who share their interests and passions, and participate in discussions and forums. This can help them build their professional networks, learn new skills, and stay up-to-date with the latest trends and technologies in the industry.

In conclusion, CodePen.io is a valuable tool for developers of all skill levels. Its sandbox environment, collaboration features, and community-driven approach make it a popular choice for developers who are looking to experiment with new ideas, showcase their work, and connect with others in the industry.
สล็อตออนไลน์ระบบอัตโนมัติ แตกง่าย แจ็คพอตแตกบ่อยที่สุดในไทย
Published: 2023-03-04 22:07:51

มีเครื่องสล็อตแมชชีนรูปแบบเฉพาะสำหรับเสียงหัวเราะซึ่งอาจวางไว้ในคาสิโนซึ่งบางครั้งสามารถสลับการดำรงอยู่ของคุณได้ มันขึ้นอยู่กับคุณและรูปแบบการพนันของคุณว่าคุณจะชนะได้กี่ตัน และยิ่งไปกว่านั้นความสำเร็จของคุณยังบ่งบอกว่าเงินจำนวนมหาศาลมีให้คุณมากน้อยเพียงใด หากคุณถูกรางวัลแจ็คพอต มันก็เหมือนกับว่าคุณจะได้รับเสียงหัวเราะคุณภาพสูงจากสิ่งนั้น ตอนนี้สล็อตแมชชีนเหล่านั้นมีให้บริการบนอินเทอร์เน็ตและคุณสามารถเล่นเอฟเฟกต์เหล่านั้นได้ในเวลาเดียวกันเหมือนนั่งอยู่ในบ้านส่วนตัวของคุณได้อย่างง่ายดาย หากคุณกำลังนั่งอยู่ในบ้านส่วนตัวของคุณ ก็ไม่ได้หมายความว่าคุณไม่สามารถสนุกสนานกับความหมายที่แท้จริงของเกมได้ แม้ว่าคุณจะสนุกสนานไปกับมันผ่านเน็ตบนเครื่องสล็อตเพื่อความสนุกก็ตาม มีการแข่งขันสล็อตออนไลน์นับไม่ถ้วนที่จัดขึ้นหลังจากช่วงระยะเวลาหนึ่งซึ่งผู้เล่นบางคนสามารถมีส่วนร่วมและอาจเสี่ยงที่จะได้ชัยชนะ ในทัวร์นาเมนต์สล็อตออนไลน์เหล่านั้น คุณสามารถรับรางวัลและโบนัสที่ยอดเยี่ยมซึ่งคุณไม่สามารถชนะได้จากวิดีโอเกมทั่วไปและวิดีโอเกมสล็อตทั่วไป หากคุณชนะแจ็คพอตในทัวร์นาเมนต์เหล่านี้ มันก็เป็นประสบการณ์ชั้นหนึ่ง

[สล็อตออนไลน์ระบบอัตโนมัติ แตกง่าย แจ็คพอตแตกบ่อยที่สุดในไทย](https://okslot.com/slot-partner-auto/)

ในสหราชอาณาจักรเครื่องสล็อตได้รับการยอมรับว่าเป็นเครื่องผลไม้และเครื่องสล็อตเพื่อความบันเทิง ซึ่งคุณอาจได้รับรางวัลและโบนัสที่ไม่เหมือนใครซึ่งแต่ละระบบไม่สามารถให้คุณได้อีกต่อไป มีประชาชนทั่วไปที่เบื่อกับกีฬาที่เท่าเทียมกันและหมดความสนใจเพราะทำตามกฎและขั้นตอนที่เหมือนกันของวิดีโอเกม เพื่อรักษาผลประโยชน์ของผู้เล่นในกีฬา มีหัวข้อที่น่าสนใจมากมายในเครื่องสล็อตแมชชีนเพื่อความขบขันซึ่งอาจเปลี่ยนแปลงได้ในภายหลังและรักษาเกมให้คงที่ด้วยสิ่งนั้น

มีเว็บไซต์ที่แม่นยำพร้อมสล็อตแมชชีนเพื่อความสนุกสนานซึ่งจัดทัวร์นาเมนต์เว็บสล็อตและแรงจูงใจที่อยู่เบื้องหลังสิ่งนี้ นักเล่นเกมที่ยอดเยี่ยมที่มีความสนใจเท่ากันสามารถมีปฏิสัมพันธ์ซึ่งกันและกันและยังสามารถเล่นเกมที่สูงขึ้นได้ ระดับ. คาสิโนเหล่านี้มีกีฬาในลักษณะใดลักษณะหนึ่งที่พวกเขาเลือกจากสล็อตจำนวนหนึ่งและการเลือกช่วงกว้างนั้นทำได้ตามหัวข้อที่เลือกผ่านความหลากหลายและนอกเหนือจากความหลากหลายของวงล้อ เนื่องจากมีวงล้อสองรูปแบบคือสามรีลสล็อตและที่แตกต่างกันคือสล็อตห้ารีล

การแข่งขันสล็อตออนไลน์

ช่วงเวลาของกีฬานั้นในความเป็นจริงจะตัดสินโดยการใช้งานคาสิโนออนไลน์ หลังจากนั้นการแข่งขันสล็อตบนเว็บจะเริ่มต้นและหยุดตามนั้น คำนี้อาจมีความหลากหลายในผลลัพธ์สุดท้าย ขึ้นอยู่กับรูปแบบของการแข่งขันสล็อตทางอินเทอร์เน็ต เนื่องจากมีทัวร์นาเมนต์ใหญ่บางรายการที่คงไว้เป็นสัปดาห์ที่ไม่ซ้ำกัน และยังมีมินิทัวร์นาเมนต์ซึ่งคงไว้ไม่กี่ชั่วโมง หากคุณสนใจที่จะเล่นสล็อตแมชชีนเพื่อความสนุกและคุณต้องมีส่วนร่วมในการแข่งขันสล็อตออนไลน์ คุณสามารถเลือกรูปแบบของการแข่งขันสล็อตออนไลน์ตามงานอดิเรกของคุณ
LaTeX Book
Tags: latex, tex, beginners, opensource
Published: 2023-03-04 22:04:48

LaTeX can be a challenging system to learn, but with this book of different examples, it becomes interesting and easier than ever. This comprehensive guide covers a lot of essentials and is written in a clear and concise style, showing the result vs code. Plus, it's #opensource and freely available, creating a collaborative learning environment.

In [this book](https://github.com/AnMnv/eBook) the author tries to reveal how you can find necessary pieces of TeX code looking only at already done work.

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

Yes, of course, you can try to Google your task and find familiar results, but sometimes it’s harder than you think, especially if you are a beginner. However, using the book, even if you look at it briefly once, you will be able to find a needed solution next time easily because every example is very noticeable. Like this:

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

Isn't it cool to add different coffee stains in your document for fun? These and others examples you can easily find on Github page:

[LaTeX book in examples](https://github.com/AnMnv/eBook)

This is one of many interesting projects that is just starting to grow, and the author tries to add something interesting and new every week.

If you want to create high-quality documents with LaTeX, check out the LaTaX book on GitHub, and feel free to ask any questions you have.
3 Simple ideas for a better ReactJS
Tags: react, webdev, frame
Published: 2023-03-04 21:52:14


React has certainly made a notable stride on the quality of our DX. Features like hooks were major breakthroughs on how we develop client side applications. It is important to note however, that even though React has matured a lot, there is still plenty of room for innovation and improvement. We're currently heading towards a merge between the client and server, which is going to be a costly shift in the things we are going to have to deal with and care about. I hope that these long term plans work out, but while we watch this progression, I have a few ideas that could impact React on the short term. 

#### 1. Bring something like a platform-agnostic Zustand     
Zustand is a simple state management library capable of covering most of our needs of small to medium size state complexity. It has an insignificant learning curve and solves the problems of using state anywhere much more gracefully than the current built-in alternative way of accomplishing it (context API, which isn't a state management library to begin with and needs to be tied to a parent component). Bringing something like this to the core would encourage the simplicity and easiness that Zustand tackles state managemente.

#### 2. Release the docs as it is, improvements can come later.     
It is been several years since the docs are outdated. Still using hooks. The perfectionism here completely outweighed the benefits of just releasing what is already good. It should be released a while ago, even if we don't have a proper landing page.

#### 3. Make the React DevTools relevant again.     
I don't know if is either because a core contributor isn't there anymore or the roadmap was completed, but this project is pretty much stale.
As we're moving towards SSR, would be useful to have some new features there to help us debug server related problems, for example:
- Possibility to go back between renders to check the differences between server and client (to better identify hydration mismatches)
- Visualize suspense data
- Check for waterfall requests
- See which components are RSC and which are client, etc


Implementing these short term ideas could have a significant impact on the React community and make our development experience even better.
JavaScript Tutorial Series: Manipulating elements part 1
Published: 2023-03-04 21:33:47

In this post we're going to learn how to create elements, add a node to the list of children of the parent node get and set the content of nodes and elements

## createElement
Using the `document.createElement()` allows you to create an HTML element. This method accepts an HTML tag name into the as argument and then returns a new Node of the Element type.

```JavaScript
const h1 = document.createElement('h1');

console.log(h1);
```

![create element method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8qe0aff0pss0fzngpci.png)
In the example above, we created an `<h1>` element which is not visible yet on the screen.

## innerHTML
You can obtain or modify the HTML markup that is present in an element by using its `innerHTML` property.

```JavaScript
const h1 = document.createElement('h1');
h1.innerHTML = "Title";
console.log(h1);
```
![Inner HTML method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emy26pw6dkk80w944cc9.png)

```HTML
<h2 id="heading">This is an h2</h2>
```

```JavaScript
const h2 = document.getElementById('heading');
console.log(h2.innerHTML);
```

![inner HTML method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3837b2bhux17q4rodr6v.png)

## textContent
Using the `textContent` property will allow you to obtain a node's and its descendants' text content.

```HTML
<ul id="menu">
  <li>Lorem, ipsum.</li>
  <li>Lorem, ipsum dolor.</li>
  <li>Lorem, ipsum.</li>
</ul>
```

```JavaScript
const menu = document.getElementById('menu');

console.log(menu.textContent);
```
You can also set the text content of a node, meaning if we take our JavaScript code and modify it like so: 

```JavaSCript
const menu = document.getElementById('menu');
menu.textContent ='This is an example';
console.log(menu.textContent);
```
the output  will change from: 


![text Content method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im2a1b1mjngckwk46asc.png)

to: 

![TextContent method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/132mdyp20kv1vdtne6p7.png)

## appendChild
By using the appendChild() method, you can add a node to the end of a parent node's list of children.

```HTML
<ul id="menu">
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ul>
```

```JavaScript
const menu = document.getElementById("menu");

const li = document.createElement("li");

li.innerHTML ="Last Item";

menu.appendChild(li);
```
Before appending:

![append child](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzf37p8yljdtuufwd3cx.png)

After appending the list item

![appendChild method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ecfv83j0oldso79iqh7k.png)
Performing array maths operations with .map() and .filter()
Published: 2023-03-04 21:24:22

```
const numbers = [1, 2, 3, 4, 5, 6];

const doubledNumbers = numbers.reduce((acc, num) => {
  acc.push(num * 2);
  return acc;
}, []);
console.log('doubled numbers', doubledNumbers);
console.log('numbers', numbers);
```
You can use .reduce()

```
const numbers = [1, 2, 3, 4, 5, 6];

const doubledNumbers = numbers.map(num => num * 2);
console.log('doubled numbers', doubledNumbers);
console.log('numbers', numbers);
```
Or you can use a newer and easier method .map()

```
const numbers = [1, 2, 3, 4, 5, 6];

const greaterNumbers = numbers.filter(num => num > 3);
console.log(greaterNumbers);
```
Use .filter() if you're dealing with operations that deal with boolean. For example >, =, ?, etc...
Using If statements with .reduce()
Published: 2023-03-04 21:13:07

```javascript
const cars = [
  { name: "Toyota", isElectric: false, weight: 1320 },
  { name: "Ford", isElectric: false, weight: 1400 },
  { name: "Volkswagen", isElectric: false, weight: 1370 },
  { name: "Honda", isElectric: false, weight: 1375 },
  { name: "Tesla", isElectric: true, weight: 1750 },
  { name: "BMW", isElectric: true, weight: 1350 },  
];


const totalWeight = cars.reduce((accumulator, car) => {
    if (car.isElectric) {
        return accumulator + car.weight;
    } else {
        return accumulator;
    }
}, 0)

console.log(totalWeight);
```

 or following FP principles:

```javascript
const cars = [
  { name: "Toyota", isElectric: false, weight: 1320 },
  { name: "Ford", isElectric: false, weight: 1400 },
  { name: "Volkswagen", isElectric: false, weight: 1370 },
  { name: "Honda", isElectric: false, weight: 1375 },
  { name: "Tesla", isElectric: true, weight: 1750 },
  { name: "BMW", isElectric: true, weight: 1350 },  
];


const totalWeight = cars.filter(car => car.isElectric).reduce((accumulator, car) => {
        return accumulator + car.weight;
}, 0)

console.log(totalWeight);
```
Welcome to Dev.to
Tags: beginners
Published: 2023-03-04 21:09:41

Dev.to is a community-driven platform for developers that allows them to share knowledge, connect with peers, and build their professional networks. It was founded in 2016 by Ben Halpern, Jess Lee, and Peter Frank, with the goal of creating a platform where developers could come together to learn, share, and connect with each other.

One of the unique features of dev.to is its emphasis on community-driven content. Unlike other platforms that rely on algorithms to surface content, dev.to relies on its users to create and curate content. This creates a more personalized experience for users, as they can find content that is relevant to their interests and needs.

Dev.to covers a wide range of topics related to software development, including programming languages, frameworks, tools, and best practices. Users can publish articles, tutorials, and code snippets on the platform, and other users can provide feedback and engage in discussions in the comments section.

One of the benefits of using dev.to is the sense of community that it fosters. Developers from all over the world come together on the platform to share their knowledge and experiences. This creates a supportive environment where developers can learn from each other and collaborate on projects.

In addition to its content-driven approach, dev.to also has a number of features that make it easy for developers to connect with each other. For example, users can follow each other, and receive notifications when new content is published by their favorite authors. They can also join communities based on their interests, which allows them to connect with like-minded developers.

Another unique feature of dev.to is its commitment to inclusivity and diversity. The platform actively encourages and supports underrepresented groups in tech, such as women, people of color, and members of the LGBTQ+ community. This is reflected in the content that is published on the platform, as well as in the community guidelines.

Overall, dev.to is a valuable resource for developers who are looking to learn, grow, and connect with others in their field. Its community-driven approach, wide range of topics, and emphasis on inclusivity make it a unique and valuable platform in the tech industry.

Hope to see you around!
🚀Learning Object Destructuring in JavaScript
Tags: webdev, javascript, programming, destructuring
Published: 2023-03-04 21:09:31

**Object destructuring** is a feature in JavaScript that allows you to **extract values from objects** and assign them to variables in a more concise and readable way. 

This feature was introduced in [ES6](http://es6-features.org/) and has since become a popular technique among JavaScript developers.

In order to use object destructuring, you can use curly braces `{}` to specify the properties you want to extract from an object. Let's take a look at some examples of how this incredible feature can be used:

**1. The basic Object Destructuring**

```javascript
const person = { name: 'John', age: 30 };
const { name, age } = person;
console.log(name); // Output: John
console.log(age); // Output: 30
```

Here we declare a `person` object with `name` and `age` properties. We then use destructuring to extract these properties and assign them to variables with the same names. We can then use them to access the values of the properties.

**2. Renaming variables**
```javascript
const person = { name: 'John', age: 30 };
const { name: fullName, age: years } = person;
console.log(fullName); // Output: John
console.log(years); // Output: 30
```

Here we use destructuring to extract the `name` and `age` properties from the `person` object. However, we also use the colon `:` syntax to rename the variables to `fullName` and `years`. This allows us to use different variable names while still extracting the values we need.

**3. Default values**
```javascript
const person = { name: 'John' };
const { name, age = 30 } = person;
console.log(name); // Output: John
console.log(age); // Output: 30
```

Here we use destructuring to extract the `name` property from the `person` object. We also declare a default value of `30` for the `age` variable in case it is not defined in the `person` object. This ensures that our code does not throw an error if the `age` property is missing.

**4. Dynamic property names**
```javascript
const helloStr = "Hello world!"
const { length, [length-1]: last } = str
console.log(length)  // 12
console.log(last)  // "!"
```

Here we use destructuring to dynamically assing `last` as the new property name from the `helloStr` variable in order to get the last character from the string.

## Conclusion 🏁

_**Object Destructuring**_ is a powerful feature that will not only make you look cool but also will help you to write cleaner and more efficient code that will be easier to maintain and understand.


**_Happy learning and thank you for reading!_**

_If this article was helpful to you, don't forget to hit that ❤️ button and support me with a follow, i will keep posting more content about tech, programming, career development and more! :)_