teleren/devto huggingface dataset:
Java Threads
Published: 2020-12-10 03:58:29

<B>What are Java Threads? </B>Basically, Threads allows a program to operate more efficiently by doing multiple things at the same time.
To start the next task: Instead of waiting till one task ends, It will be more efficient to do multiple tasks at the same time.

<B>The life cycle of a thread:</B>
1. New
2. Runnable
3. Running
4. Non-Runnable (Blocked)
5. Terminated
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vv98o24etacn49gwx7lg.png)
<B>The life cycle of Thread in detail:</B>

1.<B>New:</B> The thread is in new state when you create an instance of Thread class.  it is in this stare before the invocation of start() method.

2.<B>Runnable:</B> The thread is in runnable state after the invocation of start() method, but the thread scheduler has not selected it to be for running.

3.<B>Running:</B>
The thread is in running state when the thread scheduler has selected it.

4.<B>None Runnable:</B> In this state the thread is alive but not in running state .

5.<B>Terminated:</B> A thread is in terminated or dead state when it's run() method exits.

<B>Creation of Threads:</B>

There are two methods for creating threads: 1. Using Thread class 

2. Using Runnable Interface

In detail:
1. <B>Using Thread class:</B>
<br>STEPS:-

i) Create a Thread class:
                            
    public class Myclass extends Thread

ii) Override run() method:  
        
    public void run();

iii) Create object of class: 
      
    MyThread obj = new MyThread();

iv)Invoke start() method:

    obj.start();

Example:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hlfn71k3eciiuv8bfx8o.JPG)



2. <B>Using Runnable Interface:</B>
STEPS:

i) Create a thread class:
    
    public class MyThread implements Runnable 

ii) Override run() method:

    public void run();
important point: We can also use '@override' to override the run()

iii) Create object of the class:
 
    Thread t = new Thread(new MyThread());
Note: we use new twice because MyThread class does not extend Thread class
and we can also write the same thing as:

     Runnable r = new MyThread();
     Thread t = new Thread(r);

iv)Inoke start() method:
  
    t.start();

Note: We use runnable interface because if a class is already a child of its parent class it cannot extend Thread class and hence it can implement Runnable Interface.

<B>Example:</B>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/d5tjq3tpof1gvi7y4fhf.JPG)



<B>Similarities between Thread class and Runnable Interface:</B>
1. Both create a unique object of the class
2. Both consumes more memory
3. Both have to override the run() method
Advent of code - Day 9
Tags: javascript, typescript, adventofcode
Published: 2020-12-10 07:18:10

Are you participating in the [Advent of code](http://adventofcode.com) this year?

If you don't know what the advent of code is, it's a website where you'll find a daily challenge (every day it gets harder). It's a really fun event, you should participate!

I try to solve the exercises using either JavaScript or TypeScript and will share my solutions daily (with one day delay so no one can cheat!). I only share the solution for the second part.

Day 9 felt surprisingly not as scary as day 8. Maybe I'm just getting better?
Here is my solution for day #9:
```js
function resolve(code, offset) {
  for (let i = offset; i < code.length; i++) {
    const currentNumber = code[i];
    const possibleNumbers = code.slice(i - offset, i);
    const ok = possibleNumbers.some((firstNumber) =>
      possibleNumbers.some(
        (secondNumber) =>
          firstNumber + secondNumber === currentNumber &&
          firstNumber !== secondNumber
      )
    );
    if (!ok) return currentNumber;
  }
}

function findMinMax(code, offset) {
  const invalidNumber = resolve(code, offset);
  for (let i = 0; i < code.length; i++) {
    let total = 0;
    for (let j = i; j < code.length; j++) {
      // Since the input is sorted, we just need to traverse
      // and make the sum until we find one that matches
      total += code[j];
      if (total < invalidNumber) continue;
      if (total > invalidNumber) break;
      const range = code.slice(i, j + 1);
      return Math.min(...range) + Math.max(...range);
    }
  }
}

findMinMax(input)
```

Feel free to share your solution in the comments!

________________________

Photo by [Markus Spiske](https://unsplash.com/@markusspiske?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText)
Everyone, support this dude's game!
Tags: gamedev, watercooler, showdev
Published: 2020-12-10 06:55:48

 Maybe the help tag isn't used exactly as it specifies, but, staff, don't remove it, it's there to signal we need to help support this dev.
<br/>
So, recently, I came across [this post](https://www.reddit.com/r/proceduralgeneration/comments/k7d544/mountain_pillars_biome_type/) on [r/proceduralgeneration](https://www.reddit.com/r/proceduralgeneration/), and I thought it looked cool.

I downloaded the demo of this game ([SeptSide](https://koboldskeep.itch.io/septside)), and I was not disappointed. It is a legit <b>GOOD</b> Minecraft clone.
It's not like the kind of knock-off or bootleg game you'd expect, but unlike MC, it has a neat twist, you can define your own terrain generation.

Sure, while that's not a big deal, and Minecraft mods can probably already do this, I think it saves a hassle, and is a great sentiment and novelty to have. They also want to make an RTS game (if or if not this project dies, eitherway). Either way, I support them as a dev, and I think they're really cool (because they can actually get graphics to work.... hmmph), and you should support them, too.

Here's their socials\:
[Twitter](https://twitter.com/koboldskeep) \| [Reddit](https://www.reddit.com/user/thomar/) \| [ItchIO](https://koboldskeep.itch.io/)
<br/>
Please share this post with your friends.
Thanks!
Introduction to Storybook JS
Tags: angular, javascript, react, vue
Published: 2020-12-10 06:40:56

I have recently come across a cool UI tool i.e ***Storybook***. 
Storybook is really efficient and helps in faster UI development.

Before jumping on anything lets get clear on

***What is a storybook?***
>Storybook is an open-source tool for developing UI components in isolation for React, Vue, Angular, and more. It makes building stunning UIs organized and efficient.
You can develop entire UIs without needing to start up a complex dev stack, force certain data into your database, or navigate around your application

![Alt text]
(https://res.cloudinary.com/practicaldev/image/fetch/s--0REcx4xZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h0tkhbillluy2661maka.png)

With Storybook, you create stories for your components. Each story shows the behavior for a single component with specific states set.

Storybook helps you document components for reuse and automatically visually test your components to prevent bugs. Extend Storybook with an ecosystem of addons that help you do things like fine-tune responsive layouts or verify accessibility.

Storybook integrates with the most popular JavaScript UI frameworks and (experimentally) supports server-rendered component frameworks such as Ruby on Rails.



***Learning***

If you want to build a simple application in your framework with the storybook, [LearnStorybook](https://www.learnstorybook.com/)  will help you!

*Few more resources*
[Implementation with Angular](https://medium.com/javascript-in-plain-english/storybook-for-angular-components-with-markdown-support-72950cc3d9ee)
[Implementation with React](https://www.digitalocean.com/community/tutorials/how-to-build-a-ui-component-with-react-and-storybook)
[Implementation with Vue](https://labs.thisdot.co/blog/how-to-set-up-storybook-in-vuejs)
Deadlock Prevention | Operating System - M04 P04
Tags: linux, devops, beginners, tutorial
Published: 2020-12-10 06:39:30

**This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the forth module which consists of 8 articles.**

_In this article we are going to see that what are the ways by which we can prevent deadlock and various methods to handle deadlock in an operating system._

***Various methods to handle deadlock.***
1. Deadlock ignorance _(ostrich method)_
2. Deadlock prevention.
3. Deadlock avoidance _(banker’s algorithm)_
4. Deadlock detection and recovery.

**Deadlock ignorance:** 
- In this method when deadlock occur in the system then operating system just ignore the deadlock.
- This method is used because, if we add one more algorithm/ patch of code, in our operating system then the performances of the system get decreased. 
- And also that the deadlock condition occur very rarely.
- Restart the system that is deadlock ignorance.
- This is called ostrich method, because when sand storm comes ostrich put its head in ground, and think that there is no sand storm.

**Deadlock prevention:**
- This method means that we try to find a way that we do not get any deadlock scenario, before the deadlock occurs.
- It can be followed by removing the following conditions _(any one)_
    - Mutual exclusion.
    - No preemption 
    - Hold and wait
    - Circular wait

**Deadlock avoidance**
- In this method when we give resource to a process than we check that if it is safe or not to give that resource to that process.
- This is done by _Banker’s algorithm_
Deadlock detection and recovery
- In this method we try to detect that is there any deadlock present or not in the system. If the deadlock is present than we try to recover our system form it.
- We can do recovery by 
    - Kill the processes or process _(But this will decrease the performance of the system)_
    - Resource preemption from a process.

_So this was all about deadlock handling methods and deadlock prevention. Hope you liked it and learned something new from it._

If you have any doubt, question, quires related to this topic or just want to share something with me, than please feel free to contact me.

### 📱 Contact Me

[Twitter](https://twitter.com/r_mishra10)
[LinkedIn](https://www.linkedin.com/in/rahul-mishra-66210b185)
[Telegram](https://t.me/rahul_mishra10)
[Instagram](https://www.instagram.com/rahul_mishra10/?hl=en)

### 📧 Write a mail
<rahulmishra102000@gmail.com>

#### 🚀 Other links

[GitHub](https://github.com/rahulMishra05)
[HackerRank](https://www.hackerrank.com/rahulmishra10201)
Python3 Programming - Exercise 4 - Arithmetic Operators
Tags: python, programming, beginners, tutorial
Published: 2020-12-10 06:32:20

##  Arithmetic Operators

Arithmetic operators are reserved symbols used for performing mathematical operations ( calculations).

## Examples

|    operators     | symbols |   use    | return type |
| :--------------: | :-----: | :------: | :---------: |
|     Addition     |    +    |  1 + 3   |     int     |
|   Subtraction    |    -    |  3 - 1   |     int     |
|  Multiplication  |   \*    |  3 \* 2  |     int     |
|     Exponent     |  \*\*   | 3 \*\* 2 |     int     |
|  Float division  |    /    |  3 / 2   |    float    |
| Integer division |   //    |  3 // 2  |     int     |
|      Modulo      |    %    |  3 % 2   |     int     |

### Note

- If one of the operands is a float, then the resulting value is casted ( converted) into a float. `Eg: 1.0 + 1 = 2.0 and 1 + 1 = 1` .
- `//` , returns the whole number part ( quotient) of the division. So, `given: 22.0 // 3 = 7.0 and 22 // 3 = 7` .
- `/` , returns the quotient and the remainder as a float, together. `Eg: 22 /3 = 7.333333333333333 and 0.25 / 0.5 = 0.5` .

# Casting

Casting means, converting or changing from one type to another. To know the type of a value, use the `type(obj)` function. `Eg: type(2) and type('2') will return <class 'int'> and <class 'str'>` respectively. Meaning that 2 is an integer and '2' is a string.

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

## Note

The values of x and y don't change after the casting, except that we do, `y = float(y)`.

# Practicals

write a program to evaluate and print the results of the following given that `a = 2` and `b = 5` :

1.  
    - a _ (2 _ b) - 5
    - 2 \* (b - a) + b
1.  (-(a _ b) \*\* 2 - (4 _ a \* b) ) / ((b // a) // 3 + (16 / a / b))
1.  ((a ** 2) - (b ** 2)) // ((b - a) \*\* 2)
1.  ((a + b) % 2) - ((b % a) + 1)

# Summary

- `+, -, *, **, /, //, %` are reserved for mathematical operations.
- Rule of precedence is `(), **, *, //, /, +, -` .
- Use parentheses to change the precedence.
Release 4.0 Final
Published: 2020-12-10 06:30:40

Finally, I am done with my final pull request which you can find [here](https://github.com/FreeTubeApp/FreeTube/pull/852).

This was a very hard bug to work with as I've never worked with an electron app before and I've also never worked with vue before. But it was pretty educational, and it gave me that good feeling I was looking for after fixing it.

Starting off from my last blog, I was correct in my finding that the code was never actually running because of the if statement, doing some more research throughout the code I actually found that the value that they were checking "this.descriptionHtml" was actually always going to be null because it was never set to anything in the first place. Once I fixed that I could use console.logs to test if I was getting into the function or not (Good ole trusty print statements). It found that weirdly enough I was getting into the function but nothing in the description was changing. This was because I needed to add another line that changed the static text of the description to include all the proper linkers and tags in it, like if there is a link add a <a> tag around it and make a href for it. 

Luckily that was fairly easy as there was a package that they used to do so, now comes the more difficult part, figuring out why exactly the program wasn't actually changing the description href. Well the short answer was that the old regex from a past contributor actually was wrong, and I guess he never knew that it was wrong because he could never test it properly because the function would never run properly.

After fixing the regex (which took me a while to find the proper regex for it) and replacing it with the proper link I finished the bug.

This bug took me probably the longest so far in the class totalling at around 3-4 hours. But let me tell you, the hardest, longest, and most confusing bugs are always the ones that feel the best once you fix them.

In addition this was actually the first bug that I fixed throughout OSD600 so it was cool working on someone else's broken code and trying to fix it up.


Well that's all for me this semester, I had a incredible time working with all of you and I wish you the best in the new semester.

And to my teacher, thank you for teaching this course. I really liked every aspect of this course (especially Hacktoberfest) and you really were supportive to students that needed the help. I'm looking forward to working with you in OSD700 next semester!

Now all I have to do is just wait for my pull requests to be merged.
Advent of Code 2020 Solution Megathread - Day 10: Adapter Array
Tags: adventofcode, challenge
Published: 2020-12-10 06:26:30

---
title: Advent of Code 2020 Solution Megathread - Day 10: Adapter Array
published: true
description: Now we're playing with electrical plugs.  Hope we don't get *jolted!*
tags: adventofcode, challenge
series: Advent of Code 2020
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/hj7p3m6783e9ky0evs7q.png
---

We're now 40% of the way done.  Almost halfway!  You can make it!  You can do it!  I believe in you!  Even if you fell off the sleigh, as they say, you can still get back in and go back for the ones you missed later.  You got this!

## The Puzzle

In [today’s puzzle](https://adventofcode.com/2020/day/10), the device that we so cleverly hooked into yesterday has run out of battery.  We want to plug it in, but, because we're on vacation and we want to spice things up a bit, we want to use every single one of the adapters in our bag to get there.  Complicated prompt, but sounds like a fun challenge!

## The Leaderboards

As always, this is the spot where I’ll plug any leaderboard codes shared from the community.

```
Ryan's Leaderboard: 224198-25048a19
```

If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.

## Yesterday’s Languages

Updated 03:09PM 12/12/2020 PST.

| Language   | Count |
|------------|-------|
| JavaScript |     4 |
| Rust       |     3 |
| C#         |     1 |
| Ruby       |     1 |
| Haskell    |     1 |
| C          |     1 |

Merry Coding!
Advent of Code 2020: Python Solution Day 10
Tags: adventofcode, algorithms, python, challenge
Published: 2020-12-10 06:10:51

I nearly forgot about doing the challenge. Part one was easy and part two was bit tricky so I did wrong at first and got help from this [repo](https://github.com/elvinyhlee/advent-of-code-2020-python/blob/master/day10.py). Again I tried it first on test input and only then on real one. My solution is at this [repository](https://github.com/q-viper/Adevent-Of-Code-2020).

### Part one
```python
with open("day10.txt", "r") as fp:
    lines = [int(line.rstrip()) for line in fp.readlines()]

one_jolt = 0
two_jolt = 0
three_jolt = 0 
outlet_rating = 0
lines.append(max(lines)+3) # because max jolt is added


while True:
    #print(1 in lines)
    if (outlet_rating + 1) in lines:
        one_jolt+=1
        outlet_rating += 1
    elif outlet_rating+2 in lines:
        two_jolt+=1
    elif (outlet_rating + 3) in lines:
        three_jolt += 1
        outlet_rating+=3
    else:
        break
print("Part 1 answer is ", one_jolt*three_jolt)
```

### Part two
```python
# part 2
sol = {0:1}
for line in sorted(lines):
    sol[line] = 0
    if line - 1 in sol:
        sol[line]+=sol[line-1]
    if line - 2 in sol:
        sol[line]+=sol[line-2]
    if line - 3 in sol:
        sol[line]+=sol[line-3]
        
print(sol[max(lines)])
```
**Lets Share Your Solution too.**

I write blogs about Computer Vision projects on my GitHub page [q-viper.github.io](https://q-viper.github.io) and if you got some time please share yours too.
What are some fundamental differences between how a site is built in PHP compared to using web forms in ASP.NET?
Tags: php, dotnet, career, computerscience
Published: 2020-12-10 06:00:39

Programming Language is Different One is Using PHP and AspDotNet Webform uses C# or other dotnet supported language
In AspDotNet Webforms you can use Visual Studio IDE that provides Easy Project Management , TFS for Version Control and Working in Teams , Automatically Managed Project Structure and Various other VS IDE features like to Search block of code in current document or entire project and many more I can’t list them all here

Where as in PHP you have paid IDE’s and less free ide’s otherwise Notepad , Notepad++ , espresso and other options are there but there is some lack of Mature IDE’s like VS here . 

Debugging - In AspDotNet webform VS greatly make a difference By providing Awesome Debugging Tools for Error finding
Where as in PHP there is lack of some mature debuggers and sometimes choosing on of available debuggers create pain in setup Them .

AspDotnet & PHP Both are opensource now Even we have Community editions available for VS

Most people deploy aspdotnet website on windows but Both are Cross-Platform now . php is available to be deployed on linux server and aspdotnet is also now available to be deployed on linux servers

C# is faster than php but this difference can be at execute of approximately 2,000,000 loops of execution

See its not important you must have Nuclear Weapons on your side . If you utilize your tools in a proper & Efficient way then they all proves to be good .

We have Many website in php that are performing exceptionally good and also there is list of website that are creating problems in php But its the programmer that is using php code to built website not php automatically generating a website .

Meet the Experts For Better Guidence  : https://nareshit.com/asp-net-mvc-online-training/
SASS (Syntactically Awesome StyleSheets)- Basics (Part 1)
Tags: css, javascript
Published: 2020-12-10 05:53:41

What we will learn:- 

*  Store Data in variables
*  Nesting CSS with Sass
*  Reusable CSS using Mixins
*  if, else 
*  for loop
*  each 
*  while
*  Splitting styles into different files
*  Extend properties of other class


We will keep the articles short so that we can make this a short series of articles. For this article, we will be going through the first 4 parts of the above learning objectives.

### Storing Data in variables:-

In CSS if we want to declare some style for a particular class we had to write all the particular styles for it though we might have the necessity to have some of the style properties the same for the next class. This gives rise to problems when the style needs to be changed in the future. 

CSS doesn't support variables for the above-mentioned problems. In Sass, we can mention a variable that can be used and assigned like any normal programming language.

So how we do so? Let's dive into some code - 

```css
$fonts: Arial, sans-serif;
$headings-color: green;

//To use variables:
h1 {
  font-family: $fonts;
  color: $headings-color;
}
```
We can see how the variable is being used in place rather than using the actual property value.

### Nesting CSS with Sass

For any normal CSS, we don't have the unique way to nest CSS into other CSS, rather we follow writing each class and then defining the properties for each of them. For example:- 

```css
nav {
  background-color: red;
}

nav ul {
  list-style: none;
}

nav ul li {
  display: inline-block;
}
```

For the above code, we have all the classes like ul and li nested in but the above code is the normal CSS code and doesn't follow the nesting architecture. If we were to write this code in Sass form we will have:- 

```css
nav {
  background-color: red;

  ul {
    list-style: none;

    li {
      display: inline-block;
    }
  }
}
```

### Reusable CSS using Mixins:- 

This is similar to what we can say as defining the function and using it again and again with different parameters. This gives a lot of flexibility and control over the use of different styles and can reuse again and again. Let's see how we can do this.

```css
<style>
@mixin border-radius($radius) {
    -webkit-border-radius: $radius;
    -moz-border-radius: $radius;
    -ms-border-radius: $radius;
    border-radius: $radius;
}

// To reuse it again
div {
  @include border-radius(15px);
}
</style>
```

### Using if-else 

This works exactly similar to what we normally see in the if-else statements. Let's see how we can implement it in Sass

```css
@mixin text($v) {
  @if $v == danger {
    color: blue;
  }
  @else if $v == alert {
    color: red;
  }
  @else if $v == success {
    color: yellow;
  }
  @else {
    color: black;
  }
}
```

In here we use mixins and we can just do normal if-else to make conditions on the styling we want to achieve.

## Stay Tuned for the next article we will go through the next 4 sections that we haven't yet covered 😊😊