Skip to content

Instantly share code, notes, and snippets.

View ddeville's full-sized avatar
🐈

Damien Deville ddeville

🐈
View GitHub Profile
@ddeville
ddeville / gist:1527517
Created December 28, 2011 10:40
MIME type to UTI and back again in Cocoa
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
#else
#import <CoreServices/CoreServices.h>
#endif
/*
MIME type to UTI
*/
NSURLResponse *response = ... // assume a URL response from somewhere else.
@ddeville
ddeville / x86_64-registers
Created June 29, 2013 12:21
x86_64 registers
rax - accumulator
rbx - base
rcx - count
rdx - data
r8-15
rsi - source index
rdi - destination index
rbp - base pointer
@ddeville
ddeville / gist:dc6ba4346604ab4d6b65
Created July 12, 2014 21:49
Present the bookmark creation window in Spillo and populate it with the content from the frontmost tab in Safari
tell application "Safari"
set current_tab to current tab of front window
set tab_title to name of current_tab
set tab_address to URL of current_tab
tell application "Spillo"
show create bookmark panel with properties {url:tab_address, title:tab_title}
end tell
end tell

Keybase proof

I hereby claim:

  • I am ddeville on github.
  • I am ddeville (https://keybase.io/ddeville) on keybase.
  • I have a public key ASDmES-E7HI6XQtpt82tRK2_gSj34to_05USfnddUUlorwo

To claim this, I am signing this object:

@ddeville
ddeville / gist:b4db80697605474114bb
Created July 16, 2014 23:28
Create a bookmark in Spillo for every tab in the current Safari window
tell application "Safari"
set current_tabs to tabs of front window
repeat with current_tab in current_tabs
set tab_title to name of current_tab
set tab_address to URL of current_tab
tell application "Spillo"
make new bookmark with properties {url:tab_address, title:tab_title}
end tell
@ddeville
ddeville / gist:7173457
Created October 26, 2013 19:19
NSArrayController and +keyPathsForValuesAffectingValueForKey:
//
// main.m
// KVO
//
// Created by Damien DeVille on 10/26/13.
// Copyright (c) 2013 Damien DeVille. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@ddeville
ddeville / gist:7169443
Last active December 26, 2015 14:59
+keyPathsForValuesAffectingValueForKey: vs +keyPathsForValuesAffecting<Key>.
//
// main.m
// KVO
//
// Created by Damien DeVille on 10/26/13.
// Copyright (c) 2013 Damien DeVille. All rights reserved.
//
#import <Foundation/Foundation.h>
@ddeville
ddeville / gist:7103822
Created October 22, 2013 16:32
Think of a parent view controller that contains two children view controllers. The title of the parent view controller is a mixture of the titles of its children. The title of the second view controller depends on the name of its represented object too. Now, one would only need to bind the title of the window (for example) to the parent view con…
@interface ParentViewController : NSViewController
@property (strong, nonatomic) FirstChildViewController *firstViewController;
@property (strong, nonatomic) SecondChildViewController *secondViewController;
@end
@implementation ParentViewController
@ddeville
ddeville / gist:7097600
Created October 22, 2013 09:21
The correct way to react to changes on observed objects.
//
// main.m
// KVO
//
// Created by Damien DeVille on 10/22/13.
// Copyright (c) 2013 Damien DeVille. All rights reserved.
//
#import <Foundation/Foundation.h>
@ddeville
ddeville / gist:6078492
Last active December 20, 2015 05:29
objc_msgSend cast
So:
id boxedValue = objc_msgSend(self, mappingSelector, instance, value, boxingParameters);
would become:
id boxedValue = ((id (*)(id, SEL, id, id, id))objc_msgSend)(self, mappingSelector, instance, value, boxingParameters);
The first `id` and `SEL` are basically `self` and `_cmd`, the first 2 arguments in any objc_msgSend.