Paul's Programming Notes     Archive     Feed     Github

ssh-keygen -R hostname

I’ve been manually removing the line from .known_hosts when I saw this message:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:<key>.
Please contact your system administrator.
Add correct host key in /Users/<user>/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/<user>/.ssh/known_hosts:85
ECDSA host key for <ip> has changed and you have requested strict checking.
Host key verification failed.

Today I found out about this command to remove entries from known_hosts: ssh-keygen -R hostname

Raspberry Pi 1U Server

I’ve been working on a power efficient 1U server made with Raspberry Pi’s to take advantage of cheap server colocation options:

More details: Github

Python - Automatic Type Hinting With Monkeytype

I’ve been poking around with adding type hints to Python code automatically. Here’s my process so far:

  1. pip install MonkeyType
  2. run tests with monkeytype run instead of python
  3. pytest: monkeytype run -m pytest
  4. mkdir stubs
  5. monkeytype list-modules | xargs -n1 -I{} sh -c 'monkeytype stub {} > stubs/{}.pyi'
  6. pip install pytype
  7. python move_files.py (file in this gist)
  8. mypy <code folder name>
  9. remove duplicate imports added by merge-pyi, fix import sorting issues
  10. clean up super long type hints by inlining with params
"""Loop over generated .pyi (stub) files, get path to respective .py file,
then run merge-pyi to add type hints as comments."""
import os
import subprocess
for f in os.listdir('stubs'):
print('merging:', f)
split_filename = f.split('.')
# create new path if necessary
match_dir = split_filename[:-2]
if match_dir:
match_dir = os.path.join(*match_dir)
os.makedirs(match_dir, exist_ok=True)
py_path = split_filename[-2] + '.py'
if match_dir:
matching_file = os.path.join(match_dir, py_path)
stub_file = os.path.join('stubs', f)
commands = ["merge-pyi", "-i", "--as-comments", matching_file, stub_file]
out = subprocess.run(commands, stdout=subprocess.PIPE).stdout
print(out)
view raw move_files.py hosted with ❤ by GitHub

Python - virtualenv & Dockerfiles

I recently saw a Dockerfile based on the official docker Debian image that was installing dependencies into a virtualenv.

I’m pretty sure using a virtualenv in an official Debian-based Dockerfile is unnecessary, because there’s no system Python to isolate from:

$ docker run -it debian /bin/bash
root@21ca17310079:/# python
bash: python: command not found

WLED

Today I learned about the amazing WLED project: https://github.com/Aircoookie/WLED

All you need to do is flash their binary to an ESP32 and it will bring up a WIFI access point that allows you to control the LEDs through an app or web page.

Microservice Communication

I’ve been learning more about async communication between microservices and came across this article that talks about some of the trade-offs between sync and async communication: https://dzone.com/articles/patterns-for-microservices-sync-vs-async

Summary

Sync

Pros

  • “synchronous calls are simpler to grasp, debug and implement”

Cons

  • “A temporary burst at one component can flood other services with requests.”
  • Risk of Cascading Failures (domino effect of failures if one service experiences an otuage)
  • tighter coupling (requires endpoint versioning in the owning service)

Async

Pros

  • “removes the need to wait for a response thereby decoupling the execution of two or more services”
  • “deals better with sporadic bursts of traffic”

Cons

  • “Asynchronous systems tend to be significantly more complex than synchronous ones.”
  • “consumers need to adapt to work with an asynchronous system”
  • “the message bus the Achilles heel of the system as it remains a central point of failure”
  • Eventual Consistency (potentially out of date data)