teleren/devto huggingface dataset:
Python + Flask - Part 4 - Remote Database
Tags: python, flask
Published: 2019-10-20 03:05:44

![titulo](https://thepracticaldev.s3.amazonaws.com/i/lnm6ybztq944ikym1s8f.JPG)

This is the fourth and last part of a series about the Flask framework, a common tool used to create web applications with Python.
## Objectives
The part 4 will focus on connecting the web API with a remote database.
The full example is available here: [Python-Flask](https://github.com/lucianopereira86/Python-Flask).

## Topics
- [Remote Database](#remote-database)

### Remote Database

Let's connect with a remote MySQL database now. 
Follow the instructions in this [article](https://dev.to/lucianopereira86/net-core-web-api-part-2-mysql-3bje) or in this [repository](https://github.com/lucianopereira86/NetCore3-MySQL) to create a database and get the connection string. 
If you followed them correctly, you must have a _user_ table in your remote database. Change it by adding a column named _age_. 
Here is an easy script to do it:

```sql
ALTER TABLE user ADD age INT NOT NULL;
```

Now, return to VSCode, add _PyMySQL_ into the _requirements.txt_ and install it by running:

```sh
pip install -r requirements.txt
```

Inside the _db_api.py_, import the _PyMySQL_ package:

```python
import pymysql.cursors
```

Comment the _start_db_ function because it won't be needed anymore:

![flask33](https://thepracticaldev.s3.amazonaws.com/i/hm6y1fr3g5o77zd3qy2d.JPG)

Modify the _execute_ function to receive the MySQL connection by adding the connection string:

![flask34](https://thepracticaldev.s3.amazonaws.com/i/l1r3eicu7j49wo4dwgx6.JPG)

Change the _post_users_ function to receive the inserted id:

![flask35](https://thepracticaldev.s3.amazonaws.com/i/ii03z4nq1hwh50jtg0em.JPG)

Now, run the API again:

```sh
python .\api\db_api.py

```

Make a GET request to the _get_users_ function. The result will be something like this:

![flask38](https://thepracticaldev.s3.amazonaws.com/i/ax1xlpea18b6t2o6pni9.JPG)

Make a POST request to create another user:

![flask39](https://thepracticaldev.s3.amazonaws.com/i/hwa4wzp0agdeeiviu7vx.JPG)

Another GET request and the result will be:

![flask40](https://thepracticaldev.s3.amazonaws.com/i/t23a0s9ywwe0tmgw1aeq.JPG)

Modify the age from your new user with a PUT request:

![flask41](https://thepracticaldev.s3.amazonaws.com/i/lhrbo866hrkzhgw1f2l6.JPG)

Check it out:

![flask42](https://thepracticaldev.s3.amazonaws.com/i/k9k5l68aup8l1ovpav9x.JPG)

Delete another user:

![flask43](https://thepracticaldev.s3.amazonaws.com/i/c8xngfui3cs7hlgd5ln3.JPG)

And... it is gone!

![flask44](https://thepracticaldev.s3.amazonaws.com/i/okygaowyuuc14q4sp703.JPG)

## Conclusion

In this series, you have seen how a web API behaves in a Python environment with Flask framework. 
During our tests, runtime and persistent data were used. 
The local and remote database had similar functions, equal results and were easy to manipulate.
Python + Flask - Part 3 - Local Database
Tags: python, flask
Published: 2019-10-20 02:59:41












![titulo](https://thepracticaldev.s3.amazonaws.com/i/pfftroqy6k915lu968u9.JPG)

This is the third part of a series about the Flask framework, a common tool used to create web applications with Python.
  
## Objectives
The part 3 will focus on connecting the web API with a local database.
The full example is available here: [Python-Flask](https://github.com/lucianopereira86/Python-Flask).

## Topics
- [Local Database](#local-database)

### Local Database

 
Create another Python file inside the _api_ folder called _db_api_ and write this code:

![flask24_0](https://thepracticaldev.s3.amazonaws.com/i/gvwmmvvs6uavspf6495d.JPG)

The functions below must be created as well:

- Creates the database

![flask24](https://thepracticaldev.s3.amazonaws.com/i/ukjdmncwpkk1wtx5h71b.JPG)

- Creates tables

![flask25](https://thepracticaldev.s3.amazonaws.com/i/x37eje8yiaftwre5970d.JPG)

- Executes the operation

![flask27](https://thepracticaldev.s3.amazonaws.com/i/rddg9qwh3ngik9xxmb2i.JPG)

- Starts the database. This function must be called before _app.run()_.

![flask26](https://thepracticaldev.s3.amazonaws.com/i/vodyaghzzfbm1m77jyd0.JPG)

Finally, run the following command:

```sh
python .\api\db_api.py

```

The _test.db_ will be created inside the _api_ folder and will contain the _user_ table:

![flask28](https://thepracticaldev.s3.amazonaws.com/i/qe8d05f3e8oqlxvq0j76.JPG)

Copy and modify the HTTP functions from _api.py_ to _db_api.py_.

- POST

![flask29](https://thepracticaldev.s3.amazonaws.com/i/oekkelgjustlt79dblq5.JPG)

- PUT

![flask30](https://thepracticaldev.s3.amazonaws.com/i/wt4smvdt8umgqun1zfzd.JPG)

- GET

![flask31](https://thepracticaldev.s3.amazonaws.com/i/s4syizo0nukrxmqcyfy0.JPG)

- DELETE

![flask32](https://thepracticaldev.s3.amazonaws.com/i/25n6m2309l34u261xru3.JPG)

Test each one and see the result.
## Next

We will connect our web API with a remote database.
Python + Flask - Part 1 - Web API
Tags: python, flask
Published: 2019-10-20 02:30:01

![titulo](https://thepracticaldev.s3.amazonaws.com/i/5ypemv5n1l7e4vcc2ps8.JPG)

This is the first part of a series about the Flask framework, a common tool used to create web applications with Python.
## Objectives
In this series you will learn how to create a web API in Python, make requests and connect it with local and remote databases.
The part 1 will focus on the virtual environment to install Flask and how to run a web API.
The full example is available here: [Python-Flask](https://github.com/lucianopereira86/Python-Flask).


## Before Start

If you are new to Python, read these articles to get started: [Python for Beginners](https://dev.to/lucianopereira86/python-for-beginners-part-1-hello-world-19ed).

## Topics

- [venv](#venv)
- [API](#api)

### venv

Create a folder for your project, open VSCode and execute the command below to create a virtual environment (venv):

```sh
python -m venv venv
```

Confirm any popup that shows up and run the command below to use the _venv_:

```sh
.\venv\Scripts\Activate.ps1
```

Create a file named 'requirements.txt' containing the word _flask_.

![venv01](https://thepracticaldev.s3.amazonaws.com/i/o1fev1o5jy2j6hqxbq66.JPG)

Install the _flask_ package inside the _venv_ with the following command:

```sh
pip install -r requirements.txt
```

The result will be:

![venv02](https://thepracticaldev.s3.amazonaws.com/i/ekdyo3r80ttzp9kdlfea.JPG)

### API

Create a folder called _api_ with a file called _api.py_. Inside the file, write this code:

![flask01](https://thepracticaldev.s3.amazonaws.com/i/tk1klnhz7btzz8f65buq.JPG)

Run the following command:

```sh
python .\api\api.py

```

The result will be:
![flask02](https://thepracticaldev.s3.amazonaws.com/i/5vqgc5p6bzhx5isb89qi.JPG)

If you follow the URL displayed you will see the web page running:

```
http://127.0.0.1:5000/
```

![flask03](https://thepracticaldev.s3.amazonaws.com/i/9xupyixefgl7iu3rl3ya.JPG)

## Next

We will create the HTTP methods to turn our web application into a web API.
## References

- [Creating Web APIs with Python and Flask](https://programminghistorian.org/en/lessons/creating-apis-with-python-and-flask)
React Router for beginners
Tags: react, reactrouter, reactforbeginners, javascript
Published: 2019-10-20 02:16:41

---
title: React Router for beginners
published: true
description: React Router for beginners
tags: react.js, react-router, react for beginners, javascript
---
Do you want to learn how react router works? This is the one you are looking for.

{% youtube wOY_vAOWBzc %}
Giving That Water Away: On Not Having To Call When You're Addicted To The Shindig
Tags: rhcp, usher, business, professionalism
Published: 2019-10-20 01:07:55

Some people can't stop! They write too much and they forget to read something other than what they've written. These are the people I wish to bind to this text’s context. So, if you’re here, it’s because I summoned you; now keep reading, it’s good for you!

Some people expect you to do a little dance and sometimes you do a little dance; however, Usher would want us to consider that sometimes: _"situations will arise, in your life, when you gotta be smart about it"_. 

Moreover, Usher would encourage you to consider the other side of that coin, which is that just because a little dance is taking place without you, doesn't mean the dancers don't think the world of you! It doesn't mean they're _"addicted to the shindig"_!

If you're ever feeling like you're doing a little dance, or that someone close to you is doing a little dance, you might just want to drink a little water. Well, what are you waiting for? Get your buddy to get you one! Hell, I'll even get one for you! :^)

If you don't want the water, give it away!
Step-by-step procedure to post your Django project on GitHub
Tags: github, beginners, python, django
Published: 2019-10-20 01:03:13

- Open your project folder.

- Create a virtual environment

* Virtual environment isolates our project. Anything we install within the virtual environment does not affect the rest 

of the computer and vice-versa.

* on cmd: vitualenv . (to install virtual environment)

* Activate the virtual environment by running activate.bat files within the scripts folder.

git status git commands 
----------------------------

* git init

This creates a .git folder on our project folder that means git is initialized.

* git status

This shows all the folders that are not added to git.

* git add -all

This adds all the files to git.

* git commit -m "commit message"

This commits all folders to git.

* git log

This shows the log of all commits in our repository. This displays most recent commits first.

- Now we need to push our existing repository. First, we will need to add push our remote origin which is our remote
repository that we created on GitHub. Copy the HTTPs web URL and paste in cmd.

* git remote add origin weburl

- Now, we will need to push our local repository to our remote repository or GitHub account we use.

* git push -u origin master

- In case we get an error 'failed to push some reps to weburl, run below commands

* git pull --rebase origin master

* git push origin master

- Now we can see your project on your GitHub repository.


			             *** THANK YOU ***
Practical DevOps #1: The Big Sell
Tags: devops, agile, culture, leadership
Published: 2019-10-20 00:16:16



As those who know me or have seen me speak at a conference know, I'm a big fan of DevOps practices. I'm also a big fan of automation. After spending a couple of years digging into the topic, practicing it and talking about it with people from all around the world, I thought I'd share some of my own thoughts and experiences on the topic.

This article is the first part of an ongoing series. 

---

## The big sell

If you're at a shop who've been around for a while, have successful software in production and by every meaningful measure is doing great, then you'll probably have quite a hard time convincing anyone of the need to pivot towards DevOps practices. 

That, however, does not mean that you should stop or that your workplace has nothing to win from embracing DevOps practices. It just means that you'll have to take another approach than the blank-sheet-of-paper-startup-unicorns you read about on the internet.

You don't have to make a big sell and convince everyone of the benefits of a DevOps approach. In fact; You shouldn't. You will thank yourself later for not trying.

Start small, in your own team. Choose a couple of practices you think would bring value to your team, experiment and evaluate whether they had the impact you where looking for. 

Sooner or later, word will get around about how your team is improving, and with that; other parts of the organization will want to know how you did it.

So, to summarize:

- Start simple, start small.
- DevOps takes time.
- Don't settle for short-term improvements, focus on the long-term gain.
- Prioritize your experiments by their (potential) velocity increase.
- Define measurable goals before starting your experiment.
- Evaluate and keep doing what works.
- Stop doing, or change, what does not.
- Stay humble.

---

Thank you for reading. 🙏🏼


If you enjoyed this article, click the ❤️ button and subscribe to make sure you won't miss the next part.
Flutter Fatal Exception in Firestore Android
Tags: firestore, flutter, android
Published: 2020-01-07 19:09:20

---
title: Flutter Fatal Exception in Firestore Android
published: true
date: 2019-10-20 00:15:34 UTC
tags: firestore,flutter,android
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/1*mUnZxae7oC5-ov-HWgDFGw.png)

Flutter Fatal Exception in Firestore Android

Yesterday I was facing an unexpected crash in production (_How did this happen_?) to be short, I do not own a physical Android device to test RELEASE builds, in theory I was adding a small, almost insignificant change… but doing some Flutter Clean here, Flutter Package Get over there, Android CLEAN, Android BUILD and that kind of things… SOMETHING IMPORTANT DID ACTUALLY CHANGED.

```
FATAL EXCEPTION: main
Process: com.app.android, PID: 12668
java.lang.RuntimeException: Internal error in Firestore (19.0.0).
 at com.google.firebase.firestore.g.j.a(:379)
 at com.google.firebase.firestore.g.g.run(Unknown Source:2)
 at android.os.Handler.handleCallback(Handler.java:873)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loop(Looper.java:193)
 at android.app.ActivityThread.main(ActivityThread.java:6718)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
```

After digging and digging and trying to figure out what was happening, I realize that disabling useProguard and minifyEnabled I was able to fix that crash… BUT what the hell?? I didn’t change or add any proguard rules or gradle file… so, finally found WHAT was actually causing that crash thanks to my GIT file status… and guess what I’ve found…

```
android.enableR8=true
```

Some how R8 got added AND enabled in my gradle.properties file!. Changing the value to FALSE got my APP running and free of crashes.
Character Counter
Tags: vanillajs, javascript
Published: 2019-10-21 17:11:19

---
title: Character Counter
published: true
date: 2019-10-20 00:00:00 UTC
tags: vanillajs, javascript
canonical_url: 
---

I'm really enjoying [Vanilla JS Academy](https://vanillajsacademy.com/) because the projects are short and sweet but they all seem to have some real world application. So we are learning some important methods along the way but then we have to go off and apply them in an interesting way. The community around this course is also so great so I can only take my hat off to [Chris Ferdinandi](https://gomakethings.com/). Today we had to create a character counter like you might see on some sites under a text box. Possibly applications is indicating that there is a maximum number of characters in a textarea.

```
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Character Count</title>
</head>

<body>
    <h2>Character Count</h2>

    <label for="text">Enter your text below.</label>
    <textarea id="text"></textarea>

    <p>You've written <strong><span id="character-count">0</span> characters</strong>.</p>

    <script src="script.js"></script>
</body>

</html>

```

This is some very basic html and the javascript was also pretty simple to find a solution for. The event was my only catch. I initially was using keyup but after posting the solution on the Slack channel I saw others using `input` as their event. After some checking I found that the mouse copy paste did not trigger the event from happening. So I made this change and I was able to set the counter as I was typing in or doing some form of copy paste.

```
const characterCount = document.querySelector('#character-count');

window.addEventListener(
    "keyup",
    event => {event.target.matches('#text') ? characterCount.textContent = event.target.textLength : 0;},
    false,
);

characterCount.textContent = document.querySelector('#text').textLength;  

```

See it in [action](https://bikingbadger.github.io/vanilla-academy/projects/character-count/)
A Big Picture
Tags: react, ecosystem, bigpicture
Published: 2019-10-22 07:05:49

---
title: A Big Picture
published: true
date: 2019-10-20 00:00:00 UTC
tags: React, Ecosystem, Big Picture
canonical_url: http://metamn.io/react/a-big-picture/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/p3khdq8ktwse393tg3c0.png
---

React and the ecosystem mapped up.

<!--more-->

![The Big Picture](https://thepracticaldev.s3.amazonaws.com/i/p3khdq8ktwse393tg3c0.png)

A higher resolution image and detailed information about the building blocks is available in [Miro](https://miro.com/app/board/o9J_kwFipAA=/).

All resources based upon the chart was drawn are available in [Putting React in context](http://metamn.io/react/putting-react-in-context/)
Discussion: Do you have a mentor?
Tags: discuss, mentoring, career, growth
Published: 2019-10-19 23:54:11

I've been thinking a lot about how mentor/mentee relationships develop, and I have some general questions I'd like to ask the community.

# For those of you who have a mentor:
1. How did you find this person?
2. How did you build this relationship to where they became your mentor?
3. Is this someone you work with?

# For those of you who do not have a mentor:
1. Have you had one in the past?
2. Do you wish you had one?

# General questions
1. What do you look for in a mentor?
Angular 8|9 Chart.js Tutorial with ng2-charts Examples
Tags: angular89, angularmaterial, ng2charts, chartjs
Published: 2020-01-29 17:27:12

---
title: Angular 8|9 Chart.js Tutorial with ng2-charts Examples
published: true
date: 2019-10-19 21:50:57 UTC
tags: Angular 8|9, Angular Material, ng2-charts, Chart.js  
canonical_url: https://www.positronx.io/angular-chart-js-tutorial-with-ng2-charts-examples/
---

**In this Angular 8/9 Chart tutorial, we will learn to implement Chart.js integration to represent data using various charts. We will learn to integrate pie, bar, radar, line, doughnut and bubble charts in an Angular app with the help of the ng2-charts module.**
### What is Chart.js?

Chart.Js is a well-recognized JavaScript library, and It is used to represent the data using the HTML5 canvas. It allows us to build dynamic as well as static charts, and it comes with full animation support for the various charts. It takes data in the JSON form, so it is merely simple to use it with any programming language.

### Introduction to ng2-charts

The **ng2-charts** module is an open-source JavaScript library, and it is exclusively built for Angular 2+ and available via npm. It helps to create eye-catching charts in Angular with the help of Chart.js.

The ng2-charts supports Chart.js and comes with **baseChart** standard directive, and you can build 8 types of charts with it, such as: pie, bar, line, radar, polar area, doughnut, bubble and scatter.


[click here to read more](https://www.positronx.io/angular-chart-js-tutorial-with-ng2-charts-examples/)
How to find motivation 💪
Tags: motivation, productivity, beginners
Published: 2019-10-19 20:58:16

## Introduction

A few weeks ago, I woke up every day and every day I told me: "You should code today you have got a lot of projects to finish, you have to do this" but I didn't find the motivation to code. That wasn't the first time, but I didn't know what to do in order to get back this motivation. So, I decided to look after some "motivation stuff" on dev.to and I decided to write something about it to help other people who have the same problem, and maybe it will help me in the future.


## My personal tips

* Find a community

It might be strange but taking part in a developer community help me through this little period because they inspire me every time they do or share something. Here is a non-curated list of slacks communities: http://blog.honeypot.io/21-slack-channels-for-software-developers/

* Do what you want to do

In fact, I didn't even found a comment on this but that's something I've learned during this period. It seems logical but you don't have to care about others, If you want to do something, go for it.

* Never give up

Once again it seems logical but sometimes you need to read it or you need somebody to tell you this: "Don't give up", if you believe in something just do it, if you don't find something to believe in.

* Find a project

If you don't have any idea of a project, learn something new, something it might be interesting to learn for you, a new technology, a new language or maybe something completely different like a new domain (Machine learning, etc...). If you are searching for a project, the best thing to when you need motivation is to work with other developers. You should maybe take a look at an Open Source project, OSS is always looking for new contributors and it might make you feel useful.

## Comments I found on dev.to

* Be happy about little things

{% devcomment emob %}

{% devcomment em6n %}

* Take a break
 
{% devcomment 2pdm %}

* My favorite

{% devcomment 283d %}

* And the one that worked for me

{% devcomment 4ibj %}
📚 Awesome links from dev.to and around the web #2
Tags: postgres, mysql, design, webdev
Published: 2019-10-19 20:25:45

Hey fellow developers and designers 👋🏽

## ✍🏽 Links you might find interesting
⭐ [What it takes to render a complex app in milliseconds](https://dev.to/ben/what-it-takes-to-render-a-complex-webapp-in-milliseconds) by @ben
⭐ [The ultimate postgres vs mysql blog post](https://dev.to/dmfay/the-ultimate-postgres-vs-mysql-blog-post-1l5f) by @char_bone
⭐ [Using Netlify lambda functions to send emails from a GatsbyJS site](https://dev.to/char_bone/using-netlify-lambda-functions-to-send-emails-from-a-gatsbyjs-site-3pnb) by @char_bone
⭐ [Shape Up, stop running in circles and ship work that matters](https://basecamp.com/shapeup)
⭐ [The $61,392 book launch that made me quit my job](https://adamwathan.me/the-book-launch-that-let-me-quit-my-job/)


---
## ✨ Random delights from around the world

⭐ [Krita](https://krita.org) - A professional FREE and open source painting program. It is made by artists that want to see affordable art tools for everyone.
⭐ [On writing software well youtube](https://www.youtube.com/watch?v=wXaC0YvDgIo&list=PL9wALaIpe0Py6E_oHCgTrD6FvFETwJLlx) - A playlist by David Heinemeier Hansson (creator of ruby on rails) on some patterns he uses to write basecamp
⭐ [Steve Schoger's design tips moment on twitter](https://twitter.com/i/moments/994601867987619840) - A collection of byte sized practical design tips that you can start applying in your applications now
⭐ [Draw simple things channel on youtube](https://www.youtube.com/channel/UCtnxTjHsbYVLrsKHbaqZbYQ) - A youtube channel that shows you how to draw simple but beatiful illustrations with inkscape, an open source vector graphics software

---
## 🙈 Shameless Plugs

[Follow me on twitter](https://twitter.com/intent/follow?screen_name=kudapara), I post mostly about web development and design tips and tricks like 
{% twitter 1185217823322320896 %}

---

> The only way to learn a new programming language is by writing programs in it.
- Dennis Ritchie

---

Cheers 🥂
[@kudapara](https://twitter.com/kudapara)