Skip to content

Instantly share code, notes, and snippets.

View mjarvis's full-sized avatar

Malcolm Jarvis mjarvis

  • British Columbia
View GitHub Profile
@mjarvis
mjarvis / reswift-middleware.swift
Created March 14, 2017 16:01
Generic, functional middleware
//: Playground - noun: a place where people can play
import Foundation
public protocol StateType {}
public protocol Action {}
public struct Middleware<S: StateType> {
public typealias DispatchFunction = (Action) -> Void
public typealias GetState = () -> S
@mjarvis
mjarvis / SystemTestActor.swift
Created January 10, 2017 23:02
KIF tester autocomplete in Swift
import UIKit
protocol SystemTestActor {
/*!
@abstract Waits for a specific NSNotification.
@discussion Useful when a test requires an asynchronous task to complete, especially when that task does not trigger a visible change in the view hierarchy.
@param name The name of the NSNotification.
@param object The object to which the step should listen. Nil value will listen to all objects.
@return The detected NSNotification.
@mjarvis
mjarvis / NSHTMLTextDocumentType
Last active October 16, 2017 22:05
This GIST is to help explain the behaviour of NSAttributedString's "initWithData:options:documentAttributes:error:" when used with NSHTMLDocumentType.At first glance, one would expect the output here to be "1, 2, 3", But after some careful reading of the documentation, and if you run the code here, we find that not to be true.
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"3");
});
NSLog(@"1");
[[NSAttributedString alloc] initWithData:[@"<span>html!</span>" dataUsingEncoding:NSUTF8StringEncoding]
options:@{
@mjarvis
mjarvis / Arbitrary rotation of a CGImage
Created December 14, 2011 22:20 — forked from sburlot/Arbitrary rotation of a CGImage
Grayscale for CGContextClipToMask
- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle
{
CGFloat angleInRadians = angle * (M_PI / 180);
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);