Archive

Archive for January, 2019

Developing RESTful APIs with Python and Flask

January 30, 2019 Leave a comment

TL;DR: Throughout this article, we are going to use Flask and Python to develop a RESTful API. We will start by creating an endpoint that returns static data (dictionaries). After, we are going to create a class with two specializations and a few endpoints to insert and retrieve instances of these classes. Finally, will take a look on how to run the API on a Docker container. The final code developed throughout this article can be found in this GitHub repository. I hope you enjoy!

https://auth0.com/blog/developing-restful-apis-with-python-and-flask/

Categories: Interesting

Reading environment variables from a file into a Makefile

January 30, 2019 Leave a comment

Problem:
You have a bunch of environment variables that are explicitly set at the beginning of a Makefile. These variables are then used in various recipes in the Makefile. The issue was that when a developer runs the Makefile, these environment variables overwrite their local settings.

Solution:
One option is to move the environment variables out of the Makefile and use include to add them back. So the developer can use whatever values they have in their current setup as long as the names are the same.

# Makefile

foo=FOO1
bar=BAR1
baz=BAZ1

export foo
export bar
export baz

.PHONY:  target1 target2 target3

target1:
    @echo $(foo)

target2:
    @echo $(bar)

target3:
    @echo $(baz)

After splitting it up.

# .env file
foo=FOO1
bar=BAR1
baz=BAZ1

export foo
export bar
export baz
# Makefile
include .env

.PHONY:  target1 target2 target3

target1:
    @echo $(foo)

target2:
    @echo $(bar)

target3:
    @echo $(baz)

The problem with this approach is that the .env file needs to exist everywhere it will run. If you have some CI/CD setup that may not be the case. Instead have the Makefile as below and have the ENV vars set up the usual way you would in your CI/CD setup. On the local machine one can simply run $ source .env before running $ make to get things to work.

# Makefile
.PHONY:  target1 target2 target3

target1:
    @echo $(foo)

target2:
    @echo $(bar)

target3:
    @echo $(baz)

Source:
https://stackoverflow.com/questions/39005789/reading-makefile-variables-from-bash-script

Categories: bash Tags:

How I Built A Python Web Framework And Became An Open Source Maintainer

January 22, 2019 Leave a comment

Inspirational thoughts and tips on starting and managing an open source project, based on my experience building Bocadillo, an asynchronous Python web framework.

https://blog.florimondmanca.com/how-i-built-a-web-framework-and-became-an-open-source-maintainer

Source:
https://www.pythonweekly.com/

Categories: Interesting

10 reasons why Software Development projects fail

January 18, 2019 Leave a comment

View at Medium.com

1. Poorly defined (or, god willing, undefined!) outcome.
2. Solving the wrong problem.
3. Not enough communication.
4. No plan or timeline.
5. Lack of accountability.
6. Moving the goalposts too often.
7. Inadequate documentation and tracking.
8. Badly defined system requirements.
9. Poor preparation.
10. Unrealistic expectations.

Categories: Interesting

Sane GitHub Labels

January 15, 2019 Leave a comment

TLDR; the default GitHub labels kinda suck; use a sane labelling scheme instead; and use git-labelmaker to simplify GitHub label editing.

https://medium.com/@dave_lunny/sane-github-labels-c5d2e6004b63

Categories: Interesting

GNU Makefile setting env variables

January 12, 2019 Leave a comment

Problem:
Exporting env variables in Makefiles. The issue was that the environment variables were not visible across different targets. I needed the same env vars to be seen in both target1 and target2 below.

Solution:
Export the variables outside the target, eg at the top of the file.

VALUE1="myvalue1"
VALUE2="myvalue2"

export VALUE1
export VALUE2

target1:
    echo $VALUE1

target2:
    echo $VALUE2

Source:
https://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make
https://www.linuxquestions.org/questions/programming-9/exporting-makefile-variables-to-%24-shell-environment-807422/

Categories: bash, Interesting Tags: ,

DevTernity 2017: Ian Cooper – TDD, Where Did It All Go Wrong

January 9, 2019 Leave a comment

Since Kent Beck wrote the book on TDD in 2002 a lot of words have been dedicated to the subject. But many of them propagated misunderstandings of Kent’s original rules so that TDD practice bears little resemblance to Kent’s original ideas. Key misunderstandings around what do I test, what is a unit test, and what is the ‘public interface’ have led to test suites that are brittle, hard to read, and do not support easy refactoring. In this talk, we re-discover Kent’s original proposition, discover where key misunderstandings occurred and look at a better approach to TDD that supports software development instead of impeding it. Be prepared from some sacred cows to be slaughtered and fewer but better tests to be written.

Categories: Interesting Tags: ,