Skip to content

Instantly share code, notes, and snippets.

View smic's full-sized avatar

Stephan Michels smic

View GitHub Profile
@smic
smic / Test.swift
Created July 25, 2015 11:58
First trial to implement lenses for any type
public struct Lense<T: AnyObject,V: Any> {
public let getter: () -> V
public let setter: (value: V) -> ()
init(getter: () -> V, setter: (value: V) -> ()) {
self.getter = getter;
self.setter = setter;
}
}
@smic
smic / NSControl+SMTriggerAction.m
Created July 29, 2014 22:08
Send control value back to controller over binding
@implementation NSControl (SMTriggerAction)
- (void)triggerAction {
[self sendAction:self.action to:self.target];
for (NSValueBinder *binder in [[self _bindingAdaptor] binders]) {
[binder performAction:self];
}
}
@smic
smic / gist:74a5399cd8480277b918
Created July 7, 2014 11:38
Calculation of the nearest point on a bézier spline using a subdivision algorithm, http://twitter.com/stemichels/status/485743201668841472
void SMSplineSubdivisionIterate_Private(CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4, CGFloat u, CGFloat du, BOOL *stop, BOOL(^block)(CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4, CGFloat u, CGFloat du, BOOL *stop)) {
// Call block for the given spline
if (!block(p1, p2, p3, p4, u, du, stop)) {
// don't continue with the subdivisions
return;
}
if (*stop) {
// stop the whole iteration
return;
}
@smic
smic / gist:1ab001d6c62e9a6e6cbf
Created July 1, 2014 14:46
Gesture recognition before NSGestureRecognizer
- (void)mouseDown:(NSEvent *)downEvent {
CGFloat doubleClickTime = [NSEvent doubleClickInterval] ;
NSEventMask eventMask = NSLeftMouseDraggedMask | NSLeftMouseUpMask;
// Is this a singe, double or triple click? Or long click, or a drag?
NSEvent *nextEvent = [NSApp nextEventMatchingMask:eventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:doubleClickTime] inMode:NSEventTrackingRunLoopMode dequeue:YES];
if (nextEvent) {
// could be an up or a drag
if (nextEvent.type == NSLeftMouseUp) {
// got at least a single click, make sure it's not performing a double click
if ( (nextEvent = [NSApp nextEventMatchingMask:NSLeftMouseDownMask untilDate:[NSDate dateWithTimeIntervalSinceNow:doubleClickTime] inMode:NSEventTrackingRunLoopMode dequeue:YES]) ) {
expr -- (void)printf("[%s %s]\n",(char *) object_getClassName(*(long*)($rdi)), (char *)($rsi))
@smic
smic / SMDocument.m
Created January 25, 2013 06:55
Replace the managed object context of a NSPersistentDocument by a context created by MagicalRecord.
#import "SMDocument.h"
@implementation SMDocument
- (id)init {
self = [super init];
if (self) {
NSManagedObjectContext *context = self.managedObjectContext;
if (context.concurrencyType != NSMainQueueConcurrencyType) {
NSUndoManager *undoManager = context.undoManager;
@smic
smic / main.m
Created January 8, 2012 17:28
Performance test of the function hypot
//
// main.m
// HypotTest
//
// Created by Stephan Michels on 08.01.12.
// Copyright (c) 2012 Stephan Michels Softwareentwicklung und Beratung. All rights reserved.
//
#import <Foundation/Foundation.h>