Allgemein

How to install RabbitMQ on Ubuntu in 30 seconds

Use our script:

wget -qO- https://techoverflow.net/scripts/install-rabbitmq.sh | sudo bash /dev/stdin

This will install RabbitMQ and its dependencies from the official deb repositories.

Or do it manually:

Copy and paste these command blocks into your Linux shell. You need to copy & paste one block at a time – you can paste the next block once the previous block is finished!

sudo apt-get update -y
sudo apt-get install apt-transport-https curl gnupg -y
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
deb https://dl.bintray.com/rabbitmq-erlang/debian $(lsb_release -cs) erlang
deb https://dl.bintray.com/rabbitmq/debian $(lsb_release -cs) main
EOF
sudo apt-get update -y
sudo apt-get install rabbitmq-server -y --fix-missing

 

Posted by Uli Köhler in Allgemein

How to cleanup large gitlab prometheus/data in Omnibus/Docker setting

In many of my dockerized Gitlab instances, the prometheus/data folder was eating up multiple Gigabytes of hard drive space even though I was not using Prometheus at all.

In order to fix this, I first disabled Prometheus in the docker-compose.yml config using

prometheus_monitoring['enable'] = false

Also see How I reduced gitlab memory consumption in my docker-based setup for a detailed explanantion.

After that, you need to restart gitlab in order for the settings change to take effect.

Now you can just delete the Prometheus data folder. Make a backup of the entire gitlab data folder before this step.

Run this command from within your gitlab data folder:

rm -rf prometheus/data

 

Posted by Uli Köhler in Allgemein, Linux

Cylinder volume calculator (from diameter & height)

Calculate the volume of a cylinder from its diameter and height using this online calculator – formula included.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

m

m



V = \pi\cdot(\frac{d}{2})²\cdot h

Posted by Uli Köhler in Allgemein

Bilirubin mg/dl to μmol/l converter

Convert Bilirubin from mg/dl to μmol/l using this online calculator – formula included.

Note about medical information:
This information is presented for informational purposes only and is intended for professionals. While we strive to provide accurate information, this information might be outdated, unintentionally misleading or incorrect. Consult a medical professional and/or read the primary sources cited in our article before basing any decision on this information.
TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

mg/dl


n[mol] = \frac{m[g]}{M_m[\frac{g}{mol}]}

Posted by Uli Köhler in Allgemein

Accessory cord tensile strength calculator (EN 564)

Calculate the tensile strength of accessory cords according to EN564 using this online calculator – formula included.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

mm

F_{\text{tensile,min}}[N] = 0.20\frac{\text{kN}}{\text{mm²}} \cdot \text{D[mm]}²
Posted by Uli Köhler in Allgemein

Sense resistor / current shunt + current sense amplifier calculator

Calculate the output voltage of a current sense amplifier combined with a current shunt resistor – formula included.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

Don’t need a current sense amplifier? See our Sense resistor / current shunt calculator.

This calculator allows you to find out which sense resistor and current sense amplifier you need to use to obtain a specific amplifier output voltage at a specific current.

A

V

V/V

R_{\text{sense}} = \frac{U_{\text{drop}}}{I_{\text{sense}} \cdot G_{\text{current sense amplifier}}} U_{\text{sense,drop}} = I_{\text{sense}} \cdot R_{\text{sense}} P_{\text{sense}} = {I_{\text{sense}}}^2 \cdot R_{\text{sense}}
Posted by Uli Köhler in Allgemein

Sense resistor / current shunt calculator

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

Too much power dissipation? You need to use a current sense amplifier ! See our Sense resistor / current shunt + current sense amplifier calculator !

Know the value of your sense resistor already? Use our Sense resistor power dissipation calculator

This calculator allows you to find out which sense resistor you need to drop a specified voltage at a given current. Additionally it computes the power dissipated in the sense resistor.

A

V

R_{\text{sense}} = \frac{U_{\text{drop}}}{I_{\text{sense}}} P_{\text{sense}} = I_{\text{sense}}² \cdot R_{\text{sense}}
Posted by Uli Köhler in Allgemein

Relay lifetime online calculator

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

Note: A cycle is typically defined as switching the relay on and switching it off again, i.e. one cycle consists of two switch actions (on + off).

In case you know how many seconds between cycles:

s

cycles

N_{\text{predicted}} = N_{\text{nominal}} \cdot \text{Seconds between cycles}

In case you know how many relay cycles per second:

Hz

cycles

N_{\text{predicted}} = \frac{N_{\text{nominal}}}{\text{Cycles per second}}
Posted by Uli Köhler in Allgemein

Go HTTP Server minimal example

package main

import (
    "fmt"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello world!")
    })

    // log.Fatal shows you if there is an error like the
    //  port already being used
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Save this file as Main.go in a directory called GoHTTPServer, run go build && ./GoHTTPServer. Then, open http://localhost:8080 in your browser and see the result for yourself.

Posted by Uli Köhler in Allgemein

Go HTTP client minimal example

This example gets the current IPv4 address from TechOverflow’s IP address HTTP API How to get your current IPv4 address using wget.

package main

import (
    "io/ioutil"
    "net/http"
)

func main() {
    // Perform request
    resp, err := http.Get("https://ipv4.techoverflow.net/api/get-my-ip")
    if err != nil {
        print(err)
        return
    }
    // Cleanup when this function ends
    defer resp.Body.Close()
    // Read all the response data into a []byte
    body, err := ioutil.ReadAll(resp.Body)
    // Decode & print
    println(string(body))
}

Save as Main.go in a new project directory (e.g. GoHttpTest) and run go build in that directory.
After that, you can run ./GoHttpTest which should print your IPv4 adress. Example:

uli@server ~/GoHttpTest % go build
uli@server ~/GoHttpTest % ./GoHttpTest 
91.59.80.56

 

Posted by Uli Köhler in Allgemein, Go

How to fix Angular Cannot find module ‘@angular/http’ after ‘ng update’

When updating to Angular 8.x+, developers commonly encouter this type of error:

app/app.module.ts:9:42 - error TS2307: Cannot find module '@angular/http'.

9 import {HttpModule, RequestOptions} from '@angular/http';

The solution

The @angular/http module has been removed in recent versions of Angular and replaced by @angular/common/http.  Furthermore, there are some name changes that might need manual fixing, including:

  • HttpModuleHttpClientModule
  • HttpHttpClient
  • URLSearchParams ⇒ HttpParams

Note that the replacements are not always exact equivalent and hence might require some work to get working

See the official @angular/http deprecation guide for more details on how to migrate.

Posted by Uli Köhler in Allgemein

How to fix vpnc-disconnect ‘no vpnc found running’

Problem:

You want to disconnect from your vpnc VPN using vpnc-disconnect, but you see this error message:

Solution:

vpnc-disconnect doesn’t know the difference between no vpnc is running and permission denied when trying to stop the vpnc daemon.

In most cases, using sudo:

sudo vpnc-disconnect

will fix the issue.

If this does not resolve the issue for you, check if you used the --pid-file argument to vpnc. vpnc-disconnect always assumes that the PID file is /var/run/vpnc.pid.

Alternatively, check out our alternate methods of stopping vpnc.

Posted by Uli Köhler in Allgemein

What is the pullup/pulldown resistor value on the SAMD21?

Also see Does the SAMD21 have pullups on every pin?

The ATSAMD21 microcontrollers have integrated pull-up and pull-down resistors which you can enable or disable in software.

The nominal value of the pull-up and pull-down resistors is 40 kΩ but it can be between 20 kΩ and 60 kΩ.

Refer to the datasheet, section 37.9.1 for more details.

Posted by Uli Köhler in Allgemein

How to dump SQL from SQLite3 database file

If you have a SQLite3 database file (usually the filename extension is .db) and you want to dump it as SQL code, you can use

sqlite3 [database file] .dump

For example:

$ sqlite3 /usr/share/command-not-found/commands.db .dump
[...]
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('packages',14669);
INSERT INTO sqlite_sequence VALUES('commands',47706);
CREATE INDEX idx_commands_command ON commands (command);
CREATE INDEX idx_packages_name ON packages (name);
COMMIT;

Missing the sqlite3 executable?

In case you don’t have the sqlite3 executable, you can install it using

sudo apt -y install sqlite3

on Ubuntu/Debian-based system

Posted by Uli Köhler in Allgemein, SQLite

How to fix C error ‘stderr undeclared’

Problem:

You have C code like

fprintf(stderr, "test");

but when you try to compile it you see an error message like

/home/uli/myproject/main.c:9:25: error: ‘stderr’ undeclared (first use in this function)
                 fprintf(stderr, "test");

Solution:

Add

#include <stdio.h>

at the top of the source file where the error occured. Including stdio.h will include symbols like printf, fprintf, stdin, stdout and stderr.

Posted by Uli Köhler in Allgemein

How to install MicroK8S (MicroKubernetes) on Ubuntu in 30 seconds

This set of commands will install & start MikroK8S (MikroKubernetes) on Ubuntu and similar Linux distributions.

sudo snap install microk8s --classic
sudo snap install kubectl --classic
sudo microk8s.enable # Autostart on boot
sudo microk8s.start # Start right now
# Wait until microk8s has started
until microk8s.status ; do sleep 1 ; done
# Enable some standard modules
microk8s.enable dashboard registry istio

For reference see the official quickstart manual.

Posted by Uli Köhler in Allgemein, Cloud, Container, Kubernetes

How to fix kubectl ‘The connection to the server localhost:8080 was refused – did you specify the right host or port?’

Problem:

You want to configure a Kubernetes service using kubectl using a command like

kubectl patch service/"my-elasticsearch-svc" --namespace "default"   --patch '{"spec": {"type": "LoadBalancer"}}'

but you only see this error message:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Solution:

Kubernetes does not have the correct credentials to access the cluster.

Add the correct credentials to the kubectl config using

gcloud container clusters get-credentials [cluster name] --zone [cluster zone]

e.g.

gcloud container clusters get-credentials cluster-1 --zone europe-west3-c

After that, retry your original command.

In case you don’t know your cluster name or zone, use

gcloud container clusters list

to display the cluster metadata.

Credits to this StackOverflow answer for the original solution.

Posted by Uli Köhler in Allgemein, Cloud, Container, Kubernetes

Fixing NodeJS Intl.DateTimeFormat not formatting properly for locales

Symptom:

NodeJS starting from version v9.x supports the ES6 Intl.DateTimeFormat

When you use it with the ‘en-US’ locale, it works properly and prints "August 13, 2018":

const df = new Intl.DateTimeFormat('en-US', {day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC'});
console.log(df.format(new Date("2018-08-13T04:00:00.000Z")));

However, using it with a different locale fails:

const df = new Intl.DateTimeFormat('de', {day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC'});
console.log(df.format(new Date("2018-08-13T04:00:00.000Z")));

While you would expect this to print "13. August 2018" , it will print "2018 M08 13"

Reason:

By default, NodeJS is only built with small-icu support, thereby only installing the en-US locale in order to reduce the installation filesize.

Solution 1 (preferred):

You can use the intl polyfill module to completely replace NodeJS’s implementation of intl:

Installation:
npm i --save intl
Usage:
// Replace Intl by polyfill
Intl = require("intl")

const df = new Intl.DateTimeFormat('de', {day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC'});
console.log(df.format(new Date("2018-08-13T04:00:00.000Z")));

This will print 13. August 2018 as expected.

Solution 2 (alternate):

You can use the full-icu package to continue using the NodeJS ICU implementation (i.e. no polyfill), but just install the ICU data.

While this reduces the total installation filesize, installation is slow and the exact method depends on the NodeJS version and requires more work than just using the intl polyfill.

In order to install, use

npm i --save full-icu

This will take some time to compile the data and then will print instructions like this:

 √ icudt62l.dat (link)
Node will use this ICU datafile if the environment variable NODE_ICU_DATA is set to “node_modules/full-icu”
or with node --icu-data-dir=node_modules/full-icu YOURAPP.js
 For package.json:
{"scripts":{"start":"node --icu-data-dir=node_modules/full-icu YOURAPP.js"}}

By the way, if you have full data, running this in node:
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
... will show “enero”. If it shows “January” you don't have full data.
News: Please see https://github.com/icu-project/full-icu-npm/issues/6

In order to actually use full-icu, you need to use the --icu-data-dir=node_modules/full-icu argument every time you run node. In order to run node interactively, use

node --icu-data-dir=node_modules/full-icu

If you use scripts in your application (e.g. the start script, i.e. what gets executed if you run npm start), you need to adjust the configuration in package.json:

Instead of

// [...]
"scripts": {
    "start": "node index.js"
}
// [...]

use

// [...]
"scripts": {
    "start": "node --icu-data-dir=node_modules/full-icu index.js"
}
// [...]

Depending on your application, you might need to use a different script name than index.js – common names include server.js and start.js

Posted by Uli Köhler in Allgemein, Javascript, NodeJS

What do ko, Mo & Go mean?

ko , Mo and Go are french for kb, Mb and Gb:

ko (kilooctet) = kb (kilobytes)
Mo (Mégaoctet) = Mb (Megabytes)
Go (Gigaoctet) = Gb (Gigabytes)
To (Téraoctet) = Tb (Terabytes)
Posted by Uli Köhler in Allgemein

How to use BIOS instead of UEFI firmware for a VMWare virtual machine

Recent versions of VMWare’s VMPlayer use UEFI firmwares by default if you select a UEFI-compatible operating system during VM creation.
There are some cases, however, in which you have to change the VM to a classical BIOS firmware afterwards, for example if you have your operating system installed without UEFI support or if you selected the wrong operating system.

Currently, it seems to be impossible do change the firmware setting in the GUI, therefore you first have to find the .vmx file corresponding to the virtual machine. Usually it is located at ~/vmware/<Name of VM>/<Name of VM>.vmx.

After stopping the VM , open that file in your favourite text editor and look for this line:

firmware = "efi"

Change it to

firmware = "bios"

After that, save the file, restart VMPlayer and start your VM.

Posted by Uli Köhler in Allgemein