Instantly share code, notes, and snippets.

View SmoothScroll.js
Please duplicate this radar for a Safari fix!
This will clean up a 50-line workaround.
rdar://22376037 (
(Now available as a standalone repo.)
View promise_any.js
// Promises are started in parallel.
// Resolves with the first resolved value in time.
// If there's no winner, it rejects with last rejection.
Promise.any = function (promises) {
return new Promise((resolve, reject) => {
var rejectedCount = 0;
function onMemberResolved(value) {
function onMemberRejected(reason) {
View promise_preferred.js
// Promises are started in parallel.
// Resolves with the first resolved value in array order.
// If there's no winner, it rejects with last rejection.
Promise.preferred = function (promisesOrdered) {
return new Promise((resolve, reject) => {
var resolvedValues = new WeakMap();
var resolvables = promisesOrdered.slice(); // copy
function onMemberResolved(value, member) {
resolvedValues.set(member, value);
if (member == resolvables[0])
View gist:b839c768dbb4e7ab8825
ACTION = build
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
View BLZLabelWithInset.h
@interface BLZLabelWithInset : UILabel
@property (nonatomic) UIEdgeInsets insets;
View PSPDFUIKitMainThreadGuard.m
// Taken from the commercial iOS PDF framework
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout. This is also called reflow or layout thrashing, and is common performance bottleneck.


Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
View NSObject+BlockObservation.h
// NSObject+BlockObservation.h
// Version 1.0
// Andy Matuschak
// Public domain because I love you. Let me know how you use it.
#import <Cocoa/Cocoa.h>

Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.

If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them:

OS X El Capitan

  • split view - two apps side by side on full screen
View NSArray+IndexHelper.h
// NSArray+IndexHelper.h
// C_POS
// Created by Tomohisa Takaoka on 6/14/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
#import <Foundation/Foundation.h>