Skip to content

Instantly share code, notes, and snippets.

View mingsai's full-sized avatar
🎯
Focusing

Tommie N. Carter, Jr. mingsai

🎯
Focusing
View GitHub Profile
@mingsai
mingsai / MNGCountryData.swift
Created February 12, 2016 18:15
A Swift class to manage telephone calling data for all countries.
//
// MNGCountryData.swift
//
//
// Created by Tommie N. Carter, Jr., MBA on 2/4/16.
// Copyright © 2016 MING Technology. All rights reserved.
//
import Foundation
@mingsai
mingsai / MNGContactsManager.swift
Created February 12, 2016 18:20
A Swift singleton to manage the new contacts framework in iOS8+
//
// MNGContactsManager.swift
//
//
// Created by Tommie N. Carter, Jr., MBA on 8/1/15.
// Copyright © 2015 MING Technology. All rights reserved.
//
import UIKit
import ContactsUI
@mingsai
mingsai / IO.swift
Last active February 12, 2016 19:33 — forked from alecthomas/IO.swift
A Swift class to use low-level I/O efficiently. Requires attached Swift String extensions to compensate for missing API calls in Swift 2.2 (specifically the .NS namespace to link to NSString.
//
// IO.swift
//
//
// Created by Tommie N. Carter, Jr., MBA on 2/12/16.
// Copyright © 2016 MING Technology. All rights reserved.
//
// Based on work of:
//
// Swift.IO
@mingsai
mingsai / ExceptionCatcher.h
Created February 12, 2016 19:08
An objective c exception block to throw exceptions.
//
// ExceptionCatcher.h
//
#import <Foundation/Foundation.h>
NS_INLINE NSException * _Nullable tryBlock(void(^_Nonnull tryBlock)(void)) {
@try {
tryBlock();
}
@mingsai
mingsai / NSStream.swift
Created February 12, 2016 19:40 — forked from ishikawa/NSStream.swift
Generic read/write method
extension NSInputStream {
func read<T : Integer>() -> T? {
var buffer : T = 0
let n = withUnsafePointer(&buffer) { (p) in
self.read(UnsafePointer<UInt8>(p), maxLength: sizeof(T))
}
if n > 0 {
import Foundation
let bufferSize = 1024*1024
enum Error: ErrorType {
case UnknownArgument(String)
case MissingValue(String)
case MissingPassword
case ShortWrite
case ReadError(NSError?)
@mingsai
mingsai / JSON.swift
Created February 12, 2016 19:42 — forked from jparishy/JSON.swift
//
// JSON.swift
// Swerver
//
// Created by Julius Parishy on 12/12/15.
// Copyright © 2015 Julius Parishy. All rights reserved.
//
import Foundation
@mingsai
mingsai / NSObject+PublicClass.swift
Created February 12, 2016 19:44
Determine if a random NSObject subclass instance is a public or private framework (does not test for your objects)
import Foundation
extension NSObject {
var isPublicClass: Bool {
return self.dynamicType.isPublicClass
}
class var isPublicClass: Bool {
return _PUBLIC_IOS_CLASSES.contains(NSStringFromClass(self))
}
@mingsai
mingsai / unzip.swift
Created February 13, 2016 06:16 — forked from kristopherjohnson/unzip.swift
zip(), zip3(), unzip(), and unzip3() for Swift
// Given array of 2-tuples, return two arrays
func unzip<T, U>(array: [(T, U)]) -> ([T], [U]) {
var t = Array<T>()
var u = Array<U>()
for (a, b) in array {
t.append(a)
u.append(b)
}
return (t, u)
}
@mingsai
mingsai / MNGStreamReaderWriter.swift
Last active August 2, 2021 16:13
A Stream Reader / Writer that takes two URLs and copies from source to target without exceeding memory limits.
//
// MNGStreamReaderWriter.swift
// ths
//
// Created by Tommie N. Carter, Jr., MBA on 2/14/16.
// Copyright © 2016 MING Technology. All rights reserved.
//
import Foundation
import Darwin.Mach.mach_time