Skip to content

Instantly share code, notes, and snippets.

Zach Waugh zachwaugh

Block or report user

Report or block zachwaugh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
zachwaugh / Makefile
Last active Jun 2, 2019
Swift + Sublime Text 3
View Makefile
# I rarely use make, probably a better way to do some/all of this?
swiftc -sdk $(SDK) $(SOURCES) -o $(EXECUTABLE)
zachwaugh /
Last active Aug 29, 2015
Lists all fonts installed on iOS. Helpful to get the correct name when using custom fonts in an app
func printFonts() {
    println("--- Installed fonts ---")
    let families = sorted(UIFont.familyNames() as! [String]) { $0 < $1 }

    for family in families {
        println("family: \(family)")
        let fonts = UIFont.fontNamesForFamilyName(family)
        for font in fonts {
zachwaugh / switch-shortcut.swift
Last active Sep 9, 2019
Swift shortcut for returning and/or assigning the result of switch statement?
View switch-shortcut.swift
// Can currently do this
func titleForSection1(section: Int) -> String? {
switch section {
case 0: return "Foo"
case 1: return "Bar"
default: return nil
// But I want to do this to remove the redundant returns
zachwaugh /
Last active Aug 19, 2019
iOS device compatibility

A hopefully accurate list of iOS compatibility per device

iOS 13


iOS 12


iOS 11


zachwaugh / ZWDictionaryOfVariableBindings.m
Last active Jul 29, 2016
Experiment to figure out how NSDictionaryOfVariableBindings works, and try to make a more flexible version. This version strips underscores and supports self.* variables, but I'm sure there is a better way to do it.
View ZWDictionaryOfVariableBindings.m
#import <Foundation/Foundation.h>
// Experimental improvement to NSDictionaryOfVariableBindings where keys are simplified to remove underscores and "self." prefixes
// so you can use the simple version within the VFL string
// Example:
// [NSLayoutConstraint constraintsWithVisualFormat:@"|-[_foo]-[]-[baz]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_foo,, baz)];
// -> this doesn't work, gives an error about "self."

Keybase proof

I hereby claim:

  • I am zachwaugh on github.
  • I am zachwaugh ( on keybase.
  • I have a public key whose fingerprint is 6B46 CDCF BBD4 4006 97C2 0D7A 70CA 12E6 82A9 D4C6

To claim this, I am signing this object:

View gist:2421586
// static var to store shared date formatter
static NSDateFormatter *_formatter = nil;
@implementation NSDate (Extras)
// Simple comparison, create a string from today and date, see if they're the same
- (BOOL)isToday
// Lazy load and cache formatter, date formatters are slow to init
if (!_formatter)
zachwaugh / gist:1264981
Created Oct 5, 2011
NSImage category for writing image to file
View gist:1264981
// [image writeToFile:[NSURL fileURLWithPath:@"/some/path/image.png"]];
- (void)writeToFile:(NSURL *)fileURL
NSBitmapImageRep *bitmapRep = nil;
for (NSImageRep *imageRep in [self representations])
if ([imageRep isKindOfClass:[NSBitmapImageRep class]])
bitmapRep = (NSBitmapImageRep *)imageRep;
View gist:1151687
- (UIImage *)imageWithMask:(UIImage *)maskImage andIsWhite:(BOOL)isWhite
CGRect imageRect = CGRectMake(0, 0, maskImage.size.width, maskImage.size.height);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextClipToMask(ctx, imageRect, maskImage.CGImage);
if (isWhite) {
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1);
} else {
zachwaugh / console_test.js
Created Feb 23, 2011
Testing node.js console.log output string quoting
View console_test.js
console.log('100', 'something');
console.log(100, 'something');
console.log(100, 'something', 'something else');
console.log(100 + ' something');
console.log('something', 100, 'something');
You can’t perform that action at this time.