Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 00:55 (UTC -04:00)
View GitHub Profile
@wildthink
wildthink / spaceutil.c
Created February 20, 2018 16:55 — forked from camillol/spaceutil.c
Two ways of messing with spaces
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
typedef int CGSConnection;
extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace);
extern OSStatus CGSSetWorkspace(const CGSConnection cid, int workspace);
extern CGSConnection _CGSDefaultConnection(void);
int get_space_id(void);
@wildthink
wildthink / Plist.swift
Created April 18, 2018 02:02
Neatly wrap object->plist->object functions
import Foundation
func reify<T:Codable>(type: T.Type, _ json: String) -> T? {
let data = json.data(using: .utf16)
let nob = try? JSONDecoder().decode(T.self, from: data!)
return nob
}
func plist<T:Codable>(_ nob: T) -> Any? {
guard let data = try? JSONEncoder().encode(nob) else { return nil }
public struct Person {
public var name: String
public var birthday: Date
// In years
public var age: Int {
return Calendar.current.dateComponents([.year], from: birthday, to: Date()).year!
}
}
// Create a Person and use a Waldo get and set some values
// swiftlint:disable variable_name
import Foundation
{% for type in types.based.DynamicType %}
extension {{ type.name }} {
public func waldo() -> Waldo { return _Waldo(this: self) }
class _Waldo: Waldo {
public protocol DynamicType {
func waldo() -> Waldo
}
public protocol Waldo {
func value<T>() -> T?
func type (for key: String) -> Any.Type?
func get<T> (for key: String, default value: T?) -> T?
func set<T> (_ key: String, to value: T?)
}
extension Person {
public fun waldo() -> Waldo { return _Waldo(this: self) }
class _Waldo: Waldo {
var this:Person
private static var type_map: [String:Any.Type] = [
"name": String.self,
"birthday": Date.self,
import Foundation
// Variation of
// https://gist.github.com/vincent-pradeilles/1886454090d18fc0e3c7cfcfd96ad6bb
protocol WithSet {
associatedtype S = Self
func with<T>(_ property: ReferenceWritableKeyPath<S, T>, setTo value: T) -> S
}

[Pitch] Introduce “Dynamic Member” fulfillment of Protocols

Hi All,

To complement the @dynamicMemberLookup feature I think types with dynamic member lookup should automatically be considered to conform to protocol properties that can be satisfied with a dynamicMember subscript.

protocol PersonProtocol {
    var name: String
 var birthdate: Date
@wildthink
wildthink / Swift – func deepDescription
Last active July 20, 2018 20:31 — forked from mhuusko5/Swift – func deepDescription
Swift – func deepDescription(any: Any) -> String (pretty print any object, recursively)
func deepDescription(_ any: Any) -> String {
guard let any = deepUnwrap(any) else {
return "nil"
}
if any is Void {
return "Void"
}
if let int = any as? Int {
@wildthink
wildthink / NSXMLNode+TAL.h
Created August 15, 2018 03:44
Tagged Attribute Langage
//
// NSXMLNode+TAL.h
// WTTAL
//
// Created by Jason Jobe on 10/29/05.
// Copyright (c) 2005, 2013 Jason Jobe. All rights reserved.
//
#import <Foundation/Foundation.h>