Skip to content

Instantly share code, notes, and snippets.

View pfandrade's full-sized avatar
🏠
Working from home

Paulo Andrade pfandrade

🏠
Working from home
View GitHub Profile
@pfandrade
pfandrade / AnyDecodable.swift
Created February 12, 2020 15:58
AnyDecodable
import Foundation
struct AnyDecodable: Decodable {
static let supportedTypes = CodingUserInfoKey(rawValue: "SupportedTypes")!
enum Errors: Error {
case missingSupportedTypesList
case unknownType
}
@pfandrade
pfandrade / gist:dffeaadd3c34bc217461d88be4999f9a
Created February 6, 2020 14:52 — forked from rmondello/gist:b933231b1fcc83a7db0b
Exporting (iCloud) Keychain and Safari credentials to a CSV file

Exporting (iCloud) Keychain and Safari credentials to a CSV file

After my dad died, I wanted to be able to have access any of his online accounts going forward. My dad was a Safari user and used iCloud Keychain to sync his credentials across his devices. I don’t want to have to keep an OS X user account around just to access his accounts, so I wanted to export his credentials to a portable file.

This is the process I used to create a CSV file of his credentials in the format “example.com,user,pass”. This portable format would be pretty easy to import into 1Password or Safari in the future.

The way I went about this isn’t great; it opens up more opportunities for apps to control one’s Mac through Accessibility APIs, it writes plaintext passwords to disk, and it could use some cleaning up. A better approach might leverage the security command line tool that ships with OS X. That said, I found this method to be a fun illustration of what’s possible us

@pfandrade
pfandrade / DynamicColor.h
Last active February 12, 2022 17:03
Dynamic NSColor subclass to support Dark Mode on macOS prior to 10.13
@interface DynamicColor : NSColor
- (instancetype)initWithAquaColor:(NSColor *)aquaColor
darkAquaColor:(NSColor *__nullable)darkAquaColor;
- (NSColor *)effectiveColor;
@end
@pfandrade
pfandrade / SharedFolder.swift
Last active October 22, 2017 21:51
Getting a readable/writable shared folder on iOS and Simulator
private func sharedFolderURL() -> URL {
if let simulatorSharedDir = ProcessInfo().environment["SIMULATOR_SHARED_RESOURCES_DIRECTORY"] {
// running on the simulator. We'll write to ~/Library/Caches
let simulatorHomeDirURL = URL(fileURLWithPath: simulatorSharedDir)
let cachesDirURL = simulatorHomeDirURL.appendingPathComponent("Library/Caches")
XCTAssertTrue(FileManager.default.isWritableFile(atPath: cachesDirURL.path), "Cannot write to simulator Caches directory")
let sharedFolderURL = cachesDirURL.appendingPathComponent("Secrets")
XCTAssertNoThrow( try FileManager.default.createDirectory(at: sharedFolderURL, withIntermediateDirectories: true, attributes: nil), "Failed to create shared folder \(sharedFolderURL.lastPathComponent) in simulator Caches directory at \(cachesDirURL)")
return sharedFolderURL
@pfandrade
pfandrade / SecretsTouchUITests.swift
Last active October 22, 2017 21:24
Example setup and teardown in Secrets UI tests
class SecretsTouchUITests: XCTestCase {
var testDirectoryURL: URL!
var testDocumentURL: URL!
func documentName() -> String? {
return "testDoc1"
}
override func setUp() {
@pfandrade
pfandrade / SimulatorSharedFolder.swift
Created October 22, 2017 21:14
Retrieving the iOS simulator Library/Caches folder URL
if let simulatorSharedDir = ProcessInfo().environment["SIMULATOR_SHARED_RESOURCES_DIRECTORY"] {
// running on the simulator. We'll write to ~/Library/Caches
let simulatorHomeDirURL = URL(fileURLWithPath: simulatorSharedDir)
let cachesDirURL = simulatorHomeDirURL.appendingPathComponent("Library/Caches")
XCTAssertTrue(FileManager.default.isWritableFile(atPath: cachesDirURL.path), "Cannot write to simulator Caches directory")
let sharedFolderURL = cachesDirURL.appendingPathComponent("Secrets")
XCTAssertNoThrow( try FileManager.default.createDirectory(at: sharedFolderURL, withIntermediateDirectories: true, attributes: nil), "Failed to create shared folder \(sharedFolderURL.lastPathComponent) in simulator Caches directory at \(cachesDirURL)")
return sharedFolderURL
}
@pfandrade
pfandrade / gist:9504524
Created March 12, 2014 10:42
keybase.md
### Keybase proof
I hereby claim:
* I am pfandrade on github.
* I am pfandrade (https://keybase.io/pfandrade) on keybase.
* I have a public key whose fingerprint is 22D1 2FD2 DD3E 2B19 AED6 7F39 FF8F 5187 B1DF 8F8A
To claim this, I am signing this object: