Create a Multi-Stage Docker Build for Python Flask and Postgres

A few days ago, I created a Docker build for Flask with PostgreSQL (both with Alpine Linux and with Debian Linux). Installing psypcopg-2 binary (required for Postgres) requires you to build the package from source. Now the Docker image grows in size, as it still contains the build artifacts. The solution? Multi-stage Docker builds. Let’s say we have the following docker-compose.yml file. There are two services: a Flask API called users and a Postgres database called users-db.
Read more →

Handle Python Dependency Management With Virtual Environments

Create isolated Python projects with virtual environments What is a virtual environments and why should I use it? A virtual environment allows you to develop several Python projects with different versions of packages on the same computer. Python usually installs the latest versions of your dependencies globally. You’ll run into problems, if one of your projects requires a different package version. venv Python ships with venv out of the box since version 3.
Read more →

Fish Plugins I Like

Updated: December 5th, 2019 Fish shell is my favorite shell. It’s awesome. Fish comes with useful features out of the box. For example, excellent auto-completion and syntax highlighting make my life easier. Fish is a joy to use. What Is a Shell? From technopedia: A shell is software that provides an interface for an operating system’s users to provide access to the kernel’s services. On Unix-based or Linux-based operating systems, a shell can be invoked through the shell command in the command line interface (CLI), allowing users to direct operations through computer commands, text or script.
Read more →

How to Search in Vim

To search a file, type / (search forwards) or ? (search backwards) and enter the word. Normally, Vim will check for upper and lower letters. But you can set two different options in your configuration file (~/.vimrc or similar): set ignorecase or set smartcase Examples: pattern ‘ignorecase’ ‘smartcase’ matches ~ foo off - foo foo on - foo Foo FOO Foo on off foo Foo FOO Foo on on Foo \cfoo - - foo Foo FOO foo\C - - foo Other options:
Read more →

Dockerize a React App

This post will be my notes on dockerizing a React application. You can find the original post by Michael Herman at Dockerizing a React App. I use a dedicated node user in my approach, instead of running the container as root user. For detailed explanations, go to Michael’s post. Requirements Docker v19.03 docker-compose 1.25 Node v12.13.1 Project Setup Create the application, for example, via create-react-app: npx create-react-app dockerized-react && cd dockerized-react Docker Add a Dockerfile to your project directory (a file without extension):
Read more →

Vim Trick: Map CTRL+S to Save

Vim is very customizable. You can adjust key-bindings to your liking. For example, if you want to save a file, you’ll type :w or :up in command mode. But maybe you’re used to press CTRL+S to save a file? You could add a custom key-mapping to your configuration file (~/.vimrc or similar): nnoremap <silent><c-s> :<c-u>update<cr> The command works in normal mode. You can also bind CRL+S for other modes (visual mode and insert mode):
Read more →

Vim Undo And Redo

Today I learned about Vim undo and redo. Undo changes: in normal mode: u to undo latest change, U to undo all changes in Ex mode (command mode): :u to undo latest change Use :u {N} to undo a number of changes. For example, :undo 5 reverts the latest 5 changes. Redo changes: in normal mode: Ctrl+r in Ex mode: :re or :redo In Vim, undo is a tree:
Read more →

Pipe a Terminal Command to Vim

How can you run a command in your normal shell and then pipe it to Vim? A typical use case could be to run a find command and open the found file in Vim. Answer: You can use command substitution. vim $(find . -name example.txt) Here’s a useful command that I’m using now: nvim (fd | fzy) (I’m using fish as my interactive shell. Thus I don’t need to use $.
Read more →

Tool: fd - The Faster Alternative to find

fd is a “simple, fast, and user-friendly alternative to find”. This neat tool offers a more intuitive syntax for finding files and operating on them. The author wrote fd in Rust. Thus, it’s quite fast. Let’s say we want to find all mp3 files in a directory. With find, you have to do something like this: find -name "*.mp3" fd looks simpler: fd -e mp3 Here’s an example command that converts all jpg files to png files:
Read more →

Start Vim With Terminal Command

Today I learned that you can start Vim with a terminal command. Vim has the -c flag, which you can use for running an Ex command. The same is true for NeoVim, which also has an inbuilt terminal. So you can either start NeoVim inside the terminal like so: nvim +te or like that: nvim -c ‘:terminal’ The second option allows you to run another command afterwards. Example:
Read more →