Generate and Verify Your Commits With GPG in GitHub

Why should you do it? “Using GPG, you can sign and verify tags and commits. With GPG keys, tags or commits that you’ve authored on GitHub are verified and other people can trust that the changes you’ve made really were made by you.” About GPG | Github Signing our commits is a great way to verify your commits and let your collaborators know that they can trust that you committed those changes in your project....

August 6, 2018 · 5 min · Franccesco Orozco

Change Flask Root Folder for Templates and Static Files

Today I was facing a problem, I didn’t know how to change Flask root directory. Flask by default look for templates and static files under the root directory (/), how can we change that? Changing the root path Here’s my directory structure: . ├── api_files │ ├── static │ │ └── style.css │ └── templates │ └── index.html ├── api.py ├── Pipfile └── Pipfile.lock 3 directories, 5 files I want Flask to be able to process the folders static and templates inside the api_files folder, my main Flask app is api....

May 12, 2018 · 1 min · Franccesco Orozco

Deploy a Flask Project to Heroku

I was suddenly in the need of deploying a very basic Flask API to the cloud, so it can be available to the public. The thing is, Flask is not made for a production and scalable environment, but if you only need to deploy a very basic web server to Heroku then this guide is for you. Initialize a repository First of all we will need to set up a virtual enviroment with Pipenv, a Flask app, and initialize a repository....

May 10, 2018 · 3 min · Franccesco Orozco

Importing Variables from a Website

Before we start: A short disclaimer Don’t do this. Don’t go there importing random code you found on the internet into your code because that can be dangerous and code would be injected into your machine or a client’s machine and you don’t want that. Remember to always have your code and modules in a version control system and that you have complete knowledge of what you’re loading. Today I was talking with some of the guys in a Discord server about python, called Python Discord (which I definitely recommend you to check out!...

April 17, 2018 · 5 min · Franccesco Orozco

Create Multiple Directories With Makedirs in Python

You don’t need a bunch of if’s and else if’s to create an array of directories in python, just the good ol’ makedirs. Create an array of directories To create an array of directories you must import the package os and import the method makedirs >>> from os import makedirs >>> makedirs('1/2/3/4/5') You’ll see now that your directories are created correctly, let’s run the command tree outside of python to see if they’re were actually created....

April 17, 2018 · 2 min · Franccesco Orozco

How to Handle a Deque in Python

Deques are a great way to handle memory efficient appends to a list-like object, it is a special module that allows you to handle list items in a more appropriate way. Create a deque To create a list simply import the deque module from collections library and call deque(_items_) on a variable. >>> from collections import deque >>> dq = deque('123') >>> dq deque(['1', '2', '3']) >>> type(dq) <class 'collections.deque'> Or if you wish to create an empty deque....

April 14, 2018 · 3 min · Franccesco Orozco

Create a Basic API With Flask

What is Flask? Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. Flask is a microframework for Python that you can use to quickly create API’s and websites. It’s a great and easy to use platform, let’s create a simple API, but first we will go through the basics. Flask Installation We’re going to install Flask in our virtual environment to later import it into our code....

April 7, 2018 · 4 min · Franccesco Orozco

Create and Object With Namedtuple

Namedtuples are a subclass of typename which allow us to create objects (or classes) with tuple-like attributes, it’s easy to create a class with immutable attributes with this library. Creating an object To create a namedtuple we only need the name of the class first and then the attribute list. >>> from collections import namedtuple >>> Person = namedtuple('Person', 'name job_position sex married') >>> john = Person('john', 'developer', 'male', False) >>> john Person(name='john', job_position='developer', sex='male', married=False) Be aware that you can pass an argument list as a string ('att1 att2'), as an actual list (['att1', 'att2']) or a string with comma separated values ('att1, att2')....

April 7, 2018 · 2 min · Franccesco Orozco

Return a List of Files and Folders With Glob in Python

There’s a great library added in Python 3.5 that lets you return a list of filenames and folders called glob, here’s how to use it. Return files and folders in current folder. >>> glob('**') ['scaffolds', 'node_modules', 'yarn.lock', '_config.yml', 'source', 'db.json', 'themes', 'package.json', 'package-lock.json'] Return files and folders recursively >>> glob('**', recursive=True) ['scaffolds', 'scaffolds/post.md', 'scaffolds/page.md', 'scaffolds/draft.md', 'node_modules', '...'] Return only specific type of files recursively >>> glob('*.json', recursive=True) ['db.json', 'package.json', 'package-lock.json'] non-recursively >>> glob('**/*....

March 29, 2018 · 1 min · Franccesco Orozco

Unit Testing Basics With Python

I encourage developers to see the value of unit testing; I urge them to get into the habit of writing structured tests alongside their code. — CodingHorror I was reading about Unit Testing and found a blog entry in CodingHorror called I Pity The Fool Who Doesn’t Write Unit Tests, and guess what, he’s right. Sadly, I’ve encountered a lot of people who doesn’t write tests for their code, and have a CI System (Travis, Jenkins, Gitlab, etc....

March 27, 2018 · 6 min · Franccesco Orozco