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
// MIT licensed. | |
use std::net::TcpStream; | |
use std::io::{Read, Write}; | |
use std::sync::mpsc::channel; | |
use std::thread; | |
fn main() { | |
let mut stream = TcpStream::connect("127.0.0.1:7496").expect("connect"); | |
stream.set_nodelay(true).expect("nodelay"); // Because we're wannabe HFT traders. |
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
find . -type f \( -name '*ViewController.m' -or -name '*ViewController.swift' \) -exec grep -L -e 'preferredStatusBarStyle' {} + |
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 Foundation | |
// Simple observable property | |
// Careful: Not thread safe! You should use this only from the main thread, or modify to | |
// have locks. | |
class Property<T> { | |
private var _value: T | |
var value: T { | |
get { return _value } | |
set { |
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 Foundation | |
import Security | |
struct SecItemWrapper { | |
static func matching(query: NSDictionary) -> (status: Status, result: AnyObject?) { | |
var rawResult: Unmanaged<AnyObject>? | |
let rawStatus = SecItemCopyMatching(query, &rawResult) | |
let result: AnyObject? = rawResult?.takeRetainedValue() | |
let status = Status.fromOSStatus(rawStatus) | |
return (status, result) |
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
// | |
// Keychain.swift | |
// SwiftKeychain | |
// | |
// Created by Chris Hulbert on 14/06/2015. | |
// Copyright (c) 2015 Chris Hulbert. All rights reserved. | |
// | |
import Foundation | |
import Security |
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 Foundation | |
/// Since there can be multiple delegates, they can only be used to signifying events (output), not for | |
/// supplying data for the manager (input). | |
@objc protocol MyManagerDelegate { | |
func manager(manager: MyManager, isNowLoading: Bool) | |
} | |
@objc class MyManager { |
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 | |
extension UIColor { | |
/// Creates a UIColor from an 'rrggbb' hex string. | |
class func fromHex(hexColour: String) -> UIColor { | |
let str = hexColour.cStringUsingEncoding(NSUTF8StringEncoding) | |
let x = strtol(str!, nil, 16) | |
let r = x >> 16 | |
let g = (x >> 8) & 0xff |
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
!!! There's a better solution here now, that doesn't require swizzling: | |
!!! http://www.splinter.com.au/2014/09/10/afnetworking-error-bodies/ | |
!!! But i'll leave the below swizzling solution up for old time's sake | |
// AFURLSessionManager+ErrorResponse.h | |
// This hacks AFURLSessionManager so that it returns the error response in failure callbacks, in the error's userInfo. | |
// Usage: | |
// [mySessionManager POST:@"some_api_endpoint" parameters:params success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) { |
NewerOlder