teleren/devto huggingface dataset:
Git Merge: The Final Guide
Tags: tutorial, git, codenewbie, beginners
Published: 2021-08-28 11:08:43

## Merging
Having multiple branches is extremely convenient to keep new changes separated from each other, and to make sure you don't accidentally push unapproved or broken changes to production. Once the changes have been approved, we want to get these changes in our *main* branch!

One way to get the changes from one branch to another is by performing a `git merge`! There are two types of merges *Git* can perform: a **fast-forward**, or a **no-fast-forward**


### Fast-forward 
``` 
git merge --ff 
```
A **fast-forward** merge can happen when the current branch has no extra commits compared to the branch we’re merging. Git is... lazy and will first try to perform the easiest option: the fast-forward! This type of merge doesn’t create a new commit, but rather merges the commit(s) on the branch we’re merging right in the current branch 

### No-fast-foward 
``` 
git merge --no-ff 
```
Not ever your current branch doesn't have any extra commits compared to the branch that you want to merge. If we committed changes on the current branch that the branch we want to merge doesn't have, git will perform a **no-fast-forward** merge.

With a **no-fast-forward** merge, Git creates a new merging commit on the active branch. The commit's parent commits point to both the active branch and the branch that we want to merge!


### Merge Conflicts
Although *Git* is good at deciding how to merge branches and add changes to files, it cannot always make this decision all by itself. This can happen when the two branches we're trying to merge have changes on the same line in the same file, or if one branch deleted a file that another branch modified, and so on.

In that case, *Git* will ask you to help decide which of the two options we want to keep! Let's say that on both branches, we edited the nineth line of *file.txt*.

If we want to merge *dev* into *master*, this will end up in a merge conflict: which is the correct line? Git can't knows this.

When trying to merge the branches, *Git* will show you where the conflict happens. We can manually remove the changes we don't want to keep, save the changes, add the changed file again, and commit the changes.
Step by step instructions to install node and npm using Linux binaries
Tags: javascript, node, discuss, linux
Published: 2021-08-28 11:08:29

Yes, you can install node through **apt package manager** with the command `sudo apt install nodejs` and you get the latest nodejs installed. But many people find it very complicated to *install Binaries*. So, I will be breaking down the process into four simple steps. (Note: **I'm using pop os and will be installing node v14.17.3**).



## Let's start:
### 1. Get the binary file
So head to [nodejs](https://www.nodejs.org/download) website and download binary files of latest stable nodejs.

![Nodejs download website](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aaf5m2ii6hjmucw36bwn.png)

### 2. Extract the tar file
Go to the directory where you've downloaded your nodejs. **In my case its Downloads directory.**

![Downloads directory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdsrs2h1m8uhf91vsg83.png)

Then, extract the files with this command `tar -xf "*your_downloaded_file*"`

![Tar extract](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hirjla0zqt2ciaz8cqg3.png)

Or, go to Downloads folder using file manager, right click on tar file and extract *(so simple)*.

![Extract through file manager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ice5f4vd7dzh7iamfqw5.png)

### 3. Copy folders to /usr
Now we get these all folders inside our extracted node folder.

![Files and folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdxkunbhkne7zhmi89k9.png)

Here we need to **cd** inside that folder. Type the command `sudo cp -r ./{lib,share,include,bin} /usr` hit enter and type your password. Remember to use **-r** flag to make sure that all files inside those folders are also copied.

![Copy to /usr](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywbdurkwyr4benfv1m28.png)

### 4. Check the node and npm version
You can check nodejs version with the command `node --version` or `node -v` and check npm version with`npm --version`.

![Node and npm version check](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo58p00lnh9wpaqe2g2v.png)

That's it, *you have now installed nodejs and npm in your system.* **Enjoy** 😎
Linux File Permissions
Tags: linux
Published: 2021-08-28 11:06:46

# Basic File Permissions
Linux systems in general break file permissions into three basic types:
* Read
* Write
* Execute

These basic types tie into the ownership of the file. The owners are broken down into three groups as well:
* Owner
* Group
* Other

These permissions and ownerships are represented as a three digit number. Each digit can have a value of 0-7 (inclusive). first digit represents owner permissions, the second digit represents group permissions, and the last digit is for others. There is a number associated with each permission where read has a value of 4, write has a value of 2, and execute has a value of 1. 

When we look at the binary values for these permissions it all makes sense:

```
Read:    (4)d = (100)b
Write:   (2)d = (010)b
Execute: (1)d = (001)b
----------------------
All:     (7)d = (111)b
```

because of this design we can easily find/set permissions for any file in linux.

For example a file that has all permissions for Owner, but no permissions for group or others will have a permission of 700.

# Changing permissions on a file in Linux
To change the permissions of a file we use a utility called chmod. chmod stands for Change Mode. This is a utility that is shipped with many linux distributions. Since chmod is changing permissions on a file (writing new permissions) then you need to have write access to the file that you are trying to change.

so the code looks like something like this: sudo chmod 777 file_name

# Changing ownership of a file in linux
To change the ownership of a file we use a utility called chown which stands for change owner the syntax for this is as follows:
sudo chown user:user_group file_name

If you have any questions or there is something incorrect here please let me know and I will fix it.
Reboot Windows Shortcut
Tags: windows, archlinux, systemd, dualboot
Published: 2021-08-28 08:58:41

Hello,
this is my first post here,
I have Arch Linux installed with windows 10 dual boot & systemd-boot as bootloader

so first u need to check your boot entries:

```
bootctl list
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3z5svmjpjgn0y2zihoka.png) 

**remember the windows id in the output**

then create a new file anywhere in your machine

```
cd & touch reboot-windows.sh
```

And add the following code inside the new file

```
#!/bin/sh
systemctl reboot --boot-loader-entry=auto-windows
```

here `--boot-loader-entry=<your windows id>`

launch the script and you will escape to windows!
![escape to windows](https://media.giphy.com/media/3o6gDUY3B8ocAgMNhu/giphy.gif)
[Part 4/4] ⚛️ Senior React Coding Interview, By A Professional React Developer 👨‍💻
Tags: react, javascript, webdev, tutorial
Published: 2021-08-28 10:51:06

**About Me:** I've been a professional web developer for just over 10 years now. I'm currently the lead web development instructor at [Better Coding Academy](https://codebetter.com.au), and as part of what I do, I post videos on our YouTube channel at [https://www.youtube.com/c/BetterCodingAcademy](https://www.youtube.com/c/BetterCodingAcademy).

_(Subscribe for awesome web development content!)_

Here's the final part of the mock React coding interview! I polish off a few loose ends of the reusable table hook, fixing up things such as adding rows, removing rows, and changing `pageSize`.

I hope you've enjoyed this series! Be sure to check out my channel for many more tutorial series just like this 😄

{% youtube 9Qt1IfiZjik %}

Happy coding!
Print() built in function in python
Tags: python, codenewbie, programming, beginners
Published: 2021-08-28 10:49:27


print() is a built in function in python 
we use print() function to print the object in it 
which is given in double Quotation
which will be like:
Print("object")
or we can do with the old classic word
ie. print("Hello World!")
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fscccytp6vcr6hbtmyzb.jpg)

We can only print ,if the object is in b/w the in double Quotation.
if the object is not in b/w the double Quotation it would give an error.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk3d387b3j9zrbxs56l2.jpg)
the error would be syntax error
why is it giving an error?
should it just print the object as it before?
what is the problem in printing with out double Quotation?

The problem in printing the object is,because the computer think the 'object' is also an 'built in function' and after thinking that it searches in the built in functions,
as the object will not be present in the built in functions ,it will give an error .
So,we have to specify the object in double Quotation.
Productivity porn vs Just code
Tags: watercooler, beginners, discuss
Published: 2021-08-28 10:40:25

## I am spending 90% of my time learning how to be a good coder and 10% of my time learning how to code

![Gif Homer Simpson saying he improved his productivity by 3 times because he only needs to type y instead of y.e.s](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfw68wjpgd9iy13ox9es.gif)

It feels nice reading productive hacks, how to be a good programmer, roadmap from self-taught programming to FAANG etc etc.

These kind of content empowers people's imagination! It make us feel like we are also a special bean in the universe destined to do stuff that empowers millions! We are on to building the next Google!

---
"The anticipation of a good event happening sparks more joy in the brain than the good event actually happening" (source: Albert Einstein??? Abraham Lincoln??? Whatever...)
---

---
This is a problem for me, because instead of reading up about productivity hacks, how to learn well and fantasising about my seven figure FAANG job that I am going to get straight out of bootcamp, I can spend that time to you know... **learn to code...**

![Gif of Homer being bored](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5j2f89onj4hpz7cnq9w.gif)

Well I get it... learning how to code is not as fun as fantasising about your coding career. But if you have to choose between the two, learning how to code well will definitely bring you better chance of getting you to where you wanna be.

Don't get me wrong, productivity porn type content are still helpful! Learning what to do as a Junior Developer is definitely going to help propel your career. But you (I) should probably spend 90% time on learning the actual thing and 10% time on these meta-learning. **Productivity hack complements your core skills, not the other way round.**

Note to self: Just code lol! Happy coding :)
Express your intentions in your coding - attributes that are not
Tags: python, codequality, architecture, refactorit
Published: 2021-08-28 10:13:58

In the previous post of this series, I suggested prefixing the underscore `_` to variables intended to be short-lived. Here I will discuss another example where variable names lie on their intentions.

Pay attention: people are addicted to the `self.`

If you are coding a class, you have some logic in a method, and you are defining a variable within that method, do **not** use `self.` if that variable has no usage outside that method! :relieved:

When you assign a variable to `self.` you are telling the readers of your code that variable (better said, that attribute) has another purpose somewhere else in the execution workflow. Maybe it is even part of the public API. Therefore, someone editing your method will automatically trigger the alarms and search the codebase for a place where that attribute appears before refactoring or recoding your method. The maintainer of your code will get a bit stressed if she/he finds no place anywhere else where that attribute is used. What is happening here?

So, be mindful and express your intentions in your coding. That is, if you define a variable inside a class method, don't use `self.` if the scope of that variable does not go beyond that method. Instead, use `self.` indeed if that variable is an actual attribute part of the private or public API of the class.

```python
class MegaClass:

    def method_1(self, arg1, arg2):
        """Write a docstring ;-)"""
        var1 = # some logic with arg1. `var1` dies after the method
        self.var2 = # some logic with var1 and arg2
        # self.var2 is an actual attribute of MegaClass part of its API.
```

Hope this example is clear and you can use it to better express your intentions in your coding :smile:
Entrepreneurship
Published: 2021-07-09 04:40:32

Entrepreneurship is awesome.

To breathe life into an idea with the hope that other people will see what you see, and believe in it, and maybe even buy it - whatever that is - how cool is that?

As some of my thoughts shift to the coming project-building phase, I've started to wonder whether there's room in this program for entrepreneurial experimentation and building. If we're going to build a storefront project, why not make a product and really sell it? Heck why not build a storefront manager and sell that as a service.

Are we going to have projects pre-determined for us, or do we determine them ourselves? If we determine them ourselves, why not make something for the purpose of existing in the world, and not just in our portfolios?

I had a conversation with a 'senior' in the program back in week 1. He told me that he was given the advice that when applying to jobs, you want your portfolio to not just be full of school projects. That employers want to see that you've built and contributed to projects that have a real impact. That in some form or fashion - open-source, for-hire, or maybe even on spec - that other people interact with your software and maybe even depend on it.

We got into software engineering to make things. Why not make real things now?

What might that look like? I'm not sure. I think about all of the talent in this program and what we're doing with it. In most cases, cultivating and growing our skills so that we can contribute to companies that are already out there. Could Hack Reactor - or any other bootcamp, be a startup incubator? Can the students be the incubators? Could the wider bootcamp ecosystem or student community be the incubator?

As a student, thinking about questions like these are really motivating. How sick would that portfolio be - yeah these are the sites and apps that we're making now that actually work and are actually used. Projects that we have to actually manage and maintain and grow like we're going to be doing when we're professional professional engineers. Projects that have real stakeholders. That have team-members who are invested in the project and its success. Maybe not *invested*-invested but also yeah, maybe.
Smallest Common Multiple
Tags: javascript, beginners, devops, programming
Published: 2021-08-21 01:00:07

* Now the next problem we're trying to figure out is finding the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.

* For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6.

```
function smallestCommons(arr) {
  

  return arr;
}

smallestCommons([1,5]);
```
* Answer:
```
function computeSCM(num1, num2) {
  let min = Math.min(num1, num2)
  let max = Math.max(num1, num2)

  for (let i = max; i <= min * max; i+= max) {
    if (i % min === 0) {
      return i; // make sure to find the smallest commmon multiple.
    }
  }
}
// now that we have that we need to find smallest common multiple of an array of numbers or a range.


function smallestCommons(arr) {
  let minNum = Math.min(...arr)
  let maxNum = Math.max(...arr)
  let scm = 1;

  for (let j = minNum; j <= maxNum; j++) {
    scm = computeSCM(scm, j)
  }
   

  return scm;
}


console.log(smallestCommons([1,5])); will display 60.
```
* Or:
```
function smallestCommons(arr) {
  arr.sort((a, b) => a - b); // comparing two numbers Either way will switch the positions when a is greater than b.

  
  //arr.sort((a, b => {
    //a > b?-1:1
// }); The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
  let [div, num] = arr
  while (div < arr[1]) {
    if (num % div == 0) {
    div++
  } else {
  num += arr[1]; // arr[1] continues being 5 because given the array [1, 5] as an example, arr[1] will always be 5, but the value stored in num increases with each loop from 5 to 10 to 15 to 20 and so on. The first loop tests 5%1, 5%2, 5%3, 5%4 (until it gets a remainder). Second loop tests 10%1, 10%2, 10%3, 10%4. Third loop tests 15%1, 15%2, 15%3, 15%4. And so on until there is no remainder in the loop, which means we have found our solution num. The reason we are not testing divisor 5 is because our dividend is always a multiple of 5 and so we know it will have no remainder when divided by 5 (that's why we can use div < arr[1] instead of div <= arr[1]).
  div = arr[0];
  }
}
  return num
}


console.log(smallestCommons([1,5]));
```
My first Phase with Flatiron
Tags: javascript, html, css
Published: 2021-08-28 09:29:28

The first 3 weeks of my Flatiron journey was just a little crazy. I learned so much, so quick, it was fun, challenging, and a great way to meet new people. I've been in and out of software development for the past couple of years, but finally decided it was time to make it my top priority and pursue a career in it. At the end of this Phase we were tasked to build out a functioning website with a partner, and on this website we had to at least include a GET request, and we had to have some sort of interactivity for users, whether that be the ability to add likes, dislikes, or maybe even a comment. My partner and I decided to use the OpenbreweryDB for our project. We pulled in data from there, and then we used DB.JSON in order to store the information we got back. We were then able to add functionality that we wanted, so we ended up making a site that was basically a review site for Breweries, The Reviewery. We pulled in a list of Breweries and listed the Brewery name and the city in which it was located. We also added a like and dislike functionality, but we wanted to do more, and we wanted to have something different. So we ended up deciding to add a button on each of the cards that simply stated "Revieweries" that you could click on to pull up a modal, that would show comments, and allow you to add new comments. All of this data persisted using Fetch, and using a POST request for the comments, and a PATCH request for the likes. The only bad part, is that all of the data lives in a DB.JSON file, so it doesn't really work unless we show it personally and have the database running. In the future I want to make a real backend for this project, and actually get it up and running for real!
How different is CommonJs require from ES6 import?
Tags: javascript, es6modules, commonjs
Published: 2021-08-28 09:28:36

In JavaScript, you can use either ECMAScript 6(ES6) modules or CommonJs modules in your project and there are a few differences between these that do affect how your program modules are loaded. In this article, I explore how each works and how it may affect your program execution.

###CommonJs modules.
CommonJs is the original and default module system of Node.js which uses require and module.exports. Below is an example.

```javascript
// Importing modules
const fs = require('fs');
const fileDelete = require('./fileDeleter');
const fileName = require('./fileNamer');

const writeFile = (data) => {
  return fs.writeFileSync(fileName, data);
}

// Exporting writeFile module
modules.exports = writeFile;
```

With require, you can’t selectively load only the modules you need. This means even the fileDelete module from the example above will be imported even if it is not needed or used anywhere. Additionally, importing of the modules is synchronous which means that fileName module can’t be imported before fs and fileDelete modules are imported, and a failure to import fileDelete will cause run-time errors even if it is not used anywhere in our program. CommonJS modules are the choice for the node.js server.

###ECMAScript modules
ECMAScript modules are relatively newer and use import and export. Below is the transformation of our CommonJs example from above to ESM.

```javascript
// Importing modules
import fs from 'fs';
import fileDelete from './fileDeleter';
import fileName from './fileNamer';

const writeFile = (data) => {
  return fs.writeFileSync(fileName, data);
}

// Exporting writeFile module
export default function writeFile;
```

With import, you load only the modules you need. For example, the fileDelete module from the above will not be imported since it is not used anywhere. Additionally, the importing of the modules is asynchronous which means that both fs and fileName are imported at the same time. You generally want to use ESM for your new projects.

**…how about .cjs and .mjs?**
.cjs is a file extension for CommonJS modules while .mjs is a file extension for ECMAScript module. Node.js by default treats .js files as CommonJS modules. You can change this by adding "type": "module"to your package.json file so you can use ECMAScript modules (in your .mjs files) within a Node.js environment. This is what Google Chrome [V8](https://v8.dev/) recommends.

I hope this was helpful to you and for further reading, do checkout [JavaScript modules](https://v8.dev/features/modules).

*Happy coding!*
3 Toast Libraries You Can Use in your React Projects
Tags: react, toast, library, tutorials
Published: 2021-08-28 08:58:58

## what is toast

A toast is a non-modal dialog that appears and disappears in the span of a few seconds. ... Typically, toast messages display one or two-line non-critical messages that do not require user interaction.

## 1. react-toastify

- [GitHub](https://github.com/fkhadra/react-toastify)

- [Website](https://fkhadra.github.io/react-toastify/introduction/)

**react-toastify** one of the most useful toast libraries out there. It has tons of cool features like;

- Swipe to close
- Display a **React element** inside the toast
- Can remove a toast programmatically
- much more..

## 2. react-hot-toast

- [Github](https://github.com/timolins/react-hot-toast)

- [Website](https://react-hot-toast.com/docs)

react-hot-toast is small, accessible and easily customizable toast library which has;

- Promise API
- Headless Hooks
- Lighweight (*less than 5kb - including the styles*)

## 3. react-toast-notifications

- [GitHub](https://github.com/jossmac/react-toast-notifications)

- [Website](https://jossmac.github.io/react-toast-notifications/)

react-toast-notifications is also cool library to get work with but unfortunately it is no longer maintained.

## 4. Links
- [React-toastify v8 is live](https://dev.to/fkhadra/react-toastify-v8-is-live-4bal)

- [Top React toast libraries compared - LogRocket Blog](https://blog.logrocket.com/top-react-toast-libraries-compared/)