This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ Returns an iterator containing the primary (built-in) Ethernet interface. The caller is responsible for | |
// releasing the iterator after the caller is done with it. | |
func FindEthernetInterfaces() -> io_iterator_t? { | |
let matchingDictUM = IOServiceMatching("IOEthernetInterface"); | |
// Note that another option here would be: | |
// matchingDict = IOBSDMatching("en0"); | |
// but en0: isn't necessarily the primary interface, especially on systems with multiple Ethernet ports. | |
if matchingDictUM == nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makePNGFromView(view: NSView) { | |
var rep = view.bitmapImageRepForCachingDisplayInRect(view.bounds)! | |
view.cacheDisplayInRect(view.bounds, toBitmapImageRep: rep) | |
if let data = rep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) { | |
data.writeToFile("/xxx/image.png", atomically: false) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func flag(country: String) -> String { | |
let base = 127397 // Root Unicode flags index | |
var usv = String.UnicodeScalarView() // Prepare a Unicode string | |
for i in country.utf16 { // Loop over the country acronym letters | |
let inc = Int(i) // The letter's ASCII index | |
let code = UnicodeScalar(base + inc) // Shift the letter index to the flags index | |
usv.append(code) // Append the grapheme to the Unicode string | |
} | |
return String(usv) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OSXVersion { | |
class func getOSXVersionNumber() -> (major: Int, minor: Int) { | |
let version = NSProcessInfo.processInfo().operatingSystemVersion | |
return (version.majorVersion, version.minorVersion) | |
} | |
class func getOSXVersionName(major major: Int, minor: Int) -> String { | |
if major == 10 { | |
switch minor { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import XCPlayground | |
import Accelerate | |
extension UIImage { | |
public func blur(size: Float) -> UIImage! { | |
let boxSize = size - (size % 2) + 1 | |
let image = self.CGImage | |
let inProvider = CGImageGetDataProvider(image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getSystemUUID() -> String? { | |
let dev = IOServiceMatching("IOPlatformExpertDevice") | |
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev) | |
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey, kCFAllocatorDefault, 0) | |
IOObjectRelease(platformExpert) | |
let ser: CFTypeRef = serialNumberAsCFString.takeUnretainedValue() | |
if let result = ser as? String { | |
return result | |
} | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URLQueryAllowedCharacterSet | |
!$&'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ | |
URLHostAllowedCharacterSet | |
!$&'()*+,-.0123456789:;=ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz~ | |
URLPathAllowedCharacterSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* HTTPDownloader.hpp | |
* | |
* A simple C++ wrapper for the libcurl easy API. | |
* | |
* Written by Uli Köhler (techoverflow.net) | |
* Published under CC0 1.0 Universal (public domain) | |
*/ | |
#ifndef HTTPDOWNLOADER_HPP | |
#define HTTPDOWNLOADER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | |
extension Array { | |
func splitBy(subSize: Int) -> [[Element]] { | |
return 0.stride(to: self.count, by: subSize).map { startIndex in | |
let endIndex = startIndex.advancedBy(subSize, limit: self.count) | |
return Array(self[startIndex ..< endIndex]) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func resize(image: NSImage, w: Int, h: Int) -> NSImage { | |
var destSize = NSMakeSize(CGFloat(w), CGFloat(h)) | |
var newImage = NSImage(size: destSize) | |
newImage.lockFocus() | |
image.drawInRect(NSMakeRect(0, 0, destSize.width, destSize.height), fromRect: NSMakeRect(0, 0, image.size.width, image.size.height), operation: NSCompositingOperation.CompositeSourceOver, fraction: CGFloat(1)) | |
newImage.unlockFocus() | |
newImage.size = destSize | |
return NSImage(data: newImage.TIFFRepresentation!)! | |
} |
NewerOlder