Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff jverkoey

View GitHub Profile
@jverkoey
jverkoey / thingsimport.rb
Last active January 26, 2018 15:59 — forked from byingyang/gist:181626
Update for Things 2.2's use of Projects instead of Areas.
# format:
# --------------
# date (mm/dd/yy)
# assignment
# assignment
# ...
#
# date
# assignment
# ...
@jverkoey
jverkoey / NSManagedObjectContext+DebugSwizzling.m
Created April 14, 2014 11:52
Core Data Managed Object Context Debugging
// NSManagedObjectContext+DebugSwizzling.h
#import <CoreData/CoreData.h>
#if DEBUG
/**
* Toggles debugging of Core Data managed object contexts.
*
* When enabled, will fire NSLogs in the following cases:
@jverkoey
jverkoey / stream.swift
Last active December 16, 2017 07:52
Stream prototype in swift
/**
An Observable emits values to its subscribed observers.
A minimal implementation based upon the reactivex specification:
http://reactivex.io/documentation/observable.html
*/
public class Observable<Value> {
/** Add a new observer. The provided instance will receive all values provided to onNext. */
public func subscribe(_ observer: @escaping (Value) -> Void) -> Observable<Value> {
observers.append(observer)
@jverkoey
jverkoey / gist:2985830
Created June 25, 2012 01:03
Memory mapping in Objective-C
const char* cstr = [string UTF8String];
void* anon = mmap(0, sizeof(char) * (string.length + 1), PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, 0, 0);
if (anon == MAP_FAILED) {
NSLog(@"Failed to map memory.");
return;
}
strcpy(anon, cstr);
// How do I get a file descriptor for use here?
func start(with context: TransitionContext) {
guard let contextView = backDelegate.backContextView(for: self,
with: context.foreViewController) else {
return
}
guard let foreImageView = foreDelegate.foreContextView(for: self) else {
return
}
/*
Copyright 2017-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@jverkoey
jverkoey / DirectlyManipulable.swift
Created April 12, 2017 18:25
Directly manipulable constraints
public final class DirectlyManipulable {
public func add(to view: UIView, withRuntime runtime: MotionRuntime, constraints: NoConstraints)
public final class Constraints {
public var draggable: ConstraintApplicator<T>?
public var rotatable: ConstraintApplicator<T>?
public var scalable: ConstraintApplicator<T>?
}
}
@jverkoey
jverkoey / NIVector.h
Created December 29, 2014 22:40
CGVector helper methods
CGVector NIVectorMakeWithPoints(CGPoint fromPoint, CGPoint toPoint);
CGVector NIVectorMakeWithPoint(CGPoint point);
CGPoint NIPointMakeWithVector(CGVector vector);
NSString* NIStringFromVector(CGVector vector);
CGFloat NIVectorLength(CGVector vector);
CGFloat NIRadiansFromReferenceVectorToVector(CGVector vector);
CGFloat NIVectorDotProduct(CGVector vector1, CGVector vector2);
extern const CGVector NIReferenceVector;
public func openValve<O: MotionObservableConvertible>(whenAllTrue observables: [O]) -> MotionObservable<T> where O.T == Bool {
return MotionObservable<T> { observer in
var upstreamSubscription: Subscription?
var connectUpstream = {
upstreamSubscription = self.asStream().subscribe(next: observer.next,
state: observer.state,
coreAnimation: observer.coreAnimation)
}
let square2Reactive = runtime.get(square2.layer)
let pan = runtime.get(UIPanGestureRecognizer())
let rawPosition = createProperty(withInitialValue: square2.layer.position)
runtime.add(pan.translated(from: rawPosition, in: view), to: rawPosition)
runtime.add(rawPosition.y().rubberBanded(below: 50, above: 400, length: 100), to: square2Reactive.positionY)