Skip to content

Instantly share code, notes, and snippets.

davbeck / NSImage+TMStretchable.h
Created Jan 12, 2012
A category to draw an NSImage using 9 slice stretching
View NSImage+TMStretchable.h
// NSImage+TMStretchable.h
// ThinkMessenger
// Created by David Beck on 1/11/12.
// Copyright (c) 2012 ThinkUltimate. All rights reserved.
#import <AppKit/AppKit.h>
davbeck / Example
Created May 14, 2012
CGContextClipToDrawing is a CGContext function for clipping with drawing in a block.
View Example
- (void)drawRect:(CGRect)drawRect
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToDrawing(context, self.bounds, ^(CGContextRef maskContext, CGRect rect){
[[UIColor whiteColor] setFill];
CGContextFillRect(maskContext, rect);
davbeck / gist:3661211
Created Sep 6, 2012
NSTimer with block
View gist:3661211
_actionDelayTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:[NSBlockOperation blockOperationWithBlock:^{
NSLog(@"Well this is useless.");
}] selector:@selector(start) userInfo:nil repeats:YES];
davbeck / NSObject+TUBlockDealloc.h
Created Nov 29, 2012
Execute block on dealloc
View NSObject+TUBlockDealloc.h
// NSObject+TUBlockDealloc.h
// ThinkGV
// Created by David Beck on 4/20/12.
// Copyright (c) 2012 ThinkUltimate LLC. All rights reserved.
#import <Foundation/Foundation.h>
davbeck /
Last active Aug 29, 2015

It's become common practice to use an @selector for associated objects. This is useful because not only are SELs guaranteed to have a unique address, but because as of Xcode 5, Xcode will warn you when you use a selector that it does not know about. Meaning that it is somewhat protected against spelling mistakes.

This can also be useful when using string keys. For things like state restoration, where you want a key for a given property, you can use the selector for the getter, and get a string from that. Xcode will autocomplete the name for you, and will warn you if you misspell it.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
    [super encodeRestorableStateWithCoder:coder];
 [coder encodeObject:self.feedID forKey:TNKPropertyKey(feedID)];
davbeck / formatted_mapping.json
Created Oct 2, 2014
Android/Rails Time Zone Mapping
View formatted_mapping.json
"International Date Line West":{
"Midway Island":{
davbeck / time_zone_map.rb
Created Oct 2, 2014
Generate Time Zone Mapping
View time_zone_map.rb
#!/usr/bin/env ruby
#encoding: utf-8
require 'active_support/all'
timezones = { |rails_name, name|
zone =
rails_name => {
offset: zone.utc_offset,
davbeck / WKUIDelegate.m
Last active Mar 15, 2022
Boilerplate implementation of WKUIDelegate to support Javascript alerts.
View WKUIDelegate.m
#pragma mark - WKUIDelegate
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)())completionHandler
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
View TNKURLFormatter.swift
// TNKURLFormatter.swift
// Created by David Beck on 2/6/15.
// Copyright (c) 2015 ThinkUltimate. All rights reserved.
import Foundation
davbeck / GQL.swift
Created May 2, 2015
GraphQL data structure implemented in Swift
View GQL.swift
import Foundation
protocol GQLNodeArgument {}
extension String: GQLNodeArgument {}
extension NSNumber: GQLNodeArgument {}
class GQLNode: StringLiteralConvertible, ArrayLiteralConvertible, Printable, DebugPrintable {
let name: String?