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
protocol URLSessionProtocol { | |
func dataTask(with url: URL, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTaskProtocol | |
} | |
protocol URLSessionDataTaskProtocol { | |
func resume() | |
} | |
extension URLSessionDataTask: URLSessionDataTaskProtocol {} |
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 UIKit | |
extension Dictionary { | |
init<S: Sequence>(_ pairs: S) where S.Iterator.Element == (Key, Value) { | |
self = [:] | |
for (k,v) in pairs { self[k] = v } | |
} | |
func keyValueMap<T: Hashable, S>(_ transform: (Key, Value) throws -> (T, S)) rethrows -> [T: S] { | |
var newDict = [T: S]() |
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
@interface MyObject : NSObject | |
@property (copy) NSString *myProperty; | |
@end | |
@interface MyObject (Category) | |
- (NSNumber *)myProperty; |
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 f(a a: Int = 0, b: Int = 0, c: Int, d: Int = 0, e: Int = 0) -> (Int, Int, Int, Int, Int){ | |
return (a, b, c, d, e) | |
} | |
f(c:3) | |
f(a:1, c:3) | |
f(b:2, c:3) | |
f(a:1, b:2, c:3) | |
f(b:2, a:1, c:3) | |
f(b:2, c:3, a:1) //Bad |
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
1. Need to recognise it's a train ticket | |
2. Need to recognise it's a train ticket to Aberystwyth | |
3. Need to recognise the date on the ticket | |
4. Need to know that the destination and date means it was for travelling to a conference | |
5. Needs to know that I run a business, and conference travel is a business expense, so needs to be classed as a receipt | |
6. Needs to know I want to view receipts by year and month | |
7. Needs to know by "year" I mean my company accounting year, not calendar year | |
8. Needs to know my company accounting year |
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 <AppKit/AppKit.h> | |
/** | |
* This seems to work fine, if repeat count is 0 then repeatCount is set to another values. However it doesn't seem to match HUGE_VALF | |
*/ | |
void basicRepeatCount() | |
{ | |
NSInteger repeatCount = 0; | |
if (repeatCount == 0) { | |
repeatCount = HUGE_VALF; |
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
I was rather disheartened to read last night that David Cameron's ridiculous comments from before the election wanting to ban encryption may actually be put forward in a bill (http://uk.businessinsider.com/david-cameron-encryption-back-doors-iphone-whatsapp-2015-7). | |
I wanted to write to you to urge you to oppose this if the government do attempt to make it law. Strong encryption is the foundation of our economy, our right to privacy and our personal and national security in a digital world. Encryption is key to ensuring that the data we store on computers or send between them is only seen by the right people. | |
There are two proposals that have been floated, both of which are technically flawed (if not impossible) and could have devastating effects on our country. The first is to provide backdoors in encryption for law enforcement and security agencies, the second is to ban encryption outright. The first option is technically impossible, as any backdoor is then available to everyone and so has the same effect |
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | |
<dependencies> | |
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/> | |
</dependencies> | |
<objects> | |
<customObject id="-2" userLabel="File's Owner"/> | |
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | |
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | |
<customView id="c22-O7-iKe"> |
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
#include <stdbool.h> | |
struct rxt_enumerator_state { | |
rxt_node *node; | |
bool leftFinished; | |
bool rightFinished; | |
bool returned; | |
rxt_enumerator_state *previousState; | |
} |
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
//We use a typedef to make things simpler | |
typedef void (*rxt_enumerator)(char *key, char *value); | |
void rxt_enumerate_node(rxt_node *root, rxt_enumerator callback) { | |
if (!root) return; | |
if (root->color) { | |
if (root->color == 2) root = root->value; | |
//All we change is that instead of printing out, we now call the function supplied to us | |
if (callback) callback(root->key, root->value); |