Skip to content

Instantly share code, notes, and snippets.

@scottdelly
scottdelly / FacebookLogin.swift
Last active April 23, 2021 21:43
Facebook Login with iOS SDK 4.0 in Swift
//If you have a Bridging-Header:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
//In your AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [String: AnyObject]?) -> Bool {
//App launch code
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
//Optionally add to ensure your credentials are valid:
@scottdelly
scottdelly / gist:6b8e648a4ac403cfca14
Created April 9, 2015 23:00
Xcode Automatic CFBundleVersion Incrementing
formatDate=$(date "+%Y%m%d%H%M%S")
buildNumber="${formatDate}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${PROJECT_DIR}/${INFOPLIST_FILE}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${SRCROOT}/<YOUR WATCHKIT APP FOLDER>/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${SRCROOT}/<YOUR WATCHKIT EXTENSION FOLDER>/Info.plist"
//Protocol for spotlight indexing
protocol SpotlightIndexable {
var spotlightTitle: String {get}
var spotlightDescription: String {get}
var spotlightKeywords: [String] {get}
var spotlightImageData: NSData? {get}
var spotlightUrl: NSURL {get}
func index()
}
let contactsGroup = dispatch_group_create()
dispatch_group_enter(contactsGroup) //Enter group for the first time
loadContactsFromServerAPIWithCompletion({ (contacts:[User]) -> () in
doStuffWithContacts(contacts)
dispatch_group_leave(contactsGroup) //Leave group
})
dispatch_group_enter(contactsGroup) //Enter group again
loadContactsAddressBookWithCompletion({ (contacts:[User]) -> () in
@scottdelly
scottdelly / .gitignore
Created April 18, 2016 17:50 — forked from adamgit/.gitignore
.gitignore file for Xcode4 / OS X Source projects
#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.6
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
@scottdelly
scottdelly / ColorFromString.swift
Created July 26, 2016 21:38
A utility method to create a UIColor from an arbitrary string. Inspired by http://stackoverflow.com/a/16348977/2138077
func fromString(string: String) -> UIColor {
var hash = 0
let utf16array = Array(string.utf16)
for i in 0..<utf16array.count {
hash = Int(utf16array[i]) + ((hash << 5) - hash)
}
var colorValues = [CGFloat]()
for i in 0..<3 {
let value = (hash >> (i * 8)) & 0xFF
colorValues.append((CGFloat(value)/255.0))
@scottdelly
scottdelly / newton.go
Created July 14, 2017 19:08
Efficient Implementation of Newtons Formula for Square Roots
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
digits := math.Floor( math.Log10( x ) ) + 1
guess := x/math.Pow(10,digits/2)
import Foundation
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}