Skip to content

Instantly share code, notes, and snippets.

View zachwaugh's full-sized avatar

Zach Waugh zachwaugh

View GitHub Profile
@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:

@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 / jquery.fadeoutandremove.js
Created June 1, 2010 15:36
jQuery plugin to handle fading out and removing and element from the DOM
/*!
* Fade Out element and remove from DOM
*/
(function($)
{
$.fn.fadeOutAndRemove = function(duration)
{
duration = (duration === undefined) ? 250 : duration;
return this.fadeOut(duration, function()
@zachwaugh
zachwaugh / fix-twitter.scpt
Created January 26, 2011 18:14
AppleScript to fix twitter appearing on all spaces issue
tell application "System Events"
set x to application bindings of spaces preferences of expose preferences
set x to {|com.twitter.twitter-mac|:3} & x -- 3 is any space you don't want twitter on
set application bindings of spaces preferences of expose preferences to x
set x to {|com.twitter.twitter-mac|:4} & x -- 4 is the space you want twitter to be on
set application bindings of spaces preferences of expose preferences to x
end tell
@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');
@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 / 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;
// 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 / 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 / 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