This file contains hidden or 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 Foundation | |
| typealias CancelableTask = (cancel: Bool) -> Void | |
| func delay(time: NSTimeInterval, work: dispatch_block_t) -> CancelableTask? { | |
| var finalTask: CancelableTask? | |
| var cancelableTask: CancelableTask = { cancel in | |
| if cancel { |
This file contains hidden or 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
| // It's tested on ios 8.2 .. | |
| // Apple document about virtual memory: | |
| // Both OS X and iOS include a fully-integrated virtual memory system that you cannot turn off; it is always on. | |
| // https://developer.apple.com/library/mac/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html | |
| // Discussing mmap on ios: | |
| // http://stackoverflow.com/questions/13425558/why-does-mmap-fail-on-ios | |
| // http://stackoverflow.com/questions/9184773/is-there-a-practical-limit-on-the-number-of-memory-mapped-files-in-ios | |
| #include <sys/mman.h> |
This file contains hidden or 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 containsEmoji(text: String) -> Bool { | |
| var containsEmoji = false | |
| for scalar in text.unicodeScalars { | |
| switch scalar.value { | |
| case 0x1F600...0x1F64F: | |
| // Emoticons | |
| containsEmoji = true | |
| case 0x1F300...0x1F5FF: | |
| // Misc Symbols and Pictographs | |
| containsEmoji = true |
This file contains hidden or 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
| struct Random { | |
| static func within<B: protocol<Comparable, ForwardIndexType>>(range: ClosedInterval<B>) -> B { | |
| let inclusiveDistance = range.start.distanceTo(range.end).successor() | |
| let randomAdvance = B.Distance(arc4random_uniform(UInt32(inclusiveDistance.toIntMax())).toIntMax()) | |
| return range.start.advancedBy(randomAdvance) | |
| } | |
| static func within(range: ClosedInterval<Float>) -> Float { | |
| return (range.end - range.start) * Float(Float(arc4random()) / Float(UInt32.max)) + range.start | |
| } |
This file contains hidden or 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
| // meet Stringy - a simple string type with a fluent interface | |
| struct Stringy { | |
| let content: String | |
| init(_ content: String) { | |
| self.content = content | |
| } | |
| func append(appendage: Stringy) -> Stringy { |
This file contains hidden or 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
| // Playground - noun: a place where people can play | |
| import Foundation | |
| typealias Byte = UInt8 | |
| protocol GenericIntegerType: IntegerType { | |
| init(_ v: Int) | |
| init(_ v: UInt) | |
| init(_ v: Int8) |
This file contains hidden or 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
| /* | |
| Copyright (c) 2015 Kristopher Johnson | |
| Permission is hereby granted, free of charge, to any person obtaining | |
| a copy of this software and associated documentation files (the | |
| "Software"), to deal in the Software without restriction, including | |
| without limitation the rights to use, copy, modify, merge, publish, | |
| distribute, sublicense, and/or sell copies of the Software, and to | |
| permit persons to whom the Software is furnished to do so, subject to | |
| the following conditions: |
This file contains hidden or 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
| /** | |
| * This software is in the public domain. Where that dedication is not recognized, | |
| * you are granted a perpetual, irrevokable license to copy and modify this file | |
| * as you see fit. | |
| * | |
| * Requires SDL 2.0.4. | |
| * Devices that do not support Metal are not handled currently. | |
| **/ | |
| #import <UIKit/UIKit.h> |
This file contains hidden or 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 func folderSize(folderPath:String) -> UInt{ | |
| // @see http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder | |
| let filesArray:[String] = NSFileManager.defaultManager().subpathsOfDirectoryAtPath(folderPath, error: nil)! as [String] | |
| var fileSize:UInt = 0 | |
| for fileName in filesArray{ | |
| let filePath = folderPath.stringByAppendingPathComponent(fileName) | |
| let fileDictionary:NSDictionary = NSFileManager.defaultManager().attributesOfItemAtPath(filePath, error: nil)! |
This file contains hidden or 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
| // Alamofire.swift | |
| // | |
| // Copyright (c) 2014 Alamofire (http://alamofire.org) | |
| // | |
| // Permission is hereby granted, free of charge, to any person obtaining a copy | |
| // of this software and associated documentation files (the "Software"), to deal | |
| // in the Software without restriction, including without limitation the rights | |
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| // copies of the Software, and to permit persons to whom the Software is | |
| // furnished to do so, subject to the following conditions: |