teleren/devto huggingface dataset:
Should I test absolutely every public method?
Published: 2021-04-05 10:04:07

No, of course not. Tests are also code, on which we spend time and money. Don't be paranoid: don't strive for 100% test coverage.

Don't test trivial methods, third-party libraries code and things you have already tested indirectly: presence of classes, methods, number of arguments.

Here's what Kent Beck [writes on the subject](http://stackoverflow.com/a/153565):  
> I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don't typically make a kind of mistake (like setting the wrong variables in a constructor), I don't test for it. I do tend to make sense of test errors, so I'm extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong.

And here's what [DHH says](https://signalvnoise.com/posts/3159-testing-like-the-tsa):  
> 1. Don't aim for 100% coverage.  
> 2. Code-to-test ratios above 1:2 is a smell, above 1:3 is a stink.
Confessions of a commercial developer - Part One
Published: 2021-04-05 09:55:00

So I started a new series over on my YouTube channel exploring the world of a commercial developer and dealing with the software world that we all work. 

I hope some of you can stop by and have a watch and enjoy the content. If you happen to enjoy please subscribe for all future videos and screencasts

https://youtu.be/42a6l6jVdN4

[![Buy me a coffee or pizza](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cl4e9xe8hwf891he4kc.png)](https://www.buymeacoffee.com/grahammorbydev)
Day 22 of 100 days of SwiftUi
Published: 2021-04-05 09:48:47

I just completed day 22 of 100 days of SwiftUi. Today, I worked on the Guess the flag challenge. I added a user score and custom error message.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c7apuihm90kaj6tzgrt.png)

The project is not yet complete but the code is available on [github](https://github.com/sanmiAde/GuessTheFlag)
Another 100 days
Tags: 100daysofcode
Published: 2021-04-05 09:43:25

Having completed another 100 days of code, it's a good time to look back and see what I did and what I learnt during that time.

I did two [Frontend Mentor](frontendmentor.io/) challenges: Accordion and IP Address Tracker.

Prior to these 100 days I'd done pieces of things and I wanted to do a whole thing, but nothing too complicated, hence the Accordion. I accepted the challenge of not using JavaScript and therefore learnt about HTML summary/details tags.

I learnt Webpack one afternoon and then used it on the IP Address Tracker. I'd hardly used APIs, so this one was a good one to use it on, since it involved a couple of them.

I did spend some time towards the beginning of the 100 days on Scrimba's Web Dev Weekly challenges and JavaScriptmas, while working on the IP Address Tracker.

I discovered CSS Battle. Watching some videos of devs doing the same challenges was useful for learning the different ways of doing the same thing. I then spent a lot of time distracting myself with various challenges on there.

A third of the way into my 100 days I'd learnt about intersection observer, and set about using it with infinite scroll. With some more practising with APIs, so I could load an infinite number of cat photos.

And then, nearly halfway in, I was ready to learnt React (again). I tried it some time ago, but found it hard and decided I needed to learn more JavaScript first. This time it made more sense (and has got easier in the meantime now hooks exist).

After working through a tutorial I started on a project. It was supposed to be for trying out all the flashy things I'd seen with CSS and the intersection observer. And then I discovered that a multi-page website would be easier with React and ended up writing the whole thing with React - and learning a lot of React in the process.

I also re-learnt about unit/integration/e2e testing - I thought I'd understood what to test. I think I understand it now!

Around 40 days later, that site was done. And I got on with the business of completing the projects to get the FreeCodeCamp Front End Libraries certification.

In summary, this 100 days I have learnt:
- Webpack
- HTML details/summary tags
- APIs
- More CSS
- Intersection Observer
- React
- Testing
PWA-first web development recommendations?
Tags: webdev, help, pwa, database
Published: 2021-04-05 09:29:17

- [Syncable database across multiple devices, yet work offline](https://qr.ae/pG80js)
- Not every has to be JavaScript, with Web Assembly? (I prefer Golang, BTW)
- Best JavaScript framework, if needed, for conveniences
- Monetization

I already have a web app, BTW. <https://zhquiz.cc> If possible, I want to get a marketing coach; although I care more about sustainability, rather than profit.

{% github zhquiz/zhquiz no-readme %}

It's Nuxt.js with [@nuxtjs/pwa](https://github.com/nuxt-community/pwa-module), BTW.
Delete node_modules like a Pro
Tags: webdev, node, javascript
Published: 2021-04-05 09:22:32

Usually, while working on multiple projects we complain about the hard drive which is mystically always full.

Whenever we start a new project and run npm install, it downloads a bunch of javascript files in the node_modules folder and we don't care about this after we abandoned the project. 

Even after knowing that we can delete it by right-clicking it.

I usually use the bash command which deletes the directories from the current working directory

```javascript
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
```

But the smartest way to get the job done is to run **npx npkill**

So, installation through npm is simple. Make sure you have installed node and npm and then run

```javascript
npm i -g npkill
```
You can also use it without installing it by running

```javascript
npx npkill
```

It easily finds and removes old and heavy node_modules folders

To know more information about npkill, you can visit the site [here](https://npkill.js.org/)

---

I follow [FireShip](https://www.youtube.com/channel/UCsBjURrPoezykLs9EqgamOA) - a youtube channel where we get high quality code tutorials to help you build & ship your app faster, for a long time. So, I came across this [video](https://www.youtube.com/watch?v=qOSH2pYg6m8) which really helped me. 

---

##**Conclusion**
👏👏 By coming this far I hope you can use this awesome npkill npm package. So, I suggest you give it a try on your project and enjoy it! 

Feel free to share your thoughts and opinions and leave me a comment if you have any problems or questions.


Till then,
**Keep on Hacking, Cheers**
What is better for Linux desktop app development between Python, C, and C++?
Tags: python
Published: 2021-04-05 09:20:10

Hey, Developers! We all know Python is a great language for quickly prototyping, and that it scales beautifully to large code bases. But what's the best choice for desktop application development (Linux, macOS, or Windows)?

I have a preference for Python because it is already installed on the machines I use (and this way I will save some time) but you could be a bit concerned about its performance. On the other hand, C and C++ were kind of standards when it comes to programming for desktops.

Python is faster to [learn](https://pythonspot.com) than C or C++. C/C++ is more oriented for low-level programming on electronics like operating systems or drivers. [Linux](https://github.com/torvalds/linux) itself is written in C.

## Which toolkit?

Once in a while, I see someone wondering whether [PyQt](https://pythonpyqt.com/) or [QT](https://qt.io) is the right framework to use for their desktop application. Should you use Qt or [PyQt](https://pythonbasics.org/pyqt-hello-world/)? The short answer is, it depends! Qt is a C++ framework, so if your application will be written mostly in C and C++, then you can use it. 

If your application will have a Python part, there are frameworks for that too.

![qt toolkit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovs3x0q8uensokiz0a93.png)

On the other side, PyQt is a Python framework. So if your application will be written mostly in Python, then it's probably the right choice for you. But what about everything else?

For me, it's always been easy: I used PyQt because I was writing everything in Python and I didn't want to start messing with C++ just yet. That made my life a bit easier.

Also, PyQt and Qt are available on multiple platforms (Linux, BSD, OS X and Windows).

If you are new to PyQt, this is a great start:
[Create GUI Apps with Python PyQt5](https://gum.co/pysqtsamples)

## Other toolkits?

Another toolkit you can use is GTK or tkinter. 

[GTK](https://www.gtk.org/docs/language-bindings/python/) is the default used on the Gnome desktop, which has it's own set of issues. Gnome while primarily installed on desktop computers, is designed for tablets. It doesn't have a start menu, the file manager can't display images (Windows 95 called, they have new features), no taskbar, no toolbar etc. Sure, you can use GTK without Gnome on i3 or window manager. However, many users prefer a complete desktop experience and KDE/QT provides one.

![gnome desktop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnxqghf9pae50q1x6nx4.png)

[Tkinter](https://python-commandments.org/tkinter-basics/) used to be the default for Python. It's basic and [easy to learn](https://bsdnerds.org/learn-python/), however it may not have all the widgets you need for developing your desktop program and it has an old interface. For example, you cannot build a webbrowser with Tkinter like [PyQt](https://pythonprogramminglanguage.com/webkit-browser/) unless it get's very hackish.
Big challenge, asking for advice
Tags: devops, startup, cloud
Published: 2021-04-05 09:00:30

Hi guys I just got a new job, and that's being the CEO of a company, basically some investor believed in me and now I lead a Huawei Cloud Consulting Partner, apart from focusing on the pain points such as latency, high availability and low-cost to  migrate companies workloads to the cloud I was thinking on giving value through automation, optimization using software tools then came to realize that there's lack of DevOps Engineers here in my region (LATAM) and willing to give a Managed Services to companies about ITC, and do the DevOps culture inception on companies to achieve Digital Transformation, so I can become not only Cloud Services Reseller but also DevOps administrator. What do you think, I'm open to new ideas.
Using Docker with Spatie's Laravel Package development
Tags: laravel, php, docker
Published: 2021-04-05 08:59:20

---
title: Using Docker with Spatie's Laravel Package development
published: true
date: 2021-04-05 08:53:37 UTC
tags: laravel,php,docker
canonical_url: https://adithya.dev/using-docker-for-spatie-laravel-package-development/
---

*Originally published on [adithya.dev](https://adithya.dev/)*

I have been building packages for my private use and came across this problem where I had to build a package and integrate it into a project that's running on Docker.   
  
For local development, I make use of `repositories` in composer.json to achieve this. In Docker, since your host machine and docker images run separately, you cannot include the path as you would, if you ran it on the same machine (without Docker).

Tools used are

- [https://github.com/spatie/package-skeleton-laravel](https://github.com/spatie/package-skeleton-laravel)
- Dockerfile (I'm using [https://github.com/aschmelyun/docker-compose-laravel](https://github.com/aschmelyun/docker-compose-laravel))

```
//composer.json
"require": { 
	"adithya/package-name": "dev-master"
},
"repositories": [
        {
            "type": "path",
            "url": "../package-name"
        }
    ]
```

When I ran `composer install`, I got the following error

> [RuntimeException]  
> The `url` supplied for the path (../package-name) repository does not exist

After a bit of researching, I found the solution. In your `docker-compose.yml`, add the **absolute** path to your package and a mount point under your `volumes` in `composer` image.

```
composer:
    build:
      context: .
      dockerfile: composer.dockerfile
    container_name: composer
    volumes:
      - ./src:/var/www/html
      - /usr/Code/package-name:/package-name
    working_dir: /var/www/html
    depends_on:
      - php
    user: laravel
    networks:
      - laravel
    entrypoint: ['composer']
```


**Similarly, make sure to add the volume to your php container!**

Now on your Project where you want to include the package, change the reference for your URL

```
//composer.json
"require": { 
	"adithya/package-name": "dev-master"
},
"repositories": [
        {
            "type": "path",
            "url": "/package-name"
        }
    ]
```

Docker should automatically mirror the changes in your package to the project so it should be a breeze. If you do choose to use `ADD` in your dockerfile instead of mounting the volumes, your changes won't be automatically reflected since it copies your folder at the build time.

```
ADD . /package-name

```
forEach undefined
Published: 2021-04-05 08:21:08

Hi everyone ! 
 i have problem with my line 96 for each is undefined why ? thank u for you help ! 

let checkout_products = [
	{
    price: 'price_1Ich7JATizJNVlWkkLy01HF7', // l'id du premier produit
    quantity: 1,
  },
	{
    price: 'price_1ISjeTATizJNVlWkVZFFmMSm', // l'id du deuxième produit
    quantity: 1,
  }
	
];

this.tab_product_cart.forEach(function (product) {
	
  checkout_products.push({
    price: currentProduct.PriceId,
    quantity: 1,
  });
});
stripe.redirectToCheckout({
  // on fournit ici la liste des produits dans le panier
  lineItems: checkout_products,
  mode: 'payment',
  // la page de succès
  successUrl: 'https://example.com/success',
  // la page d'erreur
  cancelUrl: 'https://example.com/cancel',
}).then(function (result) {
How to Install Fonts in (Ubuntu) Linux
Tags: howto, linux, ubuntu, fonts
Published: 2021-08-13 11:39:00

---
title: How to Install Fonts in (Ubuntu) Linux
published: true
date: 2021-04-05 07:42:00 UTC
tags: HowTo,Linux,Ubuntu,fonts
canonical_url: https://fossnaija.com/install-fonts-in-ubuntu-linux/?utm_source=rss&utm_medium=rss&utm_campaign=install-fonts-in-ubuntu-linux
---

You will learn an easy way to install fonts in Linux. We’ll be demonstrating it with Ubuntu 20 LTS version. ENJOY!!!



{% youtube uKPTqhNcMPw %}


**Happy Linux’NG!**

The post [How to Install Fonts in (Ubuntu) Linux](https://fossnaija.com/install-fonts-in-ubuntu-linux/) appeared first on [Foss Naija](https://fossnaija.com).
Let's Keep Your Fork Repo The Latest
Tags: git, github
Published: 2021-04-05 06:53:28

### Pre-condition
- you have github account
- you have git on your local machine
- you have a fork repo
- you have cloned the fork repo

In this post, I use https://github.com/memo/eco-nft as the original repo.

My forked repo is https://github.com/koji/eco-nft.git

### set original repo
```zsh
# add remote repo as upstream
$ git remote add upstream https://github.com/original_repo_you_forked

# check info
$ git remote -v
origin	https://github.com/koji/eco-nft.git (fetch)
origin	https://github.com/koji/eco-nft.git (push)
upstream	https://github.com/memo/eco-nft (fetch)
upstream	https://github.com/memo/eco-nft (push)
```

### fetch & merge
```zsh
$ git fetch upstream

# merge upstream into my forked repo's master branch
$ git merge upstream/master
```

### push (to make a forked repo updated)
```zsh
$ git push origin master
```

### remove upstream from remote
If you added a wrong url, you would need to remove it with the following command.

```zsh
$ git remote rm upstream
```
Easy and Simple Pagination in Vue
Tags: vue, tutorial, javascript
Published: 2021-04-05 06:41:18

### How to paginate simply by using vue js?
In this tutorial I will show you how to Add custom Pagination in a vue component.

```
<template>
  <div id="app">
    <table>
      <thead>
        <th>#</th>
        <th>Name</th>
        <th>Age</th>
      </thead>
      <tbody>
        <tr v-for="(item, index) in currentList" :key="index">
          <td>{{ item.index }}</td>
          <td>{{ item.name }}</td>
          <td>{{ item.age }}</td>
        </tr>
      </tbody>
    </table>
    <button v-on:click="previousPage()" v-if="currentPage > 1">previous</button>
    <button v-on:click="nextPage()">Next</button>
  </div>
</template>

<script>
export default {
  created() {
    this.persons.map((n) => {
      this.num++;
      n.index = this.num;
      return n;
    });
    this.makeCurrentList();
  },
  data() {
    return {
      persons: [
        { name: "kapil", age: 22 },
        { name: "pulkit", age: 23 },
        { name: "rajat", age: 24 },
        { name: "raj", age: 25 },
        { name: "ankit", age: 26 },
        { name: "abhay", age: 27 },
        { name: "anmol", age: 28 },
        { name: "ishaan", age: 29 },
        { name: "ayush", age: 30 },
        { name: "rajat", age: 24 },
        { name: "raj", age: 25 },
        { name: "ankit", age: 26 },
        { name: "abhay", age: 27 },
        { name: "anmol", age: 28 },
        { name: "kapil", age: 22 },
        { name: "pulkit", age: 23 },
        { name: "rajat", age: 24 },
        { name: "raj", age: 25 },
        { name: "ankit", age: 26 },
        { name: "abhay", age: 69 },
      ],
      itemPerPage: 5,
      currentPage: 1,
      currentList: [],
      startIndex: null,
      num: 0,
    };
  },
  methods: {
    previousPage() {
      this.currentPage--;
      this.makeCurrentList(this.currentPage);
    },
    nextPage() {
      this.currentPage++;
      this.makeCurrentList(this.currentPage);
    },
    makeCurrentList() {
      this.currentList = [];
      console.log(this.currentPage);
      this.startIndex = this.currentPage * this.itemPerPage - this.itemPerPage;
      this.currentList = this.persons.slice(
        this.startIndex,
        this.currentPage * this.itemPerPage
      );
      console.log("start Index => ", this.startIndex);
      console.log("current Page => ", this.currentPage);
      console.log("Current List => ", this.currentList);
    },
  },
  name: "App",
  components: {},
};
</script>
```
JavaScript Tricks
Tags: javascript, devjournal, programming
Published: 2021-04-05 05:38:46

Hey Guys!

Here are a few JS tricks I learned online, I thought id share a few with you all. 

#Console.table()


When you have an array and you want to display the data, instead of it looking like this,
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anwkwct4mafydlycm04v.png)

It can look cleaner like this,
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdcxhdjlncb1jsv3e5d2.png)

the difference is the first one was used with console.log() and the second was used with console.table().

#Conditionals

Within your code, you're likely going to use and if statement, now of course with this tip you'll want to use it carefully because we always want our code to be readable for other viewers. So in your code if you a simple if statement, you can use what is called a ternary operator.

Example:

    if (tired) {
      sleep();
    }

can be changed to,

    hungry && goToFridge()

or,

    if(age > 5){
      kindergarten()
    }else{
      firstGrade()
    }

transformed to this,

    age > 5 ? kindergarten() : firstGrade()

#Filtering for unique objects

Now we all know how many times we have had to filter out for unique elements, here is a trick using the Set object. "The Set object lets you store unique values of any type, whether primitive values or object references."(MDN, Online Doc)

    const my_array = [1, 7, 2, 2, 3, 1, 4, 6, 5, 7, 8, 9, 1, 2, 4]
    const unique_array = [...new Set(my_array)];
    console.log(unique_array); // [1, 2, 3, 4, 5, 6, 7, 8, 9]



Thank you for enjoying my blog, I will post more tips more in the future if this was helpful. Once again, please let me know if there is anything you would like me to write about.
Code Smell 66 - Shotgun Surgery
Tags: codenewbie, tutorial, oop, webdev
Published: 2021-04-05 04:20:38

*Say it only once*

# Problems

- Bad Responsibilities Assignments
 
- Code Duplication

- Maintainability

- [Single Responsibility](https://en.wikipedia.org/wiki/Single-responsibility_principle) Violation.

- Copy-pasted code.

# Solutions

1. Refactor

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/cb3d9eb1ede5297a16006a1453009867)
```php
<?

final class SocialNetwork {

    function postStatus(string $newStatus) {
        if (!$user->isLogged()) {
            throw new Exception('User is not logged');
        }
        ///...
    }

    function uploadProfilePicture(Picture $newPicture) {
        if (!$user->isLogged()) {
            throw new Exception('User is not logged');
        }
        ///...
    }

    function sendMessage(User $recipient, Message $messageSend) {
        if (!$user->isLogged()) {
            throw new Exception('User is not logged');
        }
        ///...
    }
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/23a8649a28ec56db1d0874c1a32b4fc7)
```php
<?

final class SocialNetwork {

    function postStatus(string $newStatus) {
        $this->assertUserIsLogged();
        ///...
    }

    function uploadProfilePicture(Picture $newPicture) {
        $this->assertUserIsLogged();
        ///...
    }

    function sendMessage(User $recipient, Message $messageSend) {
        $this->assertUserIsLogged();
        ///...
    }

    function assertUserIsLogged() {
        if (!$this->user->isLogged()) {
            throw new Exception('User is not logged');
            //This is just a simplification to show the code smell
            //Operations should be defined as objects with preconditions etc.
        }
    }
}
```

# Detection

Some modern linters can detect repeated patterns (not just repeated code) and also while performing our code reviews we can easily detect this problem and ask for a refactor.

# Tags

- Code Duplication

# Conclusion

Adding a new feature should be straightforward it our model maps 1:1 to real world and our responsibilities are in the correct places. 
We should be alert for small changes spanning in several classes.

# More info

[Wikipedia](https://en.wikipedia.org/wiki/Shotgun_surgery)

[Refactoring.guru](https://refactoring.guru/es/smells/shotgun-surgery)

[Ndepend](https://blog.ndepend.com/shotgun-surgery)

[DZone](https://dzone.com/articles/code-smell-shot-surgery)

# Credits

Photo by <a href="https://unsplash.com/@williamisted">William Isted</a> on <a href="https://unsplash.com/s/photos/shotgun">Unsplash</a>
    
* * *

> Duplication is the primary enemy of a well-designed system.

_Robert Martin_
 
* * *
 
{% post https://dev.to/mcsee/software-engineering-great-quotes-26ci %}

* * *

This article is part of the CodeSmell Series.

{% post https://dev.to/mcsee/how-to-find-the-stinky-parts-of-your-code-1dbc %}