teleren/devto huggingface dataset:
✨ Shtab: Provide Autocomplete for your Python App
Tags: showdev, python, productivity, tutorial
Published: 2020-07-28 01:23:44

---
title: ✨ Shtab: Provide Autocomplete for your Python App
published: true
description: Shtab - a magical autocomplete script generator for Python applications! It works with argparse, docopt, and argopt to produce scripts for bash and zsh. We implemented and have been using this for DVC.org for a while and realized it could be valuable to the entire ecosystem of Python CLI applications.
tags: showdev,python,productivity,tutorial
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/w9lrx06fd681vnlcwlpc.jpg
---

I believe most folks have written a bash or Python app/tool that runs from the terminal command line to do `some useful stuff`. These programs usually accept some parameters and options. And it's really cool when you can press the `TAB` key and get the list of options the command expects:

```console
$ git ch<TAB>
...
checkout         -- checkout branch or paths to working tree
checkout-index   -- copy files from index to working directory
```

> 🦾 It seems to be a minor thing but it boosts your productivity significantly! Enough for a search query `productivity terminal autocomplete` to generate almost a million results.

### So, how can you do the same magic for your Python app?

The simplest answer is [Shtab](https://github.com/iterative/shtab) - a Python library that can analyze your code and generate necessary files for `bash` or `zsh` shell to give your tools the same powerful functionality💥 .

This tool was created by [Casper](https://github.com/casperdcl) to automate the maintenance of the [DVC](https://dvc.org) project:

> 😱 _Every time a new feature is added, maintainers and contributors have to update tab completion scripts for multiple supported shells. At best, it's a pain, and at worst, error-prone._

### Okay, enough talk, let's see it in action 🎥.

For Python CLI application using `argparse`, `docopt`, or `argopt` simply hand your parser object to `shtab` (either via the CLI or the Python API), and a tab completion script will be generated for your preferred shell. It's as easy as:

```console
$ shtab --shell=bash myprogram.main.parser
```
or in Python:

```python
import shtab
print(shtab.complete(parser, shell="bash"))
```

That's how [Git for Data's](https://dvc.org/doc/install/completion) in terminal looks like when completion is installed:

```console
% dvc <TAB>
Completing dvc commands
add         -- Track data files or directories with DVC.
cache       -- Manage cache settings.
checkout    -- Checkout data files from cache.
commit      -- Save changed data to cache and update DVC-files.
completion  -- Prints out shell tab completion scripts.
At Top: Hit TAB for more, or the character to insert
```

---------

I hope you'll find it useful and this lib will save you some time! As usual, give the project a ⭐️ to thank the [author](https://github.com/casperdcl) and welcome to the issue tracker or comments 👇 if you have any questions.
Python Zero to Hero - Ep.16 - Python async
Tags: python, async, tutorial, introduction
Published: 2020-07-28 00:21:35

---
title: Python Zero to Hero - Ep.16 - Python async
published: true
description: Today we continue our story from generators to async. Introducing both the coroutine in asyncio (introduced in Python 3.4) and awaitable async function (introduced in Python 3.5).
tags: python, async, tutorial, introduction
---
*Sorry for the video quality, lot's of frames were dropped during the streaming due to my bad internet connection*

Today we continue our story from generators to async. Introducing both the coroutine in asyncio (introduced in Python 3.4) and awaitable async function (introduced in Python 3.5). If you have any questions or any suggestions about which Python topics to cover, please leave your comment at my [Twitch channel](https://www.twitch.tv/cheukting_ho)

You can get the slide deck [here](https://slides.com/cheukting_ho) and the example code and homework form [GitHub here](https://github.com/Cheukting/python02hero). Ask questions at my [Twitch channel](https://www.twitch.tv/cheukting_ho)
Frustrated by Formik? Here's a simpler way to do forms in React
Tags: react, webdev
Published: 2020-07-28 00:17:32

---
title: Frustrated by Formik? Here's a simpler way to do forms in React
published: true
description: Do you find yourself struggling for hours to solve problems with Formik? I've started using a different library that's much simpler.
tags: ['react','webdev']
canonical_url: https://maxrozen.com/2020/07/23/frustrated-formik-simpler-react-forms/
//cover_image: https://direct_url_to_image.jpg
---


Is this you?

> I've tried so many different things I've found online


> Holy crap it works now, such a small problem I've lost hours to :(


> All I want to do is a simple thing, this is all so unnecessarily complex

Try using [react-hook-form](https://react-hook-form.com/).

React-hook-form is different, because it (mostly) keeps its state in the DOM (like classic HTML form elements).

Here's an example of a single field form in react-hook form (taken from their docs):

```js
import React from 'react';
import { useForm } from 'react-hook-form';

const Example = () => {
  const { handleSubmit, register, errors } = useForm();
  const onSubmit = (values) => console.log(values);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        name="email"
        ref={register({
          required: 'Required',
          pattern: {
            value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
            message: 'invalid email address',
          },
        })}
      />
      {errors.email && errors.email.message}

      <input
        name="username"
        ref={register({
          validate: (value) => value !== 'admin' || 'Nice try!',
        })}
      />
      {errors.username && errors.username.message}

      <button type="submit">Submit</button>
    </form>
  );
};
```

Compare that to your existing form code. I don't know about you, but my React forms with Formik would have twice as many lines of code to achieve the same thing.

You'll notice that it's using `ref`, rather than tracking state within the library. Since moving to react-hook-form, I no longer have to worry about state not syncing correctly in huge forms.

Everything just works as expected, and my code is much simpler too.


## Shameless plug

If you'd like more tips on how to improve your frontend, you can [follow me on Twitter](https://twitter.com/RozenMD) or [subscribe to my newsletter](https://maxrozen.com/newsletter/) as I regularly post articles there.
Regular Expressions in JavaScript
Published: 2020-07-28 00:15:34

In JavaScript there are two ways to create regular expressions. 

In the first way, one can write a pattern of letters, numbers or symbols enclosed in forward slash(/) characters, like so:

`let regex1 = /xyz123/;`

When using this first method of constructing regular expressions, certain special characters, like a question mark(?), asterisk/star(*), dollar sign($), vertical pipe symbol (|), period/dot (.), opening or closing parenthesis, and certain other special characters, need to have a back slash ( \ ) before their character in order be included in the pattern that the regular expression is searching for, as in the following cases:

`let regex1question = /xyz123\?/;`

`let regex1pipe = /xyz123\|/;`

`let regex1money = /xyz123\$/;`

In the second method of constructing regular expressions, one can use the *RegExp constructor*:

`new RegExp()` 

With the RegExp constructor, one encloses the pattern of letters, numbers or symbols in quotation marks, like a string, within parentheses:

`let regex2 = new RegExp("xyz123");`

`let regex2money = new RegExp("xyz123$")`

A regular expression object in JavaScript has methods that can be used on it. For example, the method *test* returns a Boolean which indicates whether the string passed as an argument in the test method matches the pattern of the regular expression. For example:

`console.log(/123xyz/.test("123xyz456"));`

will return *true* since the pattern "123xyz" is contained in the string "123xyz456". 

On the other hand the following:

`console.log(/123xyz/.test("123zzz456"));`

will return *false*, since the pattern "123xyz" is not contained in the string "123zzz456". 

However, if we want to test whether or not a string contains any of the characters in a pattern, we can put the characters in regular expression between square brackets, as in the following:

`console.log(/[123xyz]/.test("zzz"));`

This will return *true*, since the string "zzz" does contain the character "z" from the pattern "123xyz".

We can also use certain shortcuts to indicate if we are searching for a certain type of character. For example, 

`\d` indicates any character that is a digit between 0 and 9 (inclusive).

`\w` indicates any alphanumeric character

`\W` indicates any non-alphanumeric character

`\D` indicates any number that is not a digit


Further reading:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp
How to convert a multidimensional array into a single array
Tags: javascript
Published: 2020-07-28 00:00:00

---
  title: How to convert a multidimensional array into a single array
  published: true
  tags: JavaScript
  date: Tue Jul 28 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/convert-multidimentional-array-into-single-array
  cover_image: https://melvingeorge.me/_next/static/images/main-3bf19ed0b2c4d5caeb299958c8b3cd39.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/convert-multidimentional-array-into-single-array)
  
To convert a multidimensional or nested array into a single array or flatten the array we can use the `flat()` method available in the array.

Suppose you have a nested array like this,

```javascript
// nested array
let arr = ["John Doe", ["Lily Rose", 23]];
```

Let's convert this array into a single array using the `flat()` method available in the array.

```javascript
// nested array
let arr = ["John Doe", ["Lily Rose", 23]];

// convert nested array into single array
let convertedArr = arr.flat();

console.log(convertedArr); // ["John Doe", "Lily Rose", 23]
```

By default, `arr.flat()` method only converts nested arrays up to 1 level deep.

What if we have nested arrays which are 3 levels deep like this,

```javascript
// nested array with 3 levels
let arr = ["John Doe", ["Lily Rose", ["salary", ["baseSalary", 23000]]]];
```

For this to convert into a single array we can pass the depth to which we want to convert the array as an argument to the `flat()` method.

```javascript
// nested array with 3 levels
let arr = ["John Doe", ["Lily Rose", ["salary", ["baseSalary", 23000]]]];

// converted nested array into single array which is 3 levels deep
let convertedArr = arr.flat(3);

console.log(convertedArr); // ["John Doe", "Lily Rose", "salary", "baseSalary", 23000]
```

### Feel free to share if you found this useful 😃.

---
What do you want to learn?
Tags: html, css, javascript, react
Published: 2020-07-27 23:53:01

I've been programming for over 20 years and I want to create a course for you!

If you have a few minutes, please fill out my TypeForm so I can know what topics you'd like to learn.

Thank you and have a wonderful day!

https://aaron052812.typeform.com/to/TpCUarCX
Day 182: Time's Up
Tags: hiphop, code, coding, lifelongdev
Published: 2020-07-27 23:09:57

_liner notes_:
- Saturday : Before the radio show, I finished gluing the magnets to the window coverings. The glue bottle I bought that had a brush make it so much easier to apply the glue with the magnets being placed vertically. So many magnets! Then it was time to do the radio show. Had a really good time as usual. This week, we did stories not having to do with the insanity happening in the world. The recording of this week's show is at https://kNOwBETTERHIPHOP.com

![Radio show episode image of a book with OUR show fliers placed on the cover with the words July 25th 2020, Kraken Aliens](https://dev-to-uploads.s3.amazonaws.com/i/5oivlt91ijg4n4yo8fei.jpg)

- Sunday : Finished up with the window coverings. I used spray adhesive to glue a black table cloth to one side of the covering. I ordered some strong black tape to help reinforce the edges where the cloth attaches to the covering. Mowed my lawn. Watched some anime. Bought yet another domain name! haha. It's for a side project that similar to the one I'm working on, with a different audience and some other features. So I'll be working on both at the same time.

- Professional : Woke up pretty sore. haha I guess I used muscles to make the window coverings that I haven't used in a while. haha Had a good meeting with my manager. Going to help out with a meetup tomorrow and they wanted a demo, so I suggested one I made a while ago and everyone liked it, so we'll go with that. Worked on a solution for a bug in a Web Component, but may have hit a wall because the element I'm using has set a restriction on it to be read only in TypeScript. Oh TypeScript. I'll have to figure something out....Tomorrow.

- Personal : I put up the window coverings in my van. They went up pretty easily and securely. Can't see inside at all. Going to see if they stay up overnight.

![An island in the middle of a blue green ocean in Zaya Nurai Island, Abu Dhabi](https://dev-to-uploads.s3.amazonaws.com/i/dbjd4s1qd7t9o32y7xd6.png)

Going to work on the meetup live stream project's dashboard tonight and maybe sketch some designs for the new side project. I really need to start ordering the framework for the van. It's almost time's up before I move in permanently. If the window coverings are still up tomorrow, I'll start moving stuff into there. Probably end up working on the framework while I'm living in the van. We'll see.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube 6ZFh0Q-wVyU %}
My First Open Source Contribution
Tags: opensource, beginners
Published: 2020-07-27 23:08:12

---
title: My First Open Source Contribution
published: true
description: 
tags: opensource, beginners
//cover_image: https://direct_url_to_image.jpg
---

For a long time, I thought about contributing to Open Source, but I felt I did not know where to start. As a software engineer, I wanted to learn and build a portfolio of work through contributing to Open Source.

Back in December 2017, I got the word of [24 Pull Requests](https://24pullrequests.com/), an initiative with a Christmas feel to it, where you can contribute to open source projects during the month of December.

![24 Pull Requests website image)](https://dev-to-uploads.s3.amazonaws.com/i/dzl62e5cntsrn5ukqfyz.png)

When I found about this, I decided to look into it and see if I could contribute. To start I thought about contributing with a “low hanging fruit” sort of issue. Even though my main interest was in coding, I wanted to start with the documentation type of contribution. So I looked into projects made of markdown files and found [fvcproductions/hire-me](https://github.com/fvcproductions/hire-me/pull/9) which is about providing resources and advice for people looking for jobs, such as interview tips, job boards, and other types of resources.

So after looking into this project I noticed that there was a job board that I knew that was not there so I saw an opportunity to contribute.

Next, I read the [contribution guidelines which were very simple](https://github.com/fvcproductions/hire-me#contributing). The steps provided in this project guidelines were: 1. fork repository; 2. read contribution guidelines; 3. add my name to the credits section; 4. Open Pull Request; 5. Get pull request approved 🎉

So after I forked the repository, I added my changes and my name to the credits in the README, and submitted a Pull Request. Here’s [my pull request #9](https://github.com/fvcproductions/hire-me/pull/9)!

Some days after the maintainer of the repository merged my PR and thanked me for my contribution! I was so happy that I finally managed to do my first open source contribution after so much time delaying it. After this moment, I knew the basics of an open source workflow and I could apply to other contributions.

Have you ever contributed to Open Source? If not, I hope this inspires you to get started :)
6 Learned Lessons From My First Year Working From Home & Being a Freelancer. 
Tags: freelancing, productivity, tips
Published: 2020-07-27 22:19:22

---
title: 6 Learned Lessons From My First Year Working From Home & Being a Freelancer. 
published: true
description: Tips for developers who work from home 
tags: freelancing, productivity, tips
---

We have an Arabic saying that says: "An eyewitness is better than hearsay". 
During the past year, I was working from home as a freelancer, at first, I was so excited about the whole thing, especially that I was done with my previous work in a company, I hated 5-9 so much. But with the time, I figured that working from home has it's own challenges too, and they are not easy to deal with, one can not think about these challenges unless actually trying to work from home. 
So here are some really important aspects that you should put into consideration when working from home or as a freelancer. Even if not, because currently due to the Covid-19, a lot of people shifted to work from home. 

##1 Time management skills are essential 
In my opinion, this is the most important one, If you didn't pay attention to it, you will suffer greatly. 
Suddenly you will find yourself working 24/7. Even when you don't want to, and be strict with your self when the work time is over, then it's over, no excuses, you need these breaks so you won't lose your balance.  

##2 Focus
One technology at a time, one tool at a time... Etc. 
When the is no obvious boundaries like the ones that are required by the company you are working on, you can get tempted and distracted easily by all the technologies that come in your way! Then stretched too thin, so end result will not be that good. 

##3 Make reasonable goals
Setting small consistent goals is a must because it will make you motivated each time you accomplish a task or take a small step. Setting one big goal might be so frightening at the beginning and not so digestible. 
Remember that our industry is changing rapidly, it's hard to even the very experienced developers to know it all. 
So just relax, and set them small goals at first.

##4 Celebrate the small wins and treat your self very well.
While working in a company, a salary raise, a promotion, a nice word from your boss, all are nice acts that will motivate you to provide more. But when you are a freelancer you have to do all this by your self; will  We are human beings, we need to reward our selves always to keep us moving forward and motivated, don't underestimate the power of rewarding yourself. Be kind to it. 

##5 Change your work environment as much as you can
Working from home will make you mess the chance of communicating with people in the work environment, so change your routine often so you don't get bored. 
Even though am more of an introvert, but staying at home for this amount of time is too much,  

##6 Have some physical outside activities
Coding is a mind activity, exhausting your brain and setting in front of the computer for long hours is bad for your health. Keep moving, balance the mind activeness with the body activeness.
Element.classList.toggle()
Tags: javascript, codenewbie
Published: 2020-07-27 22:08:40

Here's a quick one! To add or remove a single class on an element you can use <code>element.classList.add()</code> and <code>element.classList.remove()</code>:

```js
// Add class
document.body.classList.add('overlay');

// Remove class
document.body.classList.remove('scroll);
```

But did you know <code>classList</code> also includes a toggle method?
```js
// Toggle class
document.body.classList.toggle('overlay');
```

This works similar to jQuery's <code>toggle()</code> method where it's adds the supplied class if not present, otherwise it removes it. It's just one more tool to know about to help you keep your code clean! 🔨

----------
Check out more #JSBits at my blog, [jsbits-yo.com](http://jsbits-yo.com/). Or follow me on [Twitter](https://twitter.com/JS_Bits_Bill)!
How do you backup your projects?
Tags: webdev, discuss, security
Published: 2020-07-27 21:13:39

---
title: How do you backup your projects?
published: true
description: 
tags: webdev, discuss, security
cover_image: https://dedicatedhostingservernoida.files.wordpress.com/2018/01/backup-service.jpeg
---
Having a well-thought-out backup strategy can help you to avoid the crushing feeling that comes with finding out that all your projects are gone.

There are lots of ways to back up your data from personal SSDs and flash drives to repository hosting services like [GitHub](github.com), [GitLab](gitlab.com) and [BitBucket](bitbucket.org) to various cloud storages like [Dropbox](dropbox.com), [Google Drive](https://www.google.com/drive/) and [OneDrive](onedrive.com).

What methods have you tried and what worked best for you?
5 TIPS FOR A DEVELOPER
Tags: webdev, tutorial, webdesign
Published: 2020-07-27 21:29:36

As a developer/programmer, this are one of the best tip you can follow..

1. Focus on a thing As you can decide from the title, that this dude is trying to tell me to focus on one language, Am not what i meant is that you can learn as many languages , but companies will only ask you for one. Meaning no matter how many programming languages you know, focus on one

2. Develop(Practice) As it is well said, practice makes perfect.. imagine learning a new thing today and suddenly forgets tomorrow. WHY?, because you didn't practice what you learnt. so repetition is one of the best way to learn a lot

3. Build Stuffs(Projects) So alright sure, you can code and you remember your codes because you practice a lot, that amazing(to you). WHY? even tho you can code all in this world, without a project no one will believe you, they will take you for granted... so a developer without a project is more like a memer

4. Refactor your codes It is highly recommended to refactor your code: it is a technique to restructure a source code, altering its internal structure without changing its external behavior. Because as a developer we spend 80% reading code and 20% writing it, and if we have a good code we save a lot of time. Other thing is that often, we work with other people, and obviously is a good idea always write readable code.

5. Learn from experience Yes, you are a developer, you build amazing projects but you keep repeating the sane error, aren't you learning from your experience? i don't think so. Yh i don't, why? you took road A in the first phase and didn't work you switched , then when you need to do something like that you took the road A again, doesn't that sounds weird???? it does, learn as you code.

Bonus: Meet People Meeting new people is a great idea, because we establish a connection by winning contacts that can benefit us in future projects or jobs. It is also a good idea to talk with other developers to learn, also participate in meetings, presenter in a conference / talk and other things.

Thanks, hope you like it.