Skip to content

Instantly share code, notes, and snippets.

View jessesquires's full-sized avatar
🏴
free labor

Jesse Squires jessesquires

🏴
free labor
View GitHub Profile
import Cocoa
import MASShortcut
func pow() {
let rect = NSScreen.mainScreen()?.frame
let window = NSWindow(contentRect: rect!, styleMask: NSBorderlessWindowMask, backing: .Buffered, `defer`: false)
window.backgroundColor = NSColor.clearColor()
window.opaque = false
window.alphaValue = 1
window.makeKeyAndOrderFront(NSApplication.sharedApplication())
@jessesquires
jessesquires / generics_playground.swift
Last active June 27, 2018 02:19
Swift optional generic parameters?
protocol FactoryAType {
typealias Product
}
protocol FactoryBType {
typealias Product
}
@jessesquires
jessesquires / update_xcode_plugins.sh
Last active April 4, 2016 20:35 — forked from neonichu/update_xcode_plugins
Update DVTPlugInCompatibilityUUIDs for installed plugins
#!/bin/sh
# ID='A16FF353-8441-459E-A50C-B071F53F51B7' # Xcode 6.2
# ID='992275C1-432A-4CF7-B659-D84ED6D42D3F' # Xcode 6.3
# ID='AABB7188-E14E-4433-AD3B-5CD791EAD9A3' # Xcode 7b5
# ID='7265231C-39B4-402C-89E1-16167C4CC990' #Xcode 7.1.1
ID='F41BD31E-2683-44B8-AE7F-5F09E919790E' # Xcode 7.2
PLIST_BUDDY=/usr/libexec/PlistBuddy
@jessesquires
jessesquires / PrettyPrint.swift
Last active April 19, 2016 20:20
PrettyPrint
public func print<T>(object: T, _ file: String = __FILE__, _ function: String = __FUNCTION__, _ line: Int = __LINE__) {
Swift.print("\(file.lastPathComponent.stringByDeletingPathExtension).\(function)[\(line)]: \(object)")
}
extension String {
var isHomogeneous: Bool {
guard !isEmpty else { return true }
for i in startIndex..<endIndex.predecessor() {
if characters[i] != characters[i.successor()] {
return false
}
}
return true
@jessesquires
jessesquires / varTryCatch.swift
Last active August 29, 2015 14:23
Avoid using var with Swift try/catch?
var results = [MyModel]() // must use var :(
do {
results = try fetch(request: request, inContext: context)
}
catch {
print("Fetch error: \(error)")
}
// use results
@jessesquires
jessesquires / generic_constraints.swift
Created April 6, 2015 05:37
Swift generic constraints, conforming to a superclass and multiple protocols
protocol MyProtocol {
}
protocol MyOtherProtocol {
}
func configure <T: UIViewController where T: MyProtocol, T: MyOtherProtocol> (viewController: T) {
public protocol TableViewCellFactoryType {
typealias DataItem
typealias Cell: UITableViewCell
func cellForItem(item: DataItem, inTableView tableView: UITableView, atIndexPath indexPath: NSIndexPath) -> Cell
func configureCell(cell: Cell, forItem item: DataItem, inTableView tableView: UITableView, atIndexPath indexPath: NSIndexPath) -> Cell
}
@jessesquires
jessesquires / sorts.m
Last active August 29, 2015 14:02
sorts
// Swift
var arr: [Int] = // some array
let newArr = sorted(arr);
// Objective-C
NSMutableArray *arr = // some array
[arr sortUsingComparator:^NSComparisonResult(NSNumber *n1, NSNumber *n2) {
return [n1 compare:n2];
}];