Skip to content

Instantly share code, notes, and snippets.

View marcuswestin's full-sized avatar

Marcus Westin marcuswestin

  • New York
View GitHub Profile
@marcuswestin
marcuswestin / import-and-merge-repos-into-monorepo-with-full-history.sh
Created February 4, 2023 04:57
Import multiple repos into a single mono repo, into custom subfolder paths, while maintaining full commit history for all repos
#!/bin/bash
#
# Create a new monorepo by fusing multiple repositories.
#
# Exit immediately if a command exits with a non-zero status,
# and print commands and their arguments as they are executed.
set -ex
# Set the name of the org, and the monorepo to create
GITHUB_ORG="github-org-or-account"
@marcuswestin
marcuswestin / demo.ts
Created September 20, 2021 16:21
Example of content-based code-folding that works
import {EditorState, EditorView, basicSetup} from "@codemirror/basic-setup"
import { StateField } from "@codemirror/state";
import { Line } from "@codemirror/text";
import { Decoration, DecorationSet, WidgetType } from "@codemirror/view";
let doc = `
Test list 1
- Test item
- Test item
@marcuswestin
marcuswestin / demo.ts
Last active September 20, 2021 16:21
Example of content-based code-folding that has a rendering bug
import {EditorState, EditorView, basicSetup} from "@codemirror/basic-setup"
import { foldEffect } from "@codemirror/fold";
import { Line } from "@codemirror/text";
import { Decoration, DecorationSet, PluginValue, ViewPlugin, ViewUpdate, WidgetType } from "@codemirror/view";
let doc = `
Test list 1
- Test item
- Test item
@marcuswestin
marcuswestin / SwiftUI WrappableViewController.swift
Created January 25, 2020 19:37
An approach for simplified wrapping of AppKit and UIKit view controllers in SwiftUI
//
// WrappableViewController.swift
// macOS-Wordflower
//
// Created by Marcus Westin on 1/24/20.
// Copyright © 2020 Marcus Westin. All rights reserved.
//
// My preferred approach to wrapping AppKit and UIKit viewControllers in SwiftUI
@marcuswestin
marcuswestin / SwiftUI WrappableView.swift
Last active January 25, 2020 15:38
Another approach for simplified wrapping of AppKit and UIKit views in SwiftUI.
//
// WrappableView.swift
// macOS-Wordflower
//
// Created by Marcus Westin on 1/24/20.
// Copyright © 2020 Marcus Westin. All rights reserved.
//
// My preferred approach to wrapping AppKit and UIKit views in SwiftUI
@marcuswestin
marcuswestin / SwiftUI WrapView coordinator protocol approach.swift
Last active January 25, 2020 15:36
An approach for simplified wrapping of AppKit and UIKit views in SwiftUI
protocol ViewWrapper {
associatedtype ViewType: OSView
typealias Context = OSViewRepresentableContext<WrapView<Self>>
func makeView(_ context: Context) -> ViewType
func updateView(_ view: ViewType, _ context: Context)
func wrapped() -> WrapView<Self>
}
struct WrapView<Wrapper: ViewWrapper>: OSViewRepresentable {
let wrapper: () -> Wrapper
@marcuswestin
marcuswestin / SwiftUI WrapView handler approach.swift
Last active September 25, 2021 20:03
An approach for simplified wrapping of AppKit and UIKit views in SwiftUI
import SwiftUI
#if os(macOS)
typealias OSView = NSView
typealias OSViewRepresentable = NSViewRepresentable
#elseif os(iOS)
typealias OSView = UIView
typealias OSViewRepresentable = UIViewRepresentable
#endif
@marcuswestin
marcuswestin / LinkedList.swift
Created December 28, 2019 16:37
Linked List in swift
import Foundation
class LinkedList<T> {
private class Link<T> {
var prev: Link?
var next: Link?
let value: T
init(_ value: T) {
self.value = value
@marcuswestin
marcuswestin / Atomic.swift
Created December 28, 2019 16:33
Some atomic operations in swift
import Foundation
final class Atomic {}
extension Atomic {
// Atomic value example:
// let val = Atomic.Value<Int>(1)
// val.mutate { $0 += 1 }
// val.get()
final class Value<T> {
@marcuswestin
marcuswestin / ObservableProperty.swift
Created December 27, 2019 01:18
SwiftUI Combine ObservableProperty
import Combine
private var retainForever = [AnyCancellable]()
class ObservableProperty<T>: ObservableObject {
@Published private var value: T
init(initialValue: T) {
self.value = initialValue
}