Skip to content

Instantly share code, notes, and snippets.

@oliverfoggin
oliverfoggin / MyImageDownloader.h
Created November 7, 2013 09:43
NSURLConnection download with progress callbacks
@protocol MyImageDownloaderDelegate <NSObject>
- (void)downloadFailed;
- (void)imageDownloadFinished:(UIImage *)image;
- (void)progressUpdated:(CGFloat)progress;
@end
@interface MyImageDownloader : NSObject
@oliverfoggin
oliverfoggin / viewWithTextIn.m
Last active March 9, 2016 06:53
How to centre text using drawInRect...
//Create the rect you would like your text to be inside of...
CGRect maxTextRect = CGRectMake(0, 0, 200, 60);
//Create the attributed string
NSAttributedString *theString = //... do all the setup.
//Find the rect that the string will draw into **inside the maxTextRect**
CGRect actualRect = [theString boundingRectWithSize:maxTextRect.size options:NSStringDrawingUsesLineFragmentOrigin context:nil];
//Offset the actual rect inside the maxTextRect

Roller Derby MMR test doc

As a roller derby ref I love looking at the stats.

I put this together to teach myself Neo4j a bit but also to get some decent stats out of a practise game.

Node Types

  • Skater: All of the skaters

    • Properties: Name and number.

@oliverfoggin
oliverfoggin / Neo4j MRDWC.adoc
Last active August 29, 2015 13:57
MRDWC Neo4j gist

MRDWC Neo4j gist

I’ve been watching the Men’s Roller Derby World Cup today so thought I’d get some info out of what’s going on.

Still ne to Neo4j so still learning and playing around with it to see what I can do with it.

Node Types

  • (Group {name:""})

  • (Team {name:""})

  • (Game {day:1, time:1000})

@oliverfoggin
oliverfoggin / gist:9743873
Last active August 29, 2015 13:57
Search for a book by its cover
== Search for a book by its cover
Playing on the saying "Don't judge a book by its cover" I created this so that if you see a book online or in a shop but you forget what it's called you can find it by recalling details about the cover.
//hide
//setup
[source, cypher]
----
//publishers
@oliverfoggin
oliverfoggin / gist:10024117
Last active August 29, 2015 13:58
Failing UISearchDisplayController
#import "UserSearchViewController.h"
@interface UserSearchViewController () <UISearchBarDelegate, UISearchDisplayDelegate>
@end
@implementation UserSearchViewController
- (void)viewDidLoad
{
@oliverfoggin
oliverfoggin / gist:0569e25ec93a0cc38187
Last active August 29, 2015 14:21
Programmin Challenge: the position of the element (Messing around in Swift)
import UIKit
// binary search function to find position
func findPositionInArray<T: Comparable>(array: [T], value: T) -> Int {
var lowerIndex = 0
var upperIndex = array.count - 1
while lowerIndex < upperIndex {
let currentIndex = lowerIndex + Int(Double(upperIndex - lowerIndex) * 0.5)
let currentValue = array[currentIndex]
@oliverfoggin
oliverfoggin / gist:e22aa20675e68f17a163
Last active August 29, 2015 14:22
Towers of hanoi
// Challenge set here...
// https://blog.svpino.com/2015/06/07/programming-challenge-towers-of-hanoi
import UIKit
// convenience for printing
func moveRing(ring : Int, currentPole: Int, targetPole: Int) {
println("Move ring \(ring) from pole \(currentPole) to pole \(targetPole)")
}
enum Router: URLRequestConvertible {
static let baseURLString = "http://someURL.co.uk"
static var OAuthToken: String? {
didSet {
// save token to keychain
}
}
case AuthCheck
@oliverfoggin
oliverfoggin / GKRuleSystemValidator.swift
Last active December 7, 2016 11:51
GameplayKit GKRuleSystem Validator
import Foundation
import GameplayKit
enum ValidationResult<T: Error> {
case valid
case invalid(error: T)
}
class Fact<T: Error>: NSObject {
let error: T