Skip to content

Instantly share code, notes, and snippets.

View zachwaugh's full-sized avatar

Zach Waugh zachwaugh

View GitHub Profile
@zachwaugh
zachwaugh / Makefile
Last active October 6, 2020 03:36
Swift + Sublime Text 3
# I rarely use make, probably a better way to do some/all of this?
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
SOURCES=main.swift
EXECUTABLE=main
all:
swiftc -sdk $(SDK) $(SOURCES) -o $(EXECUTABLE)
clean:
@zachwaugh
zachwaugh / fonts.md
Last active August 29, 2015 14:27
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
zachwaugh / switch-shortcut.swift
Last active February 6, 2023 16:15
Swift shortcut for returning and/or assigning the result of switch statement?
// 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
zachwaugh / iOS-devices-graphic.md
Last active August 19, 2019 15:16
iOS device compatibility

A hopefully accurate list of iOS compatibility per device

iOS 13

ios13

iOS 12

ios12

iOS 11

ios11

@zachwaugh
zachwaugh / ZWDictionaryOfVariableBindings.m
Last active July 29, 2016 12:39
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.
#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]-[self.bar]-[baz]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_foo, self.bar, baz)];
// -> this doesn't work, gives an error about "self."
//
@zachwaugh
zachwaugh / keybase.md
Created March 26, 2014 18:11
keybase.md

Keybase proof

I hereby claim:

  • I am zachwaugh on github.
  • I am zachwaugh (https://keybase.io/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:

// 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
zachwaugh / gist:1264981
Created October 5, 2011 16:50
NSImage category for writing image to file
// [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;
@zachwaugh
zachwaugh / gist:1151687
Created August 17, 2011 14:53
Image mask
- (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
zachwaugh / console_test.js
Created February 23, 2011 16:51
Testing node.js console.log output string quoting
console.log('100', 'something');
console.log(100, 'something');
console.log(100, 'something', 'something else');
console.log(100 + ' something');
console.log('something', 100, 'something');