Skip to content

Instantly share code, notes, and snippets.

View brennanMKE's full-sized avatar

Brennan Stehling brennanMKE

View GitHub Profile
@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:

@brennanMKE
brennanMKE / XcodeWarnings.sh
Created September 11, 2023 20:51
Xcode Warnings Script
TAGS="TODO:|FIXME:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
@brennanMKE
brennanMKE / README.md
Last active September 5, 2023 17:32
Bookmarklets for Swift language developers

Bookmarklets for Swift language developers

What is a bookmarklet? Basically it is a bit of JavaScript which you can store as a bookmark. The ones below prompt the user for a search term and immediately opens a URL to Google with the site restricted to get targetted search results. Simply bookmark any page then edit your bookmarks. Replace the new bookmark you just created with a useful title and the code below for each bookmark. Place them in your Favorites to show them at the top of Safari. You can also put them into a group so you can see them in a drop down list.

Apple Docs

javascript:(function() { var s = prompt("Apple Docs:"); var d = "https://www.google.com/search?q=" + encodeURIComponent(s + " site:developer.apple.com"); window.location = d;})()
@brennanMKE
brennanMKE / Debug.swift
Created September 3, 2023 20:51
Demangle and log call static symbols during runtime
// Revised code written by Naruki Chigira under MIT license.
// https://github.com/naru-jpn/CallStackSymbols
// See: https://stackoverflow.com/questions/24321773/how-can-i-demangle-a-swift-class-name-dynamically
// Darwin/Swift: https://github.com/apple/swift/blob/main/stdlib/public/runtime/Demangle.cpp#L913
#if DEBUG
import Foundation
import Darwin