Skip to content

Instantly share code, notes, and snippets.

//
// ContentView.swift
// SwiftUIDataManagingSample
//
// Created by Matthew Burke on 11/16/21.
//
import SwiftUI
struct ContentView: View {
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private lazy var toyFS: SimulatorFS = {
return SimulatorFS()
}()
private lazy var userFileSystem: GMUserFileSystem = {
return GMUserFileSystem(delegate: self.toyFS, isThreadSafe: false)
@profburke
profburke / JSONDecoder+Utils.swift
Created February 13, 2018 15:46
use JSONDecoder on a string
import Foundation
enum ExtendedDecodingError: Error {
case badString
}
extension JSONDecoder {
public func decode<T>(_ type: T.Type, from string: String) throws -> T where T: Decodable {
if let data = string.data(using: .utf8) {
let result = try decode(type, from: data)
@profburke
profburke / Item.swift
Last active November 5, 2020 13:09
Files for Serverless Swift article
public enum Style: String, Codable {
case croissant
case naan
case pumpernickel
case rye
}
public struct Item: Codable {
public let amount: Int
public let style: Style
@profburke
profburke / swiftr
Created November 19, 2017 18:12
Wrapper around swift command that makes it easier to import your own modules
#!/usr/bin/env lua
--
-- @author Matthew M. Burke <matthew@bluedino.net>
-- @date 2017-11-17
-- @version 1.0
-- @project Wrapper for Swift command
-- @file swiftr
--
-- Want to use your own Swift modules in the Swift REPL?
== How to Implement an AWS Lambda function using Swift 4
1. Use the appropriate docker image to build a Swift 4 executable.
docker run -it -v "$(PWD):/app" doctorimpossible/swift4ubuntu bash
mkdir demo; cd demo
swift package init --type executable
:: edit Sources/demo/main.swift
@profburke
profburke / backtrack.lua
Created May 3, 2017 12:30
Generalized backtrack generator for combinatorial objects
#!/usr/bin/env lua
-- For details: http://www2.seas.gwu.edu/~ayoussef/cs6212/backtracking.html
bins = {
{1, 2, 3},
{'a', 'b', 'c', 'd'},
{'A', 'B'},
}
N = #bins
-- make use of morse.lua to do morse code via
-- LEDs on an ESP8266
-- first, rough attempt
morse = dofile 'morse.lua'
DOTPIN = 2
DASHPIN = 1
_sleep = 10000

Steps to use a Swift package you are creating in the REPL. Assuming the package is named lump.

  1. Add a dynamic library product to the manifest: .library( name: "lump", type: .dyanmic, targets: ["lump"]),
  2. Build package as normal: swift build
  3. Fire up the REPL as follows: swift -I .build/debug -L .build/debug -llump
import Foundation
public enum ExecutionError: Error {
case SomethingHappened
}
func execute(command: String, args: [String]? = nil, input: String? = nil) throws -> String {
let task = Process()
var inpipe: Pipe?