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
@jessesquires
jessesquires / gist:8781c86206dfb70e78eb7f1aa4fc6fac
Created January 10, 2018 00:40
Delete all local git branches
git config --global alias.trim '!f() { git branch | grep -v "\*" | xargs -n 1 git branch -D; }; f'
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 / 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)")
}
@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 / FCPrivateBatteryStatus.m
Created March 18, 2016 16:18
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);
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())
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 / 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];
}];