Archive

Author Archive

Using Docker for Flask Application Development

March 2, 2019 Leave a comment

Introduction

I’ve been using Docker for my staging and production environments, but I’ve recently figured out how to make Docker work for my development environment as well.

When I work on my personal web applications, I have three environments:

* Production – the actual application that serves the users
* Staging – a replica of the production environment on my laptop
* Development – the environment where I write source code, unit/integration test, debug, integrate, etc.

While having a development environment that is significantly different (ie. not using Docker) from the staging/production environments is not an issue, I’ve really enjoyed the switch to using Docker for development.

The key aspects that were important to me when deciding to switch to Docker for my development environment were:

* Utilize the Flask development server instead of a production web server (Gunicorn)
* Allow easy access to my database (Postgres)
* Maintain my unit/integration testing capability

This blog post shows how to configure Docker and Docker Compose for creating a development environment that you can easily use on a day-to-day basis for developing a Flask application.

For reference, my Flask project that is the basis for this blog post can be found on GitLab.

https://www.patricksoftwareblog.com/using-docker-for-flask-application-development-not-just-production/

Advertisements
Categories: Interesting

Secure Docker in Production

March 1, 2019 Leave a comment

via Secure Docker in Production

Categories: Interesting

Speed up Development with Docker Compose

March 1, 2019 Leave a comment
Categories: Interesting

Mastering Markdown

February 27, 2019 Leave a comment

What is Markdown?

Markdown is a way to style text on the web. You control the display of the document; formatting words as bold or italic, adding images, and creating lists are just a few of the things we can do with Markdown. Mostly, Markdown is just regular text with a few non-alphabetic characters thrown in, like # or *.

https://guides.github.com/features/mastering-markdown/

Categories: git

Naming Branches

February 26, 2019 Leave a comment

Problem:
I was wondering if there is a convention for naming git branches. Though this really depends on what your organization has, what do you follow when there are no standards?

Solution:
After a quick google I opted to go for:

* feat-short-name
* test-short-name
* fix-short-name
* bug-short-name
* chore-short-name

When naming branches. Then still have

* develop for most of the work and
* master for releases.

Source:
https://github.com/agis/git-style-guide
https://stackoverflow.com/questions/273695/what-are-some-examples-of-commonly-used-practices-for-naming-git-branches

Categories: git Tags: ,

How to use `git mergetool` to resolve conflicts

February 18, 2019 Leave a comment

https://gist.github.com/karenyyng/f19ff75c60f18b4b8149

Have the following in .gitconfig

[merge]                                                                                                                           
    tool = vimdiff  
Categories: git Tags: ,

Change the last line in a file

February 12, 2019 Leave a comment

Problem:
I needed to remove a comma from the last line of a file.

Solution:
Learnt that I can specify the last line with sed.

# File with commas
$ less minerals.csv
"copper",
"bronze",
"gold",
"platinum",
$ sed '$ s/,//' minerals.csv
$ less minerals.csv
"copper",
"bronze",
"gold",
"platinum"

Addresses

Sed commands can be given with no addresses, in which case the command will be executed for all input lines; with one address, in which case the command will only be executed for input lines which match that address; or with two addresses, in which case the command will be executed for all input lines which match the inclusive range of lines starting from the first address and continuing to the second address. Three things to note about address ranges: the syntax is addr1,addr2 (i.e., the addresses are separated by a comma); the line which addr1 matched will always be accepted, even if addr2 selects an earlier line; and if addr2 is a regexp, it will not be tested against the line that addr1 matched.

After the address (or address-range), and before the command, a ! may be inserted, which specifies that the command shall only be executed if the address (or address-range) does not match.

The following address types are supported:

number
Match only the specified line number.

first~step
Match every step’th line starting with line first. For example, ”sed -n 1~2p” will print all the odd-numbered lines in the input stream, and the address 2~5 will match every fifth line, starting with the second. first can be zero; in this case, sed operates as if it were equal to step. (This is an extension.)
$
Match the last line.

/regexp/
Match lines matching the regular expression regexp.
\cregexpc
Match lines matching the regular expression regexp. The c may be any character.
GNU sed also supports some special 2-address forms:
0,addr2
Start out in “matched first address” state, until addr2 is found. This is similar to 1,addr2, except that if addr2 matches the very first line of input the 0,addr2 form will be at the end of its range, whereas the 1,addr2 form will still be at the beginning of its range. This works only when addr2 is a regular expression.
addr1,+N
Will match addr1 and the N lines following addr1.
addr1,~N
Will match addr1 and the lines following addr1 until the next line whose input line number is a multiple of N.

Source:
https://stackoverflow.com/questions/3576139/sed-remove-string-only-in-the-last-line-of-the-file
https://linux.die.net/man/1/sed

Categories: bash, sed