Skip to content

Instantly share code, notes, and snippets.

View chillpop's full-sized avatar

Carl Hill-Popper chillpop

View GitHub Profile
#!/usr/bin/env python
from json import load
from collections import defaultdict, deque, namedtuple
# handle transaction cancellations
# disallow payments with insufficient balance
# (- allow deferred up to ... time)
# handle payments to (but not from) unknown accounts
@chillpop
chillpop / Dictionary+Enum.swift
Last active August 8, 2022 10:12
swift Dictionary subscript with String enum
protocol StringEnum {
var rawValue: String { get }
}
extension Dictionary {
subscript(enumKey: StringEnum) -> Value? {
get {
if let key = enumKey.rawValue as? Key {
return self[key]
}
@chillpop
chillpop / async-unit-tests.m
Last active August 29, 2015 14:00
Asynchronous unit test helpers
@property (nonatomic, strong) dispatch_semaphore_t waitSemaphore
- (void)setUp {
[super setUp];
// Set-up code here.
self.waitSemaphore = dispatch_semaphore_create(0);
}
@chillpop
chillpop / unique ID
Created May 17, 2013 15:25
Create, store, and retrieve a unique iOS device ID using the appropriate technology.
//get a unique ID
NSString *deviceID = nil;
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(identifierForVendor)]) {
deviceID = [[device identifierForVendor] UUIDString];
}
else {
//retrieve an NSDefaults stored UUID
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *uuidKey = @"UUID";