Skip to content

Instantly share code, notes, and snippets.

View brennanMKE's full-sized avatar

Brennan Stehling brennanMKE

View GitHub Profile
@brennanMKE
brennanMKE / NoDelay.ino
Last active December 27, 2023 04:48
LED light control without delays
/**
LED lights control with no delays.
The Blink example Sketch for Arduino uses delays to control the built-in LED to turn
it on and off repeatedly. Since the next loop is delayed nothing else can be done
while until the delay expires. This Sketch controls the built-in LED and a strip of
10 LED lights without delays. It sets timeouts so that once the current clock passes
the timeout it can trigger an action. There is an interval for the blink and color
change which cycles through the list of colors and blinks a number of times for the
current color position.
@brennanMKE
brennanMKE / QRCode.swift
Created November 27, 2023 18:58
Create QR code
import CoreImage
struct QRCode {
static func generateQRCode(from url: String,
width: Double = 512.0,
heigth: Double = 512.0,
foregroundColor: CIColor = .black,
backgroundColor: CIColor = .white) -> CGImage? {
let data = url.data(using: String.Encoding.ascii)
@brennanMKE
brennanMKE / OpenWeatherMapKey.cpp
Created November 26, 2023 07:09
Networking with ESP32 Microcontroller
#include "OpenWeatherMapKey.h"
const char* OpenWeatherMapKey::key() {
return "INSERT_HERE";
}
@brennanMKE
brennanMKE / DataProvider.swift
Last active December 14, 2023 19:51
DataProvider using AsyncStream
import Foundation
struct DataProvider<Element: Sendable> {
let stream: AsyncStream<Element>
private let continuation: AsyncStream<Element>.Continuation
init(bufferingPolicy: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded) {
(stream, continuation) = AsyncStream.makeStream(bufferingPolicy: bufferingPolicy)
}
@brennanMKE
brennanMKE / README.md
Created October 28, 2023 01:56
ChatGPT and Swift Concurrency

ChatGPT and Swift Concurrency

Prompt:

What can you tell me about Swift Concurrency, Tasks, Actors and AsyncSequence?

Response:

Certainly! Swift introduced a native concurrency model starting from Swift 5.5, which brings a structured way to handle concurrent and asynchronous programming. Here's an overview of the main components:

@brennanMKE
brennanMKE / JoystickArrowKeys.ino
Created October 17, 2023 05:34
Pro Micro project that uses an arcade joystick as arrow keys.
// Joystick Keyboard
// This project is for a digital joystick (SANWA JLF-TP-8YT)
// connected to a Pro Micro board.
#include "Keyboard.h"
const int pinUp = 2; // Orange
const int pinDown = 3; // Red
const int pinLeft = 4; // Yellow
const int pinRight = 5; // Green
@brennanMKE
brennanMKE / BlockerPlayground.swift
Created October 10, 2023 20:31
Blocking code to integrate Swift Concurrency with legacy code which cannot be async
/// Sometimes it is necessary to integrate straight-line code with async code
/// and this can be done using a semaphore. Keep in mind that doing this breaks
/// the Forward Progress policy that is required by Swift Concurrency.
///
/// Warning: This code is not recommended for a production environment.
import Foundation
struct Blocker<Success, Failure: Error> {
private class ResultStore {
@brennanMKE
brennanMKE / README.md
Created October 2, 2023 22:37
Groups with ActivityPub

Groups with ActivityPub

Prompt:

I'd like to create a groups implementation using ActivityPub which allows members to join groups to share posts only members of the group can see and reply to. I also want to support photo albums and events with RSVP lists. Can this be implemented within the ActivityPub protocol using Activity Streams and Actors?

Response:

Yes, you can implement this functionality using the ActivityPub protocol with Activity Streams and Actors. The protocol is highly flexible and supports a wide variety of use cases, including the ones you've mentioned. Let's break down the process for each of the features you've listed:

@brennanMKE
brennanMKE / README.md
Last active October 2, 2023 17:15
Swinging Door: Reentrancy with an actor using Swift Concurrency

Swinging Door

This actor has 3 doors which can all be opened and closed. The open and close function will open or close all doors and also call the closure after each individual door has been modified. What happens if the open function has been called and the closure calls the close function?

Output:

Open All
@brennanMKE
brennanMKE / README.md
Created September 29, 2023 20:53
Chaos Monkey by ChatGPT

Chaos Monkey by ChatGPT

The following comes from a series to questions posed to ChatGPT.

Please list books which cover how Netflix technology works, specifically covering Chaos Monkey.

Certainly! Netflix's technology, particularly its emphasis on resilience and availability, has garnered a lot of attention. The company's pioneering work in chaos engineering, notably with tools like Chaos Monkey, has been influential in shaping how modern organizations think about reliability in distributed systems.

Here are some books and resources that delve into Netflix's technology and Chaos Monkey: