teleren/devto huggingface dataset:
Question on Fork System Call | Operating System - M01 P09
Tags: linux, beginners, devops, codenewbie
Published: 2020-11-16 06:45:34

**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 first module which consists of 12 articles.**

_In this article we will see a question on fork system call, and by that question I will try to explain you the concept of fork system call._

So, in the previous article I had explained about fork system call, it is recommended that first you go through that article for getting a basic understanding of the topic, [Fork system call](https://dev.to/rahulmishra05/fork-system-call-operating-system-m01-p08-27hp)

I am going to use a `C` program to explain you about `fork` system call 
```c
#include <stdio.h>
#include <unistd.h>

int main() {
    if(fork() && fork())
        fork();
    printf("Hello");
    return 0;
}
```
Now, the compiler will execute the code and when the `if` statement come, the first `fork` command will be executed, and a child process will be created, and both the process _(child process and parent process)_ will run parallelly, as you can see in the below diagram.
![Untitled Diagram.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605508750461/sVVqEhiBe.png)

Now the child process `C1` will print _Hello_

As you can see that `AND` operator is written after first `fork()` so it will also get executed, so another child process from parent process will get created. As you can see in the diagram below.

![Untitled Diagram (1).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605508819072/nonrBRYjI.png)

This `C2` will also print _Hello_

Now the `if` statement is completely executed, and now the `fork()` statement  written inside the `if` statement will get executed. And again a child process of parent process will be created. As you can see in the diagram below. 

![Untitled Diagram (2).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1605508827736/Y3umiDR-f.png)

This child process and parent process will print _Hello_

_Here, in total `fork` is done **3** times, and in total **4** times __Hello__ will be printed._

Hope you learned something. If you have any question, query, doubt or just want to share something with me, then 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)
CPython and more...
Tags: python, cpython, programming, opensource
Published: 2020-11-16 06:31:08

So, yesterday I stumbled upon an insightful post on the actual use case for CPython and who should use it, by Nick Coghlan (CPython core dev).

Some of the use cases I found helpful

✔ Personal Automation & Hobby Projects
✔ Organisational Process Automation
✔ Continuously Upgraded Infrastructure
✔ Ephemeral Software
✔ Shared Abstraction Layers

There are so many things he discuss in the article, like

Which audience does CPython primarily serve?
Where does PyPI fit into the picture? (my favourite section)

And, many more !!

Article link in the comments. Do check it out !
Open Source & GDP
Tags: opensource, github, python, javascript
Published: 2020-11-16 06:28:36

GDP, may be is, one of the most talked about parameter to assess the financial stability of a country.

One issue with GDP is that, it underestimates the value of free goods and services !

Consider free programming languages (open source) like Python and JavaScript, these contribute to more than 70% of job market.

These can be used by any company to develop products or provide various services either for free or for a price.

If a company hires someone to make changes to open-source libraries, then he/she would be paid and that contributes to GDP but if that person decides to contribute to open-source on his own, then that would miss GDP, even though both creates the same value !

A research led by Carol Robbins of the National Center for Science and Engineering Statistics, attempt to quantify a share of the value being created by these open-source languages.

They found that cost to develop the code for such open-source languages would be over USD 3 Billion !!

With values like these missing from GDP, it becomes very difficult to get an actual economic growth estimate.

What are your thoughts on this parameter missing from GDP ?

Link to research paper in comments.
Python (NEW) Print ?
Tags: python, programming, computerscience, discuss
Published: 2020-11-16 06:26:36

Recently, Guido Van Rossum (Creator of Python) presented python community with the idea of new print statement !

When Python 3 replaced print statement (Python 2) with print() function, many felt the transition is smooth and adaptable compared to other changes.

As of now, Python 2 is the legacy version and Van Rossum presents an updated print statement !

```
>>> print 1+6
7
```
Hmm, Nothing New !!

The new parser for print statement has the power to make ANY function in python to be used as a statement.

Yes, ANY function/method can be used as a statement !

```
>>> len ‘abc’
3
```

```
>>> import random
>>> random.randint 2, 5
4
```

How crazy is that !!

It is not just new print statement but a new way to look at python statements.

But, it comes with a drawback.

```
>>> print (2), 10
2
(None, 10)
```

Here the parser consider print(2) as function first, then evaluates return of print function (None) and 10 as a tuple, hence the output.

Anyway, it is really amazing to see generic way of using statements in-place of other functions !

Would you love to use a python statement over a function ? If not, why is that ?
Delegating OOPs
Tags: python, oop, discuss, programming
Published: 2020-11-16 06:23:10

**Delegation**

One of the pillars of OOP, it help objects to interact with each other. But, there is a dichotomy in delegation, it can be achieved following 2 different strategies.

One is Composition and other is Inheritance. But, why we tend to use inheritance more often than composition in our regular design solutions ?

Inheritance can result in clash between same names with different meaning, if not dealt with properly or we may need to remove some methods from parent class which will result in unnecessary polluting of child class.

Composition can have too many methods from container class to be contained or we may be composing instances, but creating many class methods so that the container can access them.

There may be pitfalls to both strategies, but we should look at how we can reduce maintenance hours for a particular project.

To get a scalable model, we can look at following points before designing our project:

⚡ Visibility of class methods
⚡ Control over classes
⚡ Relationship between classes
⚡ Entities in classes

Your thoughts on Inheritance and Composition ? What are the factors you take into account before proceeding ? Which one do you prefer or use regularly ?
Graceful shutdown of your legacy backend service
Tags: computerscience, loadbalancing, legacysystems, stickysessions
Published: 2020-11-16 06:20:36

# Introduction
If you are dealing with a multinode backend legacy application using stickysessions, consider implementing a graceful shutdown. Your service consumers will thank you when you are servicing nodes with zero downtime and session errors. There are many ways to do this but your loadbalancer needs to provide some supporting functionality - if you don't want all consuming application(s) to implement session restore capability that is.

# Painpoint
If you recognize the below pattern you are already one step ahead. It means you have taken operations seriously and configured some sort of healthcheck or other monitoring for your problematic legacy web service. What you see is the periodic downtime or errorrate increasing each time a backend node is taken offline, e.g. for deployment (Thanks to Jose Arroyo Rodriguez for the inspiration).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/df7lruwchvvj9qxzrrdt.jpg)

# Solution
There are two main ways to tackle this
1. Implement shared state for the nodes. This option could be too costly if you are dealing with a huge legacy application where you probably don't want to touch to much of it's code. You also need some additional loadbalancer capabilities anyways when your node "signs out" and it could have a negative performance impact.
2. Use a loadbalancer (LB) with configureable graceful shutdown of sessions. This happens when you node says "I'm out", e.g. by  specific http statuscode or body in a healthcheck service operation. The LB then stops sending new sessions to the node but keeps existing ones alive. This allows for sessions to dry out naturaly, but may take a while. After draining the node it can then be shutdown gracefully. 

# Conclusion
Other than the above you can of course always convince your consumers to implement retry/session restore capabilities. This could even be more cost-efficient if you only have a single consumer. I find solution approach no. 2 the most elegant but it requires a powerful LB. As far as I know only HAProxy and F5 support it in a manner that does not involve changing configurations every time. 

Do you know a better solution? Any feedback, recommendations are much appreciated ;)

A more comprehensive article on the matter can be read here in the context of NodeJS: [Implementing NodeJS HTTP Graceful Shutdown](https://blog.dashlane.com/implementing-nodejs-http-graceful-shutdown/).
BeautifulSoup ! The only option ?
Tags: python, beautifulsoup, programming, webscraping
Published: 2020-11-16 06:19:23

There are lot of ways in which a developer can scrap web using Python, but why we tend to rely on BeautifulSoup as our first choice or the only choice ??

Is it because when we google `web scraping using python`, we get a whole lot of links for BeautifulSoup tutorial ? Or because we actually know the benefits of using BeautifulSoup ?

Same functionality can be achieved simply by using **urllib** library, but it has its own limitations, one such limitation is writing several methods from scratch that are readily available in BeautifulSoup.

On the other hand, writing methods from scratch can help us define custom behaviour !

Sometimes HTML is so disorganised that BeautifulSoup may not interpret the HTML tags properly.

There are forms we may need to scrap, then we would need something extra - MechanicalSoup !

Yes, another ‘SOUP’ library (don’t know why scraping community loves soup so much or is it Software Of Unknown Pedigree ?)

There are so many modules to do a particular task, why aren’t we making a pros/cons list of those but simply following what a tutorial mentions ?

If we know how to debug a code, then we should just dive into code of such open-source libraries and see for ourself whether they solve our problem the way we want.

What are your views on different scraping libraries available ? Which one do you prefer or use regularly ?
Dynamically render icons in Gatsby
Tags: help, gatsby, react, svg
Published: 2020-11-16 06:15:48

I can't figure out the best way to dynamically use icons based on a users choice in a headless CMS (in this case Netlify CMS).

I made it work in two ways, but both have downsides:

## Option 1: via component name
The user enters name of the icon in the CMS (e.g. "FaClock"; the UX is of course another story here).

The component:
```js
import * as Fa from "react-icons/fa";

export const CustomSvg = ({iconName}) => (
  <Box as={Fa[iconName]} />
);
```

**Downside**
This has the huge downside, that all icons are included in the bundle,  which leads to performance issues.

## Option 2: via SVG image uploaded
The user uploads an svg via file picker.

The component:
```js
export const CustomSvg = ({iconURL}) => (
  <img src={iconURL} />
);
```

**Downside**
SVG is included as an `img` and I can't change color etc.



I'm pretty sure there must be a better way...
Solution to incomplete display of Scrollview nested ConstraintLayout or LinearLayout
Tags: android
Published: 2020-11-16 06:13:24

The content exceeds screen's length,so use a ConstraintLayout wrap the contents up,then use a Scrollview nested outside,but after run on phone,the content can't display completely display.see the source code of Scrollview
```
 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        if (!mFillViewport) {
            return;
        }

        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (heightMode == MeasureSpec.UNSPECIFIED) {
            return;
        }

        if (getChildCount() > 0) {
            final View child = getChildAt(0);
            final int widthPadding;
            final int heightPadding;
            final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
            final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (targetSdkVersion >= VERSION_CODES.M) {
                widthPadding = mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin;
                heightPadding = mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin;
            } else {
                widthPadding = mPaddingLeft + mPaddingRight;
                heightPadding = mPaddingTop + mPaddingBottom;
            }

            final int desiredHeight = getMeasuredHeight() - heightPadding;
            if (child.getMeasuredHeight() < desiredHeight) {
                final int childWidthMeasureSpec = getChildMeasureSpec(
                        widthMeasureSpec, widthPadding, lp.width);
                final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
                        desiredHeight, MeasureSpec.EXACTLY);
                child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
            }
        }
    }
```
First of all,we see, when mfillview is false, it will be returned. The explanation of mfillview is: when this variable is set to true, Scrollview will make its child views fill in the currently visible area,I Try to add the attribute android:fillViewport under the Scrollview tag
```
android:fillViewport="true"
```
or add
```
android:layout_marginBottom="xxdp"
``` 
under the ConstraintLayout/Linearlayout
Code Analyzer for C#
Tags: csharp, opensource, dotnet
Published: 2020-11-16 05:52:00

Another busy week, glad that I'm still alive.

This week, we're introducing code formatter and linter to our link checker project that we've been working on it for the whole semester. Formatter and linter are both new to me. The first time that I use linter was doing one of the PR in Hacktoberfest. It was a browser extension project, and they use ESLint to analyze their code. 

After doing research of C# formatter and linter, I have to say, there isn't much choice for C#. I'm guessing it is because that most of the C# developers use Visual Studio and VS has many powerful tools for either formatting or analyzing. It is also hard to find the C# formatter and linter that has command-line interface. For example, while I was looking for C# linter, I found a code analyzer for C# called [StyleCode Analyzer](https://github.com/DotNetAnalyzers/StyleCopAnalyzers), however, it doesn't provide command line interface, which does not meet the requirement of this lab (providing command line setup). I saw other developers have been asking the feature of command line interface for a while, hopefully this feature can be introduced in the future release.

I end up using [dotnet-format](https://github.com/dotnet/format) as my formatter and [Resharper](https://www.jetbrains.com/help/resharper/InspectCode.html) as the code analyzer. A bash script is also added for other developer to run for the environment setup. After applying these tools and start writing the contribution documentation, I again realized how many efforts are made behind an open-source project. To work as a group, minimizing the possible errors and improving the readability of my code is for sure critical. Honestly, in a limited number of options, this formatter and linter are not my best choices. I'll keep looking for better tools and apply them to my C# project.
4 reasons to be a content creator
Tags: discuss, watercooler
Published: 2020-11-16 05:39:56

Being a content creator is fun and so beneficial! 😊 Here is why you should start too:

👥Connect with other creators and your community 
🎬Improve your writing/filming skills
👩‍🏫Help others by sharing your knowledge 
👩‍💻Boost your CV

What do you think? Have a good start into the week. 😊
<help>I am looking for notes of DATA Structure and Algorithm written in easy English</help>
Published: 2020-11-16 05:33:18

I need notes on Data Structure and Algorithm which cover all concepts briefly, in easy-to-understand English, with coding and real life examples. I have a very less time before Quiz and Mid-term examination in my university and I need to go through the syllabus real-quick. Books and video tutorials are to large for last minute revision.

#Datastrucure #Algorithm #Notes
Don't stick with the theme!
Tags: css, ux, webdev, flutter
Published: 2020-11-16 05:15:06

Before underestimating me hear me clearly.
This is my first post and I am a noob

What do I mean??
I am talking about the ui of your app. If you are a webdev or an app developer ( not the one with figma) and you struggle with your designs hear me out. There are a lot of design trends in the ui realm and it's a mess. Like the material or the Cupertino, etc.. and it's hard to implement. (Yes, in flutter it's quite simple but)Some functionality or widgets by our apps needs to be different and you can't find a widget or a component for that and you can't find it , so naturally you try to combine different widgets and nothing works here's what you wanna do.

1) Create your own widget/component
I mean your own. Why not just keep it simple and clean
2) Large apps are not strict followers of themes
For example take the ui of YouTube or instagram, do they follow stylish or extra flashy UI. No usability > style. Think about it
3) Don't follow the themes you see on Instagram.
There are lot of flashy themes created with UI design softwares and some of them are actually good. But yours is too. The only way you can improve is by trying


Conclusion
I mean that's is bye. Leave a like
Project 11 of 100 - React Weather App
Tags: 100daysofcode, react, javascript
Published: 2020-11-16 05:10:38

*Hey! I'm on a mission to make 100 React.js projects in 100 days starting October 31, 2020 and ending February 7th, 2021. Please follow my dev.to profile or [my twitter](www.twitter.com/jwhubert91) for updates and feel free to reach out if you have questions. Thanks for your support!*

Link to today's deployed app: [link](https://100-react-projects-day-11-weather-app.netlify.app/)
Link to the repo: [github](https://github.com/jwhubert91/100daysofreact/tree/master/day-11-weather-app)

Asynchronous Javascript is tough to get a handle on anyway- doing projects using the fetch API, promises and async-await in React is a whole 'nother ballgame because you need to have some control over which components are refreshing and when. Otherwise you can get some unexpected behavior.

##Design
I was inspired to take this on from a [blog post](https://www.dunebook.com/react-project-ideas-for-beginners/) suggesting it among other React project ideas. I've built weather forecast mini-sites with pure Javascript and also with Node before but have to admit building one with React was the most entertaining, and the most challenging.

You really get a sense of what React is used for whenever you import a component and create a list of them with the ES6 `.map()` method. That's something you really can't do without a front-end framework like React.

My project used a Search component, a conditionally-rendered Error component for error handling, a Today component which serves as the main display and a ForecastDay component which is used for rendering the little div's for the 5 day forecast. I used Flexbox for that piece as well and some absolute positioning to hold the 5 day forecast in place.

##APIs
This project is an excellent introduction to working with APIs and specifically things like the fetch() API. After doing some text validation and manipulation I used the **Mapbox API**- which is absolutely great and free (unlike Google's Maps API) to geocode the user's search and get latitude and longitude.

After getting Latitude and Longitude from Mapbox we then need to ping a weather service. I've used DarkSky before but I just found the **openweathermap.org** API to be incredibly robust- all the way down to including images for each weather code.

##Takeaways
Probably the trickiest part of this project was handling what should be rendered while we are waiting for promises to be fulfilled, as well as what should be rendered if your search is invalid or API call doesn't work. In a standard html,css,javascript page if something doesn't render you might not notice. In React, if your component is being fed props that are defined and you try to use them, your whole application might crash.

Highly recommend this project for anyone new to React.
Thinking out loud about a dumb side project of mine
Published: 2020-11-16 01:03:48

I've been thinking about what I want to make after this class at General Assembly, and honestly... I want to make something dumb and fun. I want to make my own Blaseball.

For anyone unaware, Blaseball is, and I quote "an online browser baseball simulation horror game." 

That doesn't quite explain it though, I guess. Well, since sports will be on hold with the global pandemic, and since Baseball can be simulated fairly easily with RNG, The Game Band put their own spin on Splorts on the internet. Blaseball is a fictional baseball league with teams like the Kansas City Breath Mints and players like Polkadot Patterson. From there, a league plays out over the course of a week, with fans interacting by betting fictional currency on the games to then reinvest in boons for their team next season.

It's a weird game that got a lot weirder as time progressed, and I have fallen in love with it. Adding my love of Blaseball with my love of video games, I want to make what I have called the BlarPG!

Imagine Blaseball meets Twitch Plays Pokemon. I'm working on creating a few different databases for the characters, enemies, and attacks during my breaks from my Capstone project. I'm working on generating auto-scripting for the fights but I don't have anything to show just yet. My current challenge is trying to have one Pandas dataframe call another the same way I would with a SQL dataframe. Maybe I should just be doing this in SQL then? I'll come back in a couple weeks if/when I have any project to show, but I hope to get a working demo of it by the end of the year! Wish me luck!

Until then, We Are All Love Blaseball <3