Skip to content

Instantly share code, notes, and snippets.

Avatar

Dad @ GeekAndDad GeekAndDadDad

View GitHub Profile
@GeekAndDadDad
GeekAndDadDad / TestDecodingFunTests.swift
Last active Sep 22, 2020
@chunkyguy on twitter said they were facing a similar challenge to one I was facing, but their challenge actually seemed a little different and potentially easier. So I explored their challenge and created this solution.
View TestDecodingFunTests.swift
//
// TestDecodingFunTests.swift
// TestDecodingFunTests
//
// Created by Dad on 9/22/20.
//
// Poster wanted to be able to parse (visual) "components" out of a json file that would
// have various components of various types.
@GeekAndDadDad
GeekAndDadDad / confusing.swift
Last active Jul 24, 2020
Computed properties don't call specialized version of functions? Work fine when you call the specialized functions directly but not when those functions are used within a getter or setter it seems… ???
View confusing.swift
// macOS playground source
// swift 5.3, Xcode 12b2
import Cocoa
struct Foo<A> {
var subVal: Any?
let defaultValue: A
init(defaultValue: A) {
@GeekAndDadDad
GeekAndDadDad / detweet.swift
Created Jun 21, 2020 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
View detweet.swift
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@GeekAndDadDad
GeekAndDadDad / ContentView.Swift
Created Apr 3, 2020
Bug? Two `.alert` modifiers mean only last one works?
View ContentView.Swift
//
// ContentView.swift
// TestAlert
//
//
import SwiftUI
struct ContentView: View {
@State private var showAlert1: Bool = false
@GeekAndDadDad
GeekAndDadDad / RemindersListToTextEdit.scpt
Last active Sep 25, 2020
Hacked together AppleScript to get a list from Reminders and make a new TextEdit document with the items in the list suitable for printing.
View RemindersListToTextEdit.scpt
tell application "Reminders"
set listNames to {}
repeat with aList in lists
copy name of aList to end of listNames
end repeat
set listName to choose from list listNames with prompt "Select the list to print:"
-- now find list object for the choosen list
set listToPrint to ""
repeat with aList in lists
@GeekAndDadDad
GeekAndDadDad / ContentView.swift
Last active Feb 15, 2020
Quick hack Mac app to put up a sheet with multi-line text.
View ContentView.swift
import SwiftUI
struct ContentView: View {
@State private var showSheet: Bool = false
@State private var name: String = "Default Name"
var body: some View {
VStack {
Text("Hello, World!")
.frame(maxWidth: .infinity, maxHeight: .infinity)
@GeekAndDadDad
GeekAndDadDad / SampleView.swift
Last active Feb 13, 2020
Sample to show a blog writer a way to do what they wanted (lined up field values) that actually worked. Put this in an iOS app project and you can preview just this view and if you edit the text in the fields you can see it all adjust. Comment in the .border(Color.green) lines to see the frames of the Text views change dynamically as you type :)
View SampleView.swift
//
// ContentView.swift
// bugtest
//
// Copyright © 2020 Geek & Dad, LLC All rights reserved.
//
import SwiftUI
struct PreferenceTest: View {
@GeekAndDadDad
GeekAndDadDad / ContentView.swift
Created Jan 25, 2020
From the blog post "Tiny Hints: a couple of Xcode 11.3 SwiftUI Preview tips"
View ContentView.swift
//
// ContentView.swift
// PreviewsTips2020.01.24
//
// Dad
// @GeekAndDad
//
// Code from blog post:
// https://geekanddad.wordpress.com/2020/01/24/tiny-hints-a-couple-of-xcode-11-3-swiftui-preview-tips/
@GeekAndDadDad
GeekAndDadDad / View_printMessage_playground.swift
Last active Jan 23, 2020
Simple printMessage extension to SwiftUI's View struct
View View_printMessage_playground.swift
// from the blog post: https://geekanddad.wordpress.com/2020/01/23/snippet-swiftui-view-printmessage-extension/
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
VStack {
TestView(label: "hello", idx: 22)
.font(.title)
@GeekAndDadDad
GeekAndDadDad / OpaqueTypesPlayground.swift
Created Jan 10, 2020
macOS playground playing with opaque types & protocols.
View OpaqueTypesPlayground.swift
// paste into new macOS playground
// Xcode 11.3 on 10.15.2
import Cocoa
protocol InfoTypeProtocol {}
protocol Base {
associatedtype InfoType: InfoTypeProtocol
var info: InfoType { get set }