- Go to the OpenWebStart download page
- Download the appropriate version for your operating system
- Install
How to install Java (OpenJDK) on Windows in 2021
- Go to the AdoptOpenJDK website
- Click on the Download button
- Install
How long does a I²C message transmission take? Online calculator
Enter the number of data bytes to be transmitted (excluding the start byte containing the slave address & RW bit).
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.
How to fix GCC lots of undefined reference to std:: functions
Problem:
When trying to compile your C++ application, you see lots of undefined reference to
messages like
AutoBenchmark.cpp:(.text+0x6a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x81): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x8a): undefined reference to `std::chrono::_V2::system_clock::now()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0xcd): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0xe6): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: /tmp/cc356AdP.o: in function `AutoBenchmark::~AutoBenchmark()': AutoBenchmark.cpp:(.text+0x17e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x18e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: /tmp/cc356AdP.o: in function `AutoBenchmark::Record(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': AutoBenchmark.cpp:(.text+0x1db): undefined reference to `std::chrono::_V2::system_clock::now()' /usr/bin/ld: /tmp/cc356AdP.o: in function `AutoBenchmark::Record(char const*)': AutoBenchmark.cpp:(.text+0x252): undefined reference to `std::allocator<char>::allocator()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x288): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x294): undefined reference to `std::allocator<char>::~allocator()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x2b9): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x2ce): undefined reference to `std::allocator<char>::~allocator()' /usr/bin/ld: /tmp/cc356AdP.o: in function `AutoBenchmark::Print()': AutoBenchmark.cpp:(.text+0x316): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x332): undefined reference to `std::cout' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x337): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x344): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x572): undefined reference to `std::cout' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x577): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x59c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x5ab): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x5c2): undefined reference to `std::ostream::operator<<(double)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x5d1): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x607): undefined reference to `std::cout' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x60c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x631): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x640): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x657): undefined reference to `std::ostream::operator<<(double)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x666): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x69c): undefined reference to `std::cout' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x6a1): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x6c6): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x6d5): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x6ec): undefined reference to `std::ostream::operator<<(double)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x6fb): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x731): undefined reference to `std::cout' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x736): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x75b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x76a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x781): undefined reference to `std::ostream::operator<<(double)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x790): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /usr/bin/ld: AutoBenchmark.cpp:(.text+0x7c6): undefined reference to `std::cout'
Solution:
You need to link the stdc++
library by adding -lstdc++
to your compiler/linker flags.
For example, instead of
gcc -o myprogram *.c
use
gcc -o myprogram *.c -lstdc++
How to fix GCC error: expected constructor, destructor, or type conversion before __declspec(dllexport)
Problem:
When trying to compile an application on Linux, you see a compiler error message like
myheader.h:23:12: error: expected constructor, destructor, or type conversion before ‘(’ token 23 | __declspec(dllexport) int myfunc(
Solution:
__declspec(dllexport)
is a Windows-specific feature and not available on Linux. In order to fix it in a compatible way, add this code either in a header that is included in every file containing __declspec(dllexport)
or add it in each file where the error occurs:
#ifdef __linux__ #define __declspec(v) #endif
This will basically ignore any __declspec()
call on the preprocessor level.
How to fix GCC undefined reference to `sqrt’
Problem:
When trying to compile your application using gcc, you see an error message like
/usr/bin/ld: /tmp/ccxPIowU.o: in function `run_mymath': mathstuff.c:(.text+0x15d): undefined reference to `sqrt'
Solution:
You need to link the math library using the -lm
flag (-lxxx
means: “link the xxx
library”, i.e. -lm
means “link the m
” library)
For example, instead of
gcc -o myprogram *.c
use
gcc -o myprogram *.c -lm
How to fix GCC undefined reference to `_finite’ or implicit declaration of function ‘_finite’
Problem:
If you’re trying to compile Windows code on Linux, you will often see messages like
lmmin.c:261:10: warning: implicit declaration of function ‘_finite’; did you mean ‘finite’? [-Wimplicit-function-declaration] 116 | if(!_finite(myvalue)){
or
/usr/bin/ld: mymath.c:(.text+0x1057): undefined reference to `_finite'
and your code won’t compile.
Solution:
_finite
is a function that is only available on Windows. In order to use it on Linux using GCC or G++, one option is to use isfinite()
from math.h
:
#include <math.h> #define _finite(v) (isfinite((v)))
In case that function is not available (like on some Microcontroller platforms), you can use __builtin_isfinite()
. Note that glibc defines isfinite()
as an alias for __builtin_isfinite()
. Use it like this:
#define _finite(v) (__builtin_isfinite(v))
In case you want to have code that is compatible with both platforms (Windows and Linux), use
#ifdef __linux__ #define _finite(v) (__builtin_isfinite(v)) #endif
or
#include <math.h> #ifdef __linux__ #define _finite(v) (isfinite((v))) #endif
Where can you buy LSA+ (LSA Plus) PCB-mount terminals?
TME offers a PCB-mount LSA terminal:
Comprehensive AWG to mm² area / mm diameter chart
This chart covers wire sizes from 0000 AWG to AWG41
AWG | mm² area | mm diameter |
---|---|---|
4/0 or 0000 AWG | 107 | 11.68 mm |
3/0 or 000 AWG | 85 | 10.40384 mm |
2/0 or 00 AWG | 67.4 mm² | 9.26592 mm |
0 AWG | 53.5 mm² | 8.25246 mm |
1 AWG | 42.4 mm² | 7.35 mm |
2 AWG | 33.6 mm² | 6.54 mm |
3 AWG | 26.7 mm² | 5.83 mm |
4 AWG | 21.2 mm² | 5.19 mm |
5 AWG | 16.8 mm² | 4.62 mm |
6 AWG | 13.3 mm² | 4.11 mm |
7 AWG | 10.6 mm² | 3.67 mm |
8 AWG | 8.35 mm² | 3.26 mm |
9 AWG | 6.62 mm² | 2.91 mm |
10 AWG | 5.27 mm² | 2.59 mm |
11 AWG | 4.15 mm² | 2.3 mm |
12 AWG | 3.31 mm² | 2.05 mm |
13 AWG | 2.63 mm² | 1.83 mm |
14 AWG | 2.08 mm² | 1.63 mm |
15 AWG | 1.65 mm² | 1.45 mm |
16 AWG | 1.31 mm² | 1.29 mm |
17 AWG | 1.04 mm² | 1.15 mm |
18 AWG | 0.823 mm² | 1.024 mm |
19 AWG | 0.653 mm² | 0.912 mm |
20 AWG | 0.519 mm² | 0.812 mm |
21 AWG | 0.412 mm² | 0.723 mm |
22 AWG | 0.325 mm² | 0.644 mm |
23 AWG | 0.259 mm² | 0.573 mm |
24 AWG | 0.205 mm² | 0.511 mm |
25 AWG | 0.163 mm² | 0.455 mm |
26 AWG | 0.128 mm² | 0.405 mm |
27 AWG | 0.102 mm² | 0.361 mm |
28 AWG | 0.0804 mm² | 0.321 mm |
29 AWG | 0.0646 mm² | 0.286 mm |
30 AWG | 0.0503 mm² | 0.255 mm |
31 AWG | 0.0404 mm² | 0.16002 mm |
32 AWG | 0.0320 mm² | 0.2032 mm |
33 AWG | 0.0254 mm² | 0.18034 mm |
34 AWG | 0.0201 mm² | 0.16002 mm |
35 AWG | 0.0160 mm² | 0.14224 mm |
36 AWG | 0.0127 mm² | 0.12700 mm |
37 AWG | 0.0100 mm² | 0.11430 mm |
38 AWG | 0.00797 mm² | 0.10160 mm |
39 AWG | 0.00632 mm² | 0.08890 mm |
40 AWG | 0.00501 mm² | 0.07874 mm |
What are typical insertion & withdrawal forces for PCIe connectors?
This Amphenol datasheet lists 1.15 N/pin
insertion force and 0.15 N/pin
withdrawal force.
Based on these values:
- A PCIe x1 connector with 36 pins
- insertion force of
36*1.15N = 41.4 N = 4.22 kgf
and - withdrawal force of
36*0.15N = 5.4 N = 0.551 kgf
- insertion force of
- A PCIe x4 connector with 64 pins
- insertion force of
64*1.15N = 73.6 N = 7.505 kgf
and - withdrawal force of
64*0.15N = 9.6 N = 0.979 kgf
- insertion force of
- A PCIe x8 connector with 98 pins
- insertion force of
98*1.15N = 112.7 N = 11.492 kgf
and - withdrawal force of
98*0.15N = 14.7 N = 1.499 kgf
- insertion force of
- A PCIe x16 connector with 164 pins
- insertion force of
164*1.15N = 188.6 N = 19.232 kgf
and - withdrawal force of
164*0.15N = 24.6 N = 2.509 kgf
- insertion force of
- A PCIe x24 connector with 230 pins
- insertion force of
230*1.15N = 264.5 N = 4.22 kgf
and - withdrawal force of
230*0.15N = 34.5 N = 3.518 kgf
- insertion force of
How many pins does a PCIe connector have?
A PCIe x1 connector has 36 pins (18 pins on each side)
A PCIe x4 connector has 64 pins (32 pins on each side)
A PCIe x8 connector has 98 pins (49 pins on each side)
A PCIe x16 connector has 164 pins (82 pins on each side)
A PCIe x24 connector has 230 pins (115 pins on each side)
Source: Samtec catalog, Amphenol datasheet (x24)
How to ignore pylint problem for a specific single line of code
If you have a Python line of code like
writer = pd.ExcelWriter(filename)
that produces a pylint problem message like
Abstract class 'ExcelWriter' with abstract methods instantiated pylint(abstract-class-instantiated)
you can ignore it by adding a comment in the format # pylint: disable=[problem-code]
at the end of the line where [problem-code]
is the value inside pylint(...)
in the pylint message – for example, abstract-class-instantiated
for the problem report listed above.
The modified line will look like this:
writer = pd.ExcelWriter(filename) # pylint: disable=abstract-class-instantiated
You can also add the comment line
# pylint: disable=abstract-class-instantiated
to the function-level (or to any other block-level) to disable that pylint rule for the entire current function or block.
How to migrate from ansicolor to ansicolors
The ansicolor package in Python has not been updated in a long time and doesn’t have any documentation on PyPI. Therfore, I migrated my Python scripts to ansicolors (with an s
at the end). Only a few steps are neccessary:
First, replace
from ansicolor import red
by
from colors import red
Additionally, bold=True
is called style="bold"
in ansicolors, hence you need to replace
red("msg", bold=True)
by
red("msg", style="bold")
How to fix matplotlib .ylabel() AttributeError: ‘AxesSubplot’ object has no attribute ‘ylabel’
Problem:
You want to set the ylabel of a matplotlib plot using .ylabel("My ylabel")
but you see an error messsage like
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-12-28a87d95bccc> in <module> ---> 11 axs[0].ylabel("My ylabel") AttributeError: 'AxesSubplot' object has no attribute 'ylabel'
Solution:
Use .set_ylabel("My ylabel")
instead of .ylabel("My ylabel")
!
While
from matplotlib import pyplot as plt plt.ylabel("My ylabel")
works fine, if you have an axes object like the one you get from plt.subplots()
, you’ll have to use set_ylabel()
!
from matplotlib import pyplot as plt fig, axs = plt.subplots(2, 1) # ... axs[0].set_ylabel("My ylabel")
How to fix matplotlib .xlabel() AttributeError: ‘AxesSubplot’ object has no attribute ‘xlabel’
Problem:
You want to set the xlabel of a matplotlib plot using .xlabel("My xlabel")
but you see an error messsage like
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-12-28a87d95bccc> in <module> ---> 11 axs[0].xlabel("My xlabel") AttributeError: 'AxesSubplot' object has no attribute 'xlabel'
Solution:
Use .set_xlabel("My xlabel")
instead of .xlabel("My xlabel")
!
While
from matplotlib import pyplot as plt plt.xlabel("My xlabel")
works fine, if you have an axes object like the one you get from plt.subplots()
, you’ll have to use set_xlabel()
!
from matplotlib import pyplot as plt fig, axs = plt.subplots(2, 1) # ... axs[0].set_xlabel("My xlabel")
How to fix matplotlib .title() TypeError: ‘Text’ object is not callable
Problem:
You want to set the title of a matplotlib plot using .title("My title")
but you see an error messsage like
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-11-f5f930f00eac> in <module> ---> 10 axs[0].title("My title") TypeError: 'Text' object is not callable
Solution:
Use .set_title("My title")
instead of .title("My title")
!
While
from matplotlib import pyplot as plt plt.title("My title")
works fine, if you have an axes object like the one you get from plt.subplots()
, you’ll have to use set_title()
!
from matplotlib import pyplot as plt fig, axs = plt.subplots(2, 1) # ... axs[0].set_title("My title")
How to replace string in column names in Pandas DataFrame
Use this snippet in order to replace a string in column names for a pandas DataFrame:
new_df = df.rename(columns=lambda s: s.replace("A", "B")) # df will not be modified !
You can also modify the column names in-place (i.e. modify the original DataFrame):
df.rename(columns=lambda s: s.replace("A", "B"), inplace=True)
For example, if you have the columns ["ColumnA", "X", "Y"]
before running .rename()
, the result will have ["ColumnB", "X", "Y"]
(the "A"
has been replaced by "B"
)
How to find out if BytesIO is empty in Python
In order to find out if a BytesIO instance is empty or not, get its size and then check if it’s > 0
:
my_bytesio.getbuffer().nbytes > 0
The following example shows how to use it in an if
clause:
if my_bytesio.getbuffer().nbytes > 0: print("my_bytesio is empty") else: print("my_bytesio is NOT empty")
How to get size of BytesIO in Python
If you want to find out the size of the data stored in a io.BytesIO
instance in Python, use
my_bytesio.getbuffer().nbytes
How to fix Synology Docker: failed to initialize logging driver: database is locked
Problem:
When you try to start a specific Docker container using the Synology NAS GUI, the container is being stopped unexpectedly and you see an error message like this in the logs:
Start container mycontainer failed: {"message":"failed to initialize logging driver: database is locked"}. Signal container mycontainer failed: {"message":"Cannot kill container: mycontainer: Container 5136ddceeb46004c5b18f04eb9ec10cac3808938515874fc31185b0964232201 is not running"}.
Solution:
I fixed this problem by stopping the container, duplicating the container session: Right click on the container -> Settings -> Duplicate Settings
That will create a new container with the given settings. Note that local ports will be set to Auto and will not be copied over, so if you use fixed local ports, you need to set them to a different value in the original container and then set the local ports on the new container to the desired fixed value. Also note that files inside the container are not copied over. In my configuration, all relevant files are stored in mapped volumes on the NAS.
The root cause of this issue seems to be that the logging database for this specific container has been locked by some process. The issue is always limited to a certain container and will not affect other containers (though it could in principle occur for more than one container). I know that at least in my specific case, the issue is not caused by a reboot and will also not be fixed by a reboot of the Synology NAS. Just before I encountered the issue, my NAS had not been rebooted for months, but it might be related to Synology package updates since I updated some packages using the Package manager just before encountering the issue, including a Synology Mail Plus update which failed on the first attempt, but succeeded when I clicked Update again.