Skip to content

Instantly share code, notes, and snippets.

View hugodahl's full-sized avatar

Hugo Dahl hugodahl

View GitHub Profile
results.Keys.Should().Contain("dad2");
results.Should().ContainKey("dad2");
@hugodahl
hugodahl / SampleGuidance.ino
Last active May 28, 2024 05:14
Idea on Guidance for HugoBot in Arduino (semi-pseudo code)
#include "MeMegaPi.h"
#include "Arduino.h"
#include "SoftwareSerial.h"
// Define the pins/outputs that map to the individual motors
#define WHEEL_LF = PORT2B // Set to the pin for LEFT FRONT wheel
#define WHEEL_RF = PORT1A // Set to the pin for RIGHT FRONT wheel
#define WHEEL_LR = PORT2A // Set to the pin for LEFT REAR wheel
#define WHEEL_RR = PORT1B // Set to the pin for RIGHT REAR wheel
@hugodahl
hugodahl / code.py
Created July 23, 2022 03:06
Simple PICO sketch
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""Example for Pico. Blinks the built-in LED."""
import time
import board
import digitalio
import analogio
@hugodahl
hugodahl / GetAllCommandCommands.cs
Created May 19, 2022 03:23
Getting a list of registered services from DI
// This is the thing that does the work, or the "!command" command
public class GetAllCommandsCommand : ICommandMbhToTwitch
{
public GetAllCommandsCommand(IOptionsSnapshot<List<string>> commandNames)
{
var commands = commandNames.Get("CommandNames");
this.CommandNames = commands;
}
@hugodahl
hugodahl / The-fear-of-git-rebase.md
Last active August 18, 2021 13:18
Why folks fear the `git rebase` or `git merge --rebase`

This is a response to a question asked on the Adafruit discord server, where someone asked

"Hugo what is exactly rebasing, and why people always has nightmare stories about that?"

Rebasing has become a bit overloaded as a term, but in essence, it means taking a given branch and putting its changes "on top of" other changes. That's quite confusing, so I'll explains...

Imagine you're working on a repository with other people. Commits up to now were merged and linear in the "main" branch... c0 - c1 - c2 - c3 - c4. You start working on a feature, so you create a feature branch off the "main" branch, at commit "c4". You do work on that branch, and create your local commits. So the tree looks like this:

c0 - c1 - c2 - c3 - c4 - c5 - c6
 \ f0 - f1 - f2
@hugodahl
hugodahl / .pre-commit-config.yaml
Last active February 13, 2021 22:06
Calling pylint from the pre-commit hook
repos:
- repo: https://github.com/python/black
rev: stable
hooks:
- id: black
- repo: https://github.com/fsfe/reuse-tool
rev: latest
hooks:
- id: reuse
- repo: https://github.com/pre-commit/pre-commit-hooks
@hugodahl
hugodahl / UpdateProcess.md
Last active February 10, 2021 13:48
Steps for moving a CircuitPython library from a module to a package

Moving a CircuitPython from a module to a Package

The Clinical Steps

Code changes

  • Create a directory with the name adafruit_library where "library" is the name
    • Note: CASE matters. Make it all lowercase
  • Add an __init__.py file to the directory
    • Let Python know that the directory can be imported
@hugodahl
hugodahl / MakeItLegible.js
Last active February 8, 2021 04:35
Making Amazon Parents Dashboard Reading Log Legible
let newStyle = document.createElement('style');
newStyle.setAttribute('type', 'text/css');
newStyle.textContent = '#pd-nav { display: none; } #pd-site-wrapper .pd-margin-top { margin-top: 2px; } #pd-site-wrapper .pd-margin-bottom { margin-bottom: 2px; } .rv-xy-plot {display: none;} .css-16a1pix > * { padding: 0px; margin: 0px !important; } .category-bar { display: none; } .activity-detail-card { background-image: none !important; } .css-1ngfmhc { display: none; } .activity-list-item { height: auto; } .css-16e2ufj {display: none; } .full-day-block { page-break-before: auto; page-break-inside: avoid; border: 2px solid black; margin: 5px; } .full-day-block * { page-break-before: avoid; page-break-after: auto; page-breeak-inside: avoid; } .css-17x129u { height: auto; } '
document.head.appendChild(newStyle);
let dayBlocks = document.getElementsByClassName('activity-day-header');
dayBlocks.forEach( element => { let elem = element.parentElement; elem.classList.add('full-day-block');} );
@hugodahl
hugodahl / CreateEnv.sh
Last active February 8, 2021 02:03
Running Adafruit_Blinka with the blinka_displayio_pygamedisplay library on macOS
#!/usr/bin/env bash
# Create and move into our working directory
mkdir DisplayTest
cp SimpleTest.py ./DisplayTest/
cd DisplayTest
# Create a virtual Python3 environment, to keep things sane
python3 -m virtualenv .venv
@hugodahl
hugodahl / Exposing-Ports-in-Docker.md
Last active January 20, 2021 15:34
An Explanation of How Ports are Exposed and Mapped in Docker with Containers ( Adafruit Discord - #General Channel)

On the [Adafruit][] [Discord server][Adafruit Discord], user @madboger asked a question regarding [Docker][]. Their question was:

Cool! One quick question on my own project: if I'm running a web service inside Docker, how does the TCP port appear on the host? I assume there's some forwarding configuration somewhere that describes the mapping?

– [@MadBoger's question][Question]

Here is [my response and brief explanation][Response], in simplified terms, to cover the majority of the circumstances and avoid the more complex situations...

That's correct @madbodger, there is a mapping. In reality, the way I see it, there's 2 parts.