Allgemein

How to download Wasabi/S3 object to file using boto3 in Python

You can use boto3’s download_fileobj() in order to download files from S3 to the local filesystem:

with open("myfile.txt", "wb") as outfile:
    my_bucket.download_fileobj("myfile.txt", outfile)

Note that the file needs to be opened in binary mode ("wb").

Full example

import boto3

# Create connection to Wasabi / S3
s3 = boto3.resource('s3',
    endpoint_url = 'https://s3.eu-central-1.wasabisys.com',
    aws_access_key_id = 'MY_ACCESS_KEY',
    aws_secret_access_key = 'MY_SECRET_KEY'
)

# Get bucket object
my_bucket = s3.Bucket('boto-test')

# Download remote object "myfile.txt" to local file "test.txt"
my_bucket.download_file("myfile.txt", "test.txt")

Don’t forget to fill in MY_ACCESS_KEY and MY_SECRET_KEY. Depending on what region and what S3-compatible service you use, you might need to use another endpoint URL instead of https://s3.eu-central-1.wasabisys.com.

Posted by Uli Köhler in Allgemein

How to fix htpasswd cannot open file htpasswd for read/write access

Problem:

You are trying to add/change a password in a htpasswd file using a command like

htpasswd auth.htpasswd myuser

but you see this error message:

htpasswd: cannot open file htpasswd for read/write access

Solution:

htpasswd is trying to tell you that it got Permission denied when accessing the htpasswd file and hence can’t read it or it can’t write the file (auth.htpasswd in this example).

There are multiple ways to fix this:

  1. Run htpasswd using sudo, e.g.
    sudo htpasswd auth.htpasswd myuser
  2. Fix the permissions of the file, e.g. using
    sudo chown $USER auth.htpasswd
    chmod o+rw auth.htpasswd

    Note that this permanently modifies the permissions for the htpasswd file and hence might create additional security risks!

  3. Use a different htpasswd file to which you have access. You need to change the configuration on your webserver etc (i.e. the software that is using the htpasswd file). This option isn’t always available – e.g. if you can’t change the webserver’s configuration, you just have the option of asking the system administrator nicely.
Posted by Uli Köhler in Allgemein

How to reset Yealink T46G to factory settings

In order to reset your Yealink T46G to factory settings:

  1. Turn on the phone and wait until it has booted up
  2. Press the OK button until the phone asks you if you want to reset to factory settings
  3. Confirm the factory reset by pressing OK (i.e. the button on the bottom right of the screen, i.e. the rightmost button of the row of buttons just below the screen)
  4. Wait for the phone to reset
Posted by Uli Köhler in 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 !

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:

[email protected] ~/GoHttpTest % go build
[email protected] ~/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

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