Angular HttpClient: Return both Blob and response Headers

export interface BlobAndHeaders {
  blob: Blob;
  headers: Headers;
}

myApi(arg: string): Observable<BlobAndHeaders> {
  return this.http.get<BlobAndHeaders>(`${this.baseURL}/api/myapi`, {
    observe: 'response',
    responseType: 'blob' as 'json',
    params: {arg: arg},
  }).pipe(map(
    response => {
      if(response.body === null) {
        throw new Error('No data received');
      }
      return {"blob": response.body, "headers": response.headers};
    }
  ));
}

 

Posted by Uli Köhler in Angular, Typescript

How to fix Python TypeError: lru_cache() got an unexpected keyword argument ‘max_size

Problem:

In Python, you’re using code such as

from functools import lru_cache

@lru_cache(max_size=128)
def myfunc(arg: str):
   # ...
   return arg + "x"

but you see an error message such as

Traceback (most recent call last):
  File "/dev/shm/test.py", line 3, in <module>
    @lru_cache(max_size=128)
TypeError: lru_cache() got an unexpected keyword argument 'max_size'

Solution:

You’ve mis-spelled the argument to @lru_cache: You wrote max_size with underscore whereas it actually is maxsize without underscore.

Posted by Uli Köhler in Python

Which distributors can JLCPCB source components from?

Please note: I can’t guarantee any of this, this is just according to my own research in April 2024

JLCPCB can order components from the following distributors:

  • DigiKey
  • Mouser
  • TTI
  • Chip1stop
  • Verical
  • Sager
  • Arrow
  • Element14 UK
  • Future
  • Powell
  • Avnet
  • Element
  • Onlinecomponents
  • Rutronik
  • CoreStaff
  • TME
Posted by Uli Köhler in Electronics

JLCPCB PCBA assembly price overview

This post summarizes JLCPCB fees. Please note that this is according to my own research in April 2024 and I can’t guarantee any of these prices or price structures in any way.

For reference, also see the official price list which lists most of these costs as well: https://jlcpcb.com/help/article/98-pcb-assembly-faqs

Economic vs standard PCBA

  • Economic PCBA: One-side only, 0$
  • Standard PCBA, 25$ for one-sided PCBA, 50$ for two-sided PCBA

Some parts such as ESP32 modules or WS2812-style LEDs force you to select standard PCBA.

See JLCPCB PCB assembly: List of known Standard only parts for more details.

Basic vs extended components

  • Basic components: 0$ per component type
  • Extended components: 2.74€/3$ per component type

SMT Assembly fees per solder joint

  • 0.0017$ per SMD pin

THT fees / Wave soldering fees

  • Manual assembly fee: 0.0173$ per THT pin. This is actually a wave soldering fee.
  • Fixed Hand soldering-fee3.22€/3.50$, this is actually a wave soldering fee with “assembly by hand”

Other fees

  • Special component fee: For USB-C connectors such as HC-TYPE-C-16P-01A, e.g. €0.1382 per component type (not per individual component)
  • Stencil: 1,38€/1.50$ fixed fee
  • Setup fee: 7,37€/8.00$ fixed fee
  • Panel: 0,00€, unclear how this is computed
  • Large size: 0.00€, unclear how this is computed
  • Components: How much your components cost, no additional markup.

 

Posted by Uli Köhler in Electronics

How to iterate rows of a pandas DataFrame with timestamp index

You can use df.iterrows() normally:

import pandas as pd
import numpy as np

# Assuming 'df' is your DataFrame
# For demonstration, let's create a sample DataFrame
dates = pd.date_range('2023-01-01', periods=5)
data = np.random.randn(5, 2)
df = pd.DataFrame(data, index=dates, columns=['A', 'B'])

# Iterating over rows
for index, row in df.iterrows():
    print(f"Index: {index}, A: {row['A']}, B: {row['B']}")

Note that index is a pd.Timestamp.

Posted by Uli Köhler in pandas, Python

How to drop multiple rows from pandas DataFrame by index

import pandas as pd
import numpy as np

# Create a sample DataFrame with datetime index
dates = pd.date_range('2023-01-01', periods=10)
data = np.random.randn(10, 2)
df = pd.DataFrame(data, index=dates, columns=['A', 'B'])

# Timestamps to drop
timestamps_to_drop = [pd.Timestamp('2023-01-03'), pd.Timestamp('2023-01-05'), pd.Timestamp('2023-01-07'),
                      pd.Timestamp('2023-01-08'), pd.Timestamp('2023-01-10')]

# Drop rows
df_filtered = df.drop(index=timestamps_to_drop)

 

Posted by Uli Köhler in pandas, Python

How to fix “snap refresh”: snap “…” has running apps

Problem:

You want to update your snap, e.g. signal-desktop, but when you try to snap refresh it, you see the following error message:

Error: cannot refresh "signal-desktop": snap "signal-desktop" has running apps (signal-desktop),
        pids: 471050,471137,471138,471189,471204,471248

Solution:

You can’t stop the running apps via snap. Just kill them using killall, for example:

killall signal-desktop && sudo snap refresh signal-desktop

Alternatively, you can kill the PIDs listed in the error message (you need to separate them by space, not by comma):

kill 471050 471137 471138 471189 471204 471248

 

Posted by Uli Köhler in Linux

How to initialize your KiCAD 8 project on the command line

TL;DR:

Inside the directory where you want to create the project, run

wget -qO- https://raw.githubusercontent.com/ulikoehler/KiCAD-ProcessAutomation/master/InitializeKiCad8Project.sh | bash /dev/stdin MyProject

You should replace MyProject (at the end of the command) with your project name.

Note: This will initialize an empty KiCAD project without any libraries. This is equivalent to creating a new project in KiCAD itself (using the GUI).

Continue reading →

Posted by Uli Köhler in Electronics, KiCAD, Shell

How to fix pyspice OSError: cannot load library ‘libngspice.so’

Problem:

When trying to run a PySpice program, you see an error message such as

OSError: cannot load library 'libngspice.so': libngspice.so: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libngspice.so'

Solution:

Install libngspice, often called libngspice0.

On Ubuntu, install it using

sudo apt -y install libngspice0-dev

You need to install the -dev library since libngspice0 only contains libngspice.so.0 whereas the -dev library contains libngspice.so which is required by pyspice.

Posted by Uli Köhler in Python, SPICE

STM32 HAL PlatformIO LED blink example

In the autogenerated main.c, use the following while() loop:

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
  HAL_Delay(1000);
  HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
  HAL_Delay(1000);
}
/* USER CODE END 3 */

On STM32H7 Nucleo boards, this will toggle the green LED.

Posted by Uli Köhler in C/C++, PlatformIO, STM32

How to fix Nextcloud docker container permissions

docker-compose exec nextcloud chown -vR www-data:www-data /var/www/html

 

Posted by Uli Köhler in Nextcloud

What are the cheapest general purpose SMD diodes?

Typically some 1N4001…1N4007 in SOD-123 or SOD-123FL package is the cheapest available diode. It is available from many manufacturers and at all distributors.

The typical rating is:

  • 1A forward current
  • 1000V reverse voltage
  • Instantaneous forward voltage of <=1V @1A

On LCSC, a full reel (3000pcs) of SOD4007-MS by MSKSemi costs just 6,60€

Posted by Uli Köhler in Components

What cheap general purpose MOSFET to use?

The 2N7002 or 2N7002K MOSFET is one of the best MOSFETs to use if you just want to have a general purpose switching FET.

  • 60Vds
  • 300mA
  • 1.9Ohm RDSon

It or its variants is available from many manufacturers and at all distributors.

On LCSC, for example, one reel of 2N7002 from chinese manufacturer HL, only costs 15.90€, that is 0,0053€/pc

Posted by Uli Köhler in Components, Electronics

JST VH contact picture

JST SVH-21T-P1.1 contact, for inventory management etc.

This picture is my own work and hereby released under CC0-1.0-Universal.

Posted by Uli Köhler in Electronics

How to set pandoc PDF page border on the command line

Add these command line options:

-V geometry:margin=20mm

-V is short-form for --variable

This will configure the default LaTeX template to use

\usepackage[margin=20mm]{geometry}
Posted by Uli Köhler in LaTeX

How to fix apt-update NO_PUBKEY E88979FB9B30ACF2

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E88979FB9B30ACF2

 

Posted by Uli Köhler in Linux

Angular: How to inject child component class by ID via ViewChild

<app-my-component #myId></app-dynamic-plot>
@ViewChild('myid', {read: MyComponent}) myComponent!: MyComponent;

 

Posted by Uli Köhler in Angular

How to fix Hugo access denied: “asciidoctor” is not whitelisted in policy “security.exec.allow”; the current security configuration is:

Problem:

When compiling your Hugo page, you see an error message such as

ERROR render of "section" failed: "/home/uli/klc/themes/hugo-theme-techdoc/layouts/_default/list.html:3:4": execute of template failed: template: _default/list.html:3:4: executing "main" at <.Content>: error calling Content: "/home/uli/klc/content/footprint/F2/_index.adoc:1:1": access denied: "asciidoctor" is not whitelisted in policy "security.exec.allow"; the current security configuration is:

Solution:

You need to edit your Hugo configuration file and add asciidoctor or whatever program caused the error, to the list of allowed programs to execute.

For TOML config files, add the following section which consists of the default value plus asciidoctor

[security]
    [security.exec]
    allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^npx$', '^postcss$', '^asciidoctor$']

After that, recompile your Hugo page.

Posted by Uli Köhler in Python

How to fix Python cache3 ImportError: cannot import name ‘SafeCache’ from ‘cache3’

Problem:

You want to use cache3‘s SafeCache as shown in the Quickstart

from cache3 import SafeCache
cache = SafeCache()

but you instead see the following error message:

ImportError: cannot import name 'SafeCache' from 'cache3' (/usr/local/lib/python3.10/dist-packages/cache3/__init__.py)

Solution:

cache3 has been updated, but the documentation still has not been fixed. This is a known bug.

The closest equivalent is Cache() with thread_safe=True, an in-memory cache which supports tagging:

from cache3 import Cache
cache = Cache(name="mycache", thread_safe=True)

In case you don’t need tagging,  consider MiniCache:

from cache3 import MiniCache
cache = MiniCache(name="mycache", thread_safe=True)

 

Posted by Uli Köhler in Python

How to fix PySpice WARNING – Unsupported Ngspice version 36

Problem:

When you try to run your PySpice script, you see an error log such as

PySpice.Spice.NgSpice.Shared.NgSpiceShared._send_char - WARNING - spinit was not found
PySpice.Spice.NgSpice.Shared.NgSpiceShared._send_char - ERROR - Note: can't find init file.
PySpice.Spice.NgSpice.Shared.NgSpiceShared._init_ngspice - WARNING - Unsupported Ngspice version 36

Solution:

Your PySpice is too new for the ngspice version installed on your system.

Typically, it’s easiest to install a slightly older PySpice version:

sudo pip3 install -U "pyspice<1.5"

(but you can also update your ngspice).

Posted by Uli Köhler in Electronics, Python
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPTPrivacy &amp; Cookies Policy