Skip to content

Instantly share code, notes, and snippets.

View jaylyerly's full-sized avatar

Jay Lyerly jaylyerly

View GitHub Profile
@jaylyerly
jaylyerly / gist:0916b8f14f4a33ba2678b3ceb8a32353
Created June 12, 2019 13:46
Get the number of days in the month containing the given date.
import Foundation
let jan1 = Date(timeIntervalSince1970: 24*60*60)
let days = (0...11).map {
Calendar.current.date(byAdding: .month, value: $0, to: jan1)!
}
days
let daysPerMonth = days.map {
@jaylyerly
jaylyerly / urlAuth.playground
Created December 11, 2017 16:39
Basic URL Auth with URLCredential
import UIKit
import PlaygroundSupport
// Test site for Basic Authentication
// substitute values in the path to auth against
// http://httpbin.org/basic-auth/user/passwd
// so
// http://httpbin.org/basic-auth/foo/bar
// would check for username = foo and password = bar
@jaylyerly
jaylyerly / main.swift
Created April 6, 2017 21:20
This implementation of main.swift for an iOS app dynamically switch the AppDelegate at runtime based on the presence of the TestingAppDelegate class, which is only available during unit testing.
import Foundation
import UIKit
let appDelegateClass: AnyClass = NSClassFromString("AppNameTests.TestingAppDelegate") ?? AppDelegate.self
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(appDelegateClass))
@jaylyerly
jaylyerly / TestingAppDelegate.swift
Created April 6, 2017 21:17
This empty AppDelegate implementation for testing allows the unit tests to run without bootstrapping the rest of the application.
import Cocoa
class TestingAppDelegate: NSObject, NSApplicationDelegate {
}
@jaylyerly
jaylyerly / main.m
Created April 6, 2017 21:12
This implementation of main() for a Mac application dynamically switch the AppDelegate at runtime based on the presence of the TestingAppDelegate class, which is only available during unit testing.
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
if (NSClassFromString(@"AppNameTests.TestingAppDelegate") != nil) {
id appDelegate = [[NSClassFromString(@"AppNameTests.TestingAppDelegate") alloc] init];
NSApplication * application = [NSApplication sharedApplication];
[application setDelegate:appDelegate];
[NSApp run];
} else {
#!/bin/sh
sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \;
sudo find /private/var/folders/ -name com.apple.iconservices -exec rm -rf {} \;
sudo rm -rf /Library/Caches/com.apple.iconservices.store
@jaylyerly
jaylyerly / gist:932df9d754b0ce4cc836
Created January 14, 2015 16:38
Post notification to Slack after Xcode bot build
#!/usr/bin/env python
import os
import requests
import json
"""
bot configure note:
cd $XCS_SOURCE_DIR/project_dir/scripts/
./bot2slack.py
@jaylyerly
jaylyerly / gist:58a6c86942bc94af7b2b
Created January 9, 2015 14:50
Opt in to enable iOS device as AVCapture device
// Enable iOS device to show up as AVCapture devices
// From WWDC video 2014 #508 at 5:34
// https://developer.apple.com/videos/wwdc/2014/#508
CMIOObjectPropertyAddress prop = {
kCMIOHardwarePropertyAllowScreenCaptureDevices,
kCMIOObjectPropertyScopeGlobal,
kCMIOObjectPropertyElementMaster };
UInt32 allow = 1;
CMIOObjectSetPropertyData(kCMIOObjectSystemObject, &prop, 0, NULL, sizeof(allow), &allow);
@jaylyerly
jaylyerly / Golden
Created June 7, 2014 23:56
Draw the Golden Spiral in Swift
// Playground - noun: a place where people can play
import UIKit
let 𝜋 = M_PI
let ɸ = (1 + sqrt(5))/2
func drawTiles(tileCount: Int, height: Double, context: CGContext) {
let red = CGFloat(arc4random_uniform(100)) / 100.0
let green = CGFloat(arc4random_uniform(100)) / 100.0