Skip to content

Instantly share code, notes, and snippets.

View onmyway133's full-sized avatar
๐Ÿ˜‡
What you don't know is what you haven't learned

Khoa onmyway133

๐Ÿ˜‡
What you don't know is what you haven't learned
View GitHub Profile
@onmyway133
onmyway133 / FRP iOS Learning resources.md
Last active August 29, 2015 14:27 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP in iOS links.

Videos

@onmyway133
onmyway133 / gist:5f7ffb48feb20fbcbdc3
Last active August 29, 2015 14:27 — forked from learncodeacademy/gist:5f84705f2229f14d758d
Getting Started with Vagrant, SSH & Linux Server Administration
@onmyway133
onmyway133 / iOS 9 App Transport Security.md
Last active August 28, 2015 02:35 — forked from vinhnx/iOS 9 App Transport Security.md
iOS 9 App Transport Security

iOS 9 App Transport Security

Starting from iOS 9, App Transport Security enforces to use secure HTTPS requests by default.

App Transport Security

App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether youโ€™re creating a new app or updating an existing one.

If youโ€™re developing a new app, you should use HTTPS exclusively. If you have an existing app, you

@onmyway133
onmyway133 / Monad.swift
Last active September 20, 2015 16:36 — forked from andelf/Monad.swift
Monad in Swift
// Monad
operator infix >>= {
precedence 10
associativity left
}
struct _MReturn {
}
@transparent func _mreturn<Args>(a: Args) -> (_MReturn, Args) {
return (_MReturn(), a)
import Foundation
struct Box<T> {}
protocol Functor {
typealias A
typealias B
typealias Boxed = Box<B>
func fmap<B>(f: A -> B) -> Boxed

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. As of Swift 1.2 and Xcode 6.3, this is no longer very fragile.

Unfortunately, the compiler cannot verify the types when passing a function to (>>=). We have to wrap the function in a closure and call it with an explicit argument to compile.

optionalDoubles >>= squareRoot // doesn't compile
optionalDoubles >>= { squareRoot($0) } // compiles
@onmyway133
onmyway133 / NSHashTable+SequenceType.swift
Created September 28, 2015 09:07 — forked from almostintuitive/NSHashTable+SequenceType.swift
Use NSHashTable with for .. in .. style enumeration with Swift2 (safely)
extension NSHashTable: SequenceType {
public func generate() -> AnyGenerator<AnyObject> {
var array = self.allObjects
var nextIndex = array.count-1
return anyGenerator {
if (nextIndex < 0) {
return nil
import Cocoa
enum CoroutineState {
case Fresh, Running, Blocked, Canceled, Done
}
struct CoroutineCancellation: ErrorType {}
class CoroutineImpl<InputType, YieldType> {
let body: (yield: YieldType throws -> InputType) throws -> Void
@onmyway133
onmyway133 / gist:5360b88171541a7109f5
Created November 15, 2015 08:13 — forked from ccgus/gist:6324222
Custom SQLite Functions
[db makeFunctionNamed:@"UTTypeConformsTo" maximumArguments:2 withBlock:^(sqlite3_context *context, int argc, sqlite3_value **argv) {
if (sqlite3_value_type(argv[0]) == SQLITE_TEXT) {
const unsigned char *a = sqlite3_value_text(argv[0]);
const unsigned char *b = sqlite3_value_text(argv[1]);
CFStringRef as = CFStringCreateWithCString(nil, (const char*)a, kCFStringEncodingUTF8);
CFStringRef bs = CFStringCreateWithCString(nil, (const char*)b, kCFStringEncodingUTF8);
sqlite3_result_int(context, UTTypeConformsTo(as, bs));
import Foundation
// Generic Error
public struct Error: ErrorType {let reason: String}
/**
Printing version of try? Call either with standard or autoclosure approach
```
let contents = attempt{try NSFileManager.defaultManager().contentsOfDirectoryAtPath(fakePath)}
let contents = attempt{try NSFileManager.defaultManager().contentsOfDirectoryAtPath(XCPlaygroundSharedDataDirectoryURL.path!)}