Rust with Docker and Visual Studio Code

1. Install Rustup

Install rustup – installer for the systems programming language Rust.

If you don’t want to install rustup using script obtained using curl, you can use my Docker image which contains installed rustup:

$ docker image pull h00s/rustup

Create directory where Rust toolchain will be located:

$ mkdir $HOME/.rustup

2. Install Rust toolchain

Using rustup Docker image, install toolchain (on GNU Linux):

$ docker container run --rm --user "$(id -u)":"$(id -g)" -v $HOME/.rustup:/.rustup h00s/rustup /usr/bin/rustup install stable-x86_64-unknown-linux-gnu

Add $HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin to PATH.

3. Install components

$ docker container run --rm --user "$(id -u)":"$(id -g)" -v $HOME/.rustup:/.rustup h00s/rustup /usr/bin/rustup component add rls

$ docker container run --rm --user "$(id -u)":"$(id -g)" -v $HOME/.rustup:/.rustup h00s/rustup /usr/bin/rustup component add rust-src

$ docker container run --rm --user "$(id -u)":"$(id -g)" -v $HOME/.rustup:/.rustup h00s/rustup /usr/bin/rustup component add rust-analysis

4. Configure VSCode for Rust

Install Rust Extension to VSCode. Make sure you added toolchain bin directory to PATH.

Add this to VSCode settings.json:

"rust-client.trace.server": "messages",
"rust-client.disableRustup": true,

Screen flickering on i915 graphics using Debian 9

Recently I had a problem with my Lenovo ThinkPad E550 laptop which is running Debian 9. Problem was that occasionally display would start flickering, “jumping” or just blacking out for couple of seconds. Problem was most noticeable when using Terminal, Gedit, Chrome etc.

Apparently, problem is with (default) SNA acceleration in recent X.Org. I had to revert to older and mature backend: UXA. Read more about it here.

To fix this and revert to UXA acceleration method, create /usr/share/X11/xorg.conf.d/20-intelaccel.conf file with these contents:

Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod" "uxa"


Unitoptek IP camera RTSP URL

Recently I’ve bought cheap IP camera from AliExpress. I don’t want to write about camera’s quality (which is actually quite good for the price), you can read about it from hundreds of feedbacks on above link.

This camera has no documentation, and to access it, you have to use Internet Explorer and install ActiveX control. Yeah, I know.

If you’re alike me, you probably want RTSP link so you can connect it to ZoneMinder or some other video surveillance software system. If you wonder if RTSP link is displayed in camera’s software, it’s not.

I’ve searched and tried many, maany URLs from Internet, and this is working RTSP url for this camera:


If you haven’t setup password for admin user (you really should), just leave password empty, like this:


This link will also work for other clones of this camera: Anten TEK, Dongjia etc.

Relative time in Phoenix

In my last project I’m writing in Phoenix, I needed to display relative time on insertion time, something like time_ago_in_words in Rails. As such function doesn’t exist in Phoenix framework, I wrote it myself.

First, I wrote a seconds_ago  view function so I can get how many seconds has passed from inserted Ecto.DateTime  to current time:

[code lang="elixir"]
def seconds_ago(datetime) do
  :calendar.datetime_to_gregorian_seconds(:calendar.local_time()) - :calendar.datetime_to_gregorian_seconds(Ecto.DateTime.to_erl(datetime))

When I have information how many seconds has passed, I can calculate relative time and output it as text:
def time_ago_in_words(seconds) when seconds < 60 do
  "#{seconds} second(s) ago"
def time_ago_in_words(seconds) when seconds < 3600 do
  "#{round(seconds/60)} minute(s) ago"
def time_ago_in_words(seconds) when seconds < 86400 do
  "#{round(seconds/3600)} hour(s) ago"
def time_ago_in_words(seconds) do
  "#{round(seconds/86400)} day(s) ago"

To display relative time in template, it’s simple as this:

<%= model.inserted_at |> seconds_ago |> time_ago_in_words %>

UPDATE: Here you can get better version of  time_ago_in_words  which acts like the one in Rails.

Static IP address in Raspbian

If you installed Raspbian on RaspberryPi and tried to set static IP address using /etc/network/interfaces  you have noticed that it doesn’t work.

Problem is, Raspbian is using dhcpcd – a DHCP client for setting IP address. You can try to:

  • remove dhcpd daemon and set the address in interfaces  file, or
  • set the static IP address for your RaspberryPi in your DHCP server.

But, the really best and simplest solution is to set static IP address thru dhcpcd.

Open /etc/dhcpcd.conf  file and add this content at the end of the file:

static ip_address=
static routers=
static domain_name_servers=

This IP address is then set for eth0  interface. If you have more than one interface, you need to add interface interface_name  before static ip_address line:

interface wlan0
static ip_address=

Renaming default username in Raspian (on RaspberryPi)

When you install Raspbian on RaspberryPi, default username is pi. Often, you want to change it to custom username (and keep uid 1000). Here’s how to change it, along with user’s home directory:

usermod -l new_username -m -d /home/new_username pi
  • -l new value of the login name
  • -m move contents of the home directory to the
    new location
  • -d new home directory for the user account

Also, change default user’s group name:

groupmod -n new_username pi

To successfully change it, pi user can’t be logged in. You have to log in as root (or another user in sudo group) and execute above commands.

Automatic Mikrotik shutdown at specific time

I’m using Mikrotik wAP access point for home Wi-Fi. At night, for various reasons, I don’t want my Wi-Fi on, so I set up automatic shutdown at midnigth and automatic start up at 6am.

Problem is, in Mikrotik, you can schedule automatic shutdown but not startup. When the device was shut down, only way to start it up again is to plug it out from power outlet and plug it in again. To do this automatically, you’ll need outlet power timer switch similar to this.

Continue reading

Setting page title in Phoenix

In Rails, you probably used content_for  for setting every page title. In Phoenix, layout is rendered before page template is rendered so content_for  approach will not work. Instead, here’s how you can set different page title for every action.

In layout_view.ex file, add get_page_title  function:

def get_page_title(conn) do
  if conn.assigns[:page_title] do
    "#{conn.assigns[:page_title]} - ApplicationName"

Continue reading

Forwarding mail in ISPConfig 3 without leaving copy

In ISPConfig 2 there was a little nice feature for mail user where you could easily forward mail to another mail address, with or without leaving a copy on server:


It was really useful feature because user could always forward mail and leave a copy (or not) on server with single click. ISPConfig 3 does not have that feature (well, it has, but you can’t easily select to keep copy or not) but it has custom for mailbox where you can define filter using Sieve.

Continue reading

Enabling swap in Linux

In Linux, when physical memory (RAM) is full, inactive pages in memory are moved to the swap. Swap space is located on hard drive, which is significantly slower than RAM. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. However, it’s very useful when you need a little bit more RAM for a brief piece of time, like compiling software etc.

Many VPS providers (like Digital Ocean) don’t enable swap automatically, and you need to enable it by yourself. Here’s how:

Continue reading