Blog

jupyter notebook websockets in aws

<virtualhost *:80>
  ProxyPreserveHost On
  ProxyRequests Off

  ServerName notebook.your-domain.com

  # redirect all requests to https
  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  SetEnv HTTPS 1

  # allow web-sockets
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)           ws://localhost:8888/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)           http://localhost:8888/$1 [P,L]

  # forward to specific port
  ProxyPass / http://localhost:8888/
  ProxyPassReverse / http://localhost:8888/
</virtualhost>

unusual-linux-commands

Unusual linux commands can be very handy in several cases. Here are some of them.

Repeat the last typed command:

!!

 

Display file-content like cat, but from upside down, can be achieved with tac (reverse cat)

tac myfile.txt

 

Like to lookup in a dictionary file? Use look. Everything whats starts with the passed word will be shown.

look car

 

Display time / date in bash screen on right upper corner. Continously!

while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &

 

Show all buildin commands

compgen -b

 

Show all commands you can run

compgen -c

utf8-encoded letters in email subject

You might have discovered strange characters in your email-subject like: Ã¼, Ã¤ or Ã¶, and so on?
That’s because you have sent them as UTF-8 and they are being interpreted as ISO-8859. Maybee the charters in the email’s body part are correct because you have already set a proper encoding! Well, the body and the subject needs a separate encoding. You can solve the problem by passing the subject string like below:

'=?utf-8?B?'.base64_encode('Subject with special chars like: äöü').'?='

 

using ffmpeg for video converting

ffmpeg is a mighty tool for dealing with videos. Around the ffmpeg core is a rich ecosystem with video-editing related tools. First, we look at some handy examples to get a feeling how to deal with ffmpeg.

Converting different file formats

Getting basic information about a video is as easy as:

ffmpeg -i input.avi

Converting an mp4-video to an avi-video with ffmpeg:

ffmpeg -i input.mp4 output.avi

The quality of the output can be defined as well with a number between 1 (high quality) and 50 (low quality). If you output-video is an avi you use the -p parameter. If your output-video is mp4 you use the parameter -crf instead. Have a look at the exmaple:

ffmpeg -i input.mp4 -q 30 output.avi
ffmpeg -i input.avi -crf 30 output.mp4

Use ffmpeg to convert an input-video to an output-video and set the framerate (parameter -r) of the output video to 5 frames:

ffmpeg -i input.mp4 -r 5 output.avi

Scaling a video can be done with ffmpeg as well. Use the scale video filter. This filter has two parameters, notice that the second one is -1, this means that the scaling for the y-axis is proportional.

ffmpeg -i input5mb-1280x720.mp4 -vf scale=300:-1 out.mp4

Changing colors by using ffmpeg video filters

Convert input video to a greyscale output video with ffmpeg (see the -vf videofilter parameter):

ffmpeg -i input.mp4 -vf colorchannelmixer=.3:.4:.3:0:.3:.4:.3:0:.3:.4:.3 out.avi

Convert input video to a sepia output video with ffmpeg:

ffmpeg -i input.mp4 -r 15 -vf colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131 out.avi

Joining (concatenate) and cutting videos

Cutting video with ffmpeg is simple. You want to specify a start and end time to convert only a certain timeslice? No Problem. The parameter -ss 30:15 let the video start at 30 minutes and 15 seconds. The parameter -t 40 defines the length. Take care of the parameters orders. This example cuts a 40-second lasting piece and starts at 30 min and 15 seconds:

ffmpeg -ss 30:15 -i input.mp4 -t 40 output.mp4

You can even join (concatenate) videos together with ffmpeg. Concat two avi-videos together can be done with this command:

ffmpeg -i "concat:part1.avi|part2.avi" -codec copy output.avi

Joining mp4-videos doesn’t work the before mentioned way. Here we first create some intermediate ts files and join them afterwards:

ffmpeg -i in1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp1.ts
ffmpeg -i in2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp2.ts
ffmpeg -i in3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp3.ts
ffmpeg -i "concat:tmp1.ts|tmp2.ts|tmp3.ts" -c copy -bsf:a aac_adtstoasc result.mp4

 

Caturing video from webcam with ffmpeg

Capturing video from a webcam with ffmpeg and store it in output-video.
(It is important to know the name of your webcam device. In my case, it is /dev/video0 under linux. You can research this with the command: ffmpeg -sources)

ffmpeg -i /dev/video0 out.avi

 

terminal-shortcuts

Some useful Linux terminal shortcuts. For increased proficiency on the shell.

CTLR + L               Clean-up the whole screen

CTRL + A               Move cursor to the beginning of the line
CTRL + E               Move cursor to the end of the line

ALT + ESC + .       display the last entered parameters

Linux Tutorial Part2

Read Linux Tutorial Part1, before you start here.

Commands you have head about in Part1 are:
whoami, hostname, uname, uptime, clear, pwd, cd, echo, ~ and others.

 

In the second part of the Linux Tutorial, we will learn about dealing with files and folders (directory).

First move to your home directory with (change directory):

cd

Now let us create a directory, named „garage“, with the „make directory“ command:

mkdir garage

You have created the garage directory, but you are still inside your home directory. Go into the garage directory with:

cd garage

Notice,  that the „change directory“ is by far the most important command. You will see, that you will use this command very often.
In the next step, you go „one directory up“, so that you will be in your home directory again. This can be achieved with:

cd ..

Don’t forget the space between „cd“ and the two dots. The two dots is a sign for the directory above. There is a top-level directory, called the root. There is no directory above the root directory. You can go there with:

cd /

Again, there is a space between „cd“ and the „slash“. If you are curious whats inside the root folder, type:

ls -l

The list command, with the parameter „l“, shows you the directories content. Time to go back into our garage directory inside our home directory. Go there with:

cd ~/garage

The tilde (press Alt-key + tilde-sign) is a sign for our home folder. And we want to go inside the garage folder, which is inside our home folder. We create now a file called „mycar.txt“ and write „bmw“ inside this file. Here we go:

echo "bmw" > mycar.txt

The echo command simply displays the word in quotes, in this case „bmw“. The > character redirects the result („bmw“) into the file, which came behind the „>“ sign. Btw: a single „>“ always create an empty file, even when the file already exists. When you want to attach something to a file simply use „>>“. Let’s look into the file:

cat mycar.txt

We want to copy the file mycar.txt:

cp mycar.txt mybike.txt

And now we want to attach something to our new file:

echo "is not a car" >> mybike.txt

Check the content of our new file with:

cat mybike.txt

And check the contet of our garage folder with:

ls -l