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 / 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 / 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 / Router.swift
Created February 15, 2016 10:56
Uploading a file with SWIFT via POST multipart/form-data (PHP)
import Foundation
import Alamofire
public enum Router:URLRequestConvertible {
public static let baseUrlString:String = "http://testapi.example.com"
case Upload(fieldName: String, fileName: String, mimeType: String, fileContents: NSData, boundaryConstant:String);
var method: Alamofire.Method {
switch self {
case Upload:
//
// OrdinalNumberFormatter.swift
// Tastify
//
// Created by Ian Grossberg on 10/1/15.
// Copyright © 2015 Noble Desktop. All rights reserved.
//
import Foundation
@mingsai
mingsai / gist:9db593f182a11235d8c3
Created February 16, 2016 13:58 — forked from casademora/gist:d06e69288fb24c9ace6e
Extension to writeTo NSOutputStream
extension String
{
func writeTo(outputStream:NSOutputStream)
{
if let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
{
let bytes = ConstUnsafePointer<UInt8>(data.bytes)
outputStream.write(bytes, maxLength: data.length)
}
}
@mingsai
mingsai / MultiExporter.jsx
Created May 1, 2016 14:49 — forked from TomByrne/MultiExporter.jsx
An Illustrator script for exporting layers and/or artboards into separate files (PNG8 / PNG24 / EPS / PDF / SVG / JPG / FXG).See http://www.tbyrne.org/export-illustrator-layers-to-svg-files
// MultiExporter.jsx
// Version 0.1
// Version 0.2 Adds PNG and EPS exports
// Version 0.3 Adds support for exporting at different resolutions
// Version 0.4 Adds support for SVG, changed EPS behaviour to minimise output filesize
// Version 0.5 Fixed cropping issues
// Version 0.6 Added inner padding mode to prevent circular bounds clipping
//
// Copyright 2013 Tom Byrne
// Comments or suggestions to tom@tbyrne.org