Jekyll Docker image missing C headers

So, if you are using Jekyll Docker image and you need to install any Ruby gems that require C headers, such as raindrops in my case, which was a dependency for unicorn, you will find yourself faced with this error:

fatal error: asm/types.h: No such file or directory

Fortunately, there is a quick fix for this. Jekyll docker image allows you to add system dependencies very easily. You just need to mention the dependent packages inside a file called .apk at the root of your project or beside Dockerfile. Since the docker image is based out of Alpine linux, you need to specify the correct package name as in Alpine packages.

Create a file called .apk and add the following line to it.

linux-headers

Now, when you bring up your containers, it will automatically install the linux-headers package which contains all the required header files and proceed to installing the gems successfully.

Vim Bootstrap – generate .vimrc for your favorite programming language

Programmers in the current era like to work using IDEs because it is more user friendly. But there are reasonable number of programmers who still use command line for programming. Their favourite editor might be Vim. Vim is easy to use, light-weight and comes with almost every Unix distribution. Unlike IDEs, it does not hang easily. The only problem with Vim editor is that it does not have inbuilt syntax highlighters. Checkout Vim Bootsrap , problem solved. Using the site you can generate .vimrc file for your favourite programming language. Copy the .vimrc file in your home directory. Now, you are ready to start programming using your favourite language. Vim Bootstrap comes with support of c, python, php, javascript, perl, go and lot more.

Executing bash commands via python

In python, executing bash commands can be done using subprocess module. It’s pretty easy to use and it’s a powerful module. For simple commands,  we can use subprocess.call

Usage:

import subprocess

subprocess.call("command1")

subprocess.call(["command1", "arg1", "arg2"])

Eg:

import subprocess

subprocess.call(["ls", "-l"])
total 4

-rw-rw-r-- 1 tevin tevin 15 Sep 3 15:29 test.txt

You can also use subprocess.check_call  and subprocess.check_output

Popen:

For more flexibility, you can use Popen . Using this you can store the output of command as well as any error occurred during command execution.

Eg:

process = subprocess.Popen(["ls", "-l"])
(output, err) = process.communicate()

communicate  method interacts with process and waits for the process to complete. It returns a tuple consisting of stdout and stderr.

Executing commands in background:

subprocess.Popen() only runs a process in the background if nothing in the python script depends on the output of the command being run. For example, the following code won’t be executed in background.

import subprocess

process = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE)

Thinking about what is subprocess.PIPE?

subprocess.PIPE: Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that a pipe to the standard stream should be opened.

Changing directory(cd command):

You might be thinking that why ‘cd’? Why it can’t be executed using subprocess?

If you use subprocess.call(“cd ..”), it will throw an error ‘No such file or directory’. It is because cd is a shell internal. So you can only call it as

subprocess.call('cd ..', shell=True)

But it is pointless to do so.  As no process can change another process’s working directory (again, at least on a UNIX-like OS, but as well on Windows), this call will have the subshell change its dir and exit immediately. Don’t worry you can change directory using os.chdir(path).