Skip to content

Instantly share code, notes, and snippets.

View mjm's full-sized avatar
😴
I'm probably napping

Matt Moriarity mjm

😴
I'm probably napping
View GitHub Profile
@mjm
mjm / Observables.swift
Created July 3, 2020 13:50
StateObject vs. ObservableObject
// If you run this in a playground in Xcode 12, you can see the difference in behavior in the live view.
import SwiftUI
import PlaygroundSupport
class Counter: ObservableObject {
@Published var count: Int
init(_ initialCount: Int) {
self.count = initialCount
@mjm
mjm / aoc2021.livemd
Last active December 18, 2021 15:42
Advent of Code 2021 solutions

Advent of Code 2021

Setup

The code below is not specific to any one Advent of Code problem, but instead is used by some or all of the problems.

defmodule AdventOfCode do
@mjm
mjm / ManagedObjectChangesPublisher.swift
Created November 3, 2019 20:41
Observe changes to a Core Data fetch request with Combine
import Combine
import CoreData
extension NSManagedObjectContext {
func changesPublisher<Object: NSManagedObject>(for fetchRequest: NSFetchRequest<Object>)
-> ManagedObjectChangesPublisher<Object>
{
ManagedObjectChangesPublisher(fetchRequest: fetchRequest, context: self)
}
}
@mjm
mjm / main.go
Created March 21, 2019 21:31
Instant clone a vSphere VM
package main
import (
"context"
"flag"
"fmt"
"net"
"net/url"
"os"
"path"
@mjm
mjm / LinkedText.swift
Created May 21, 2020 03:56
Tappable links in SwiftUI Text view
import SwiftUI
private let linkDetector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
struct LinkColoredText: View {
enum Component {
case text(String)
case link(String, URL)
}