Skip to content

Instantly share code, notes, and snippets.

View mackross's full-sized avatar

Andrew Mackross mackross

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mackross on github.
  • I am mackross (https://keybase.io/mackross) on keybase.
  • I have a public key ASCwqcO__kOzzSykc-u0HQkuc9PR8aaT8snAZGwypf4mqgo

To claim this, I am signing this object:

#!/bin/bash
# RESULTS, feel free to repro yourself
#
# noLock FAIL
# accessShare FAIL
# rowShare FAIL
# rowExclusive FAIL
# shareUpdateExclusive SUCCESS
# share FAIL+DEADLOCKS
# shareRowExclusive SUCCESS
@mackross
mackross / main.go
Created May 15, 2015 06:20
go-count-inversions
// Recursive count array inversions O(n.log(n))
package main
import "fmt"
func main() {
a := []int{2, 1, 4, 3, 6, 5}
fmt.Println(a, "has", count(a), "inversions.")
}
@mackross
mackross / main.go
Last active August 29, 2015 14:21
go-merge-sort
// Recursive merge sort O(n.log(n))
package main
import "fmt"
func main() {
a := []int{9, 3, 4, 8, 4, 5, 1, 2, 6, 7, 0, 4}
fmt.Printf("%v sorted is %v\n", a, sort(a))
}
/// like XCTAssertEqual, but handles optional unwrapping
public func XCTAssertEqualOptional<T: Any where T: Equatable>(expression1: @autoclosure () -> T?, expression2: @autoclosure () -> T?, _ message: String? = nil, file: String = __FILE__, line: UInt = __LINE__) {
if let exp1 = expression1() {
if let exp2 = expression2() {
XCTAssertEqual(exp1, exp2, message ?? "", file: file, line: line)
} else {
XCTFail(message ?? "exp1 != nil, exp2 == nil", file: file, line: line)
}
} else if let exp2 = expression2() {
XCTFail(message ?? "exp1 == nil, exp2 != nil", file: file, line: line)
@mackross
mackross / gist:5630857
Last active December 17, 2015 15:19
RACBinding between UITextfield and a target that sends a signal when the text is changed programatically or using the keyboard.
- (RACSignal *)bindTextfield:(UITextField *)textField target:(id)target keypath:(NSString *)keypath
{
textField.text = [target valueForKey:keypath];
RACObservablePropertySubject *textFieldTextProperty = [RACObservablePropertySubject propertyWithTarget:textField keyPath:@keypath(textField,text)];
RACSignal *textFieldEdited = [textField rac_textSignal];
[[textFieldTextProperty binding] bindTo:[[RACObservablePropertySubject propertyWithTarget:target keyPath:keypath] binding]];
[target rac_deriveProperty:keypath from:[textFieldEdited skip:1]];
RACSignal *textValue = [[RACSignal merge:@[ textFieldEdited, textFieldTextProperty ]] distinctUntilChanged];
return textValue;
@mackross
mackross / GTKeyboardHelperDemo
Created December 17, 2012 15:05
Install & Run GTKeyboardHelper Demo
git clone https://github.com/mackross/GTKeyboardHelper.git ~/Desktop/DeleteLater && open '~/DeleteLater/Keyboard Helper Demo.xcodeproj'
@mackross
mackross / objc-core-animation-shake
Created February 3, 2012 03:50
Core Animation Shake
- (void)shakeAnimation:(CALayer*)layer
{
CGPoint pos = layer.position;
static int numberOfShakes = 3;
static CGFloat vigourOfShake = 0.055;
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, pos.x, pos.y);
int index;