Skip to content

Instantly share code, notes, and snippets.

@pocketkk
pocketkk / Swift - Dijkstra.swift
Last active February 1, 2023 11:28
Swift - Shortest Path Algorithm (Compiled from: http://waynewbishop.com/swift/graphs/dijkstra/)
import UIKit
public class Vertex {
var key: String?
var neighbors: Array<Edge>
init() {
self.neighbors = Array<Edge>()
}
}
@pocketkk
pocketkk / ff.swift
Created September 11, 2014 16:04
Swift - Factorial and Fibonacci
//Factorial
func fact(n: Int) -> Int {
if n == 1 {
return 1
} else {
return n * fact(n-1)
}
}
#!/usr/bin/env ruby
require 'pry'
def fac(n)
n==0 ? 1 : n * fac(n-1)
end
def fact(n)
if n == 0
1
@pocketkk
pocketkk / navigationBarCustomization
Created August 25, 2014 17:05
UINavigationBar Customization
let red : CGFloat = 150/255
let green : CGFloat = 212/255
let blue : CGFloat = 86/255
let navBarColor : UIColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0)
// let shadow = NSShadow()
// shadow.shadowOffset = CGSizeMake(0.0, 1.0)
// shadow.shadowColor = UIColor.whiteColor()
let titleDict: NSDictionary = [
NSForegroundColorAttributeName: UIColor.darkGrayColor(),
NSFontAttributeName: UIFont(name: "HelveticaNeue-Thin", size: 20)
@pocketkk
pocketkk / git-remove
Created July 27, 2014 21:12
Git - Remove all deleted
git rm $(git ls-files --deleted)
@pocketkk
pocketkk / Swift - Sort by date.swift
Created July 27, 2014 17:51
Swift - Sort objects by date field
@objc(Note)
class Note: NSManagedObject {
@NSManaged var content: String
@NSManaged var date: NSDate
@NSManaged var business: Business
@NSManaged var coldcall: ColdCall
@NSManaged var contact: Contact
}
@pocketkk
pocketkk / Swift - Move UIScrollView to Position.swift
Created July 21, 2014 20:47
Swift - Move UIScrollView to Position
func buttonTapped(sender: UIButton!) {
let scroll : UIScrollView? = findScroller(self.view)
let scrollPoint = CGPointMake(0.0, 0.0)
println("Button Tapped")
if scroll {
scroll!.setContentOffset(scrollPoint, animated: true)
}
}
@pocketkk
pocketkk / Search Subview for UIScrollView.swift
Created July 21, 2014 20:42
Swift Search Subview for UIScrollView
// Returns first UIScrollView in subviews of view
func searchFor(view: UIView) -> UIScrollView? {
for v in view.subviews{
let y = v as UIView
if v is UIScrollView {
return (v as UIScrollView)
}
}
return nil
}
@pocketkk
pocketkk / Swift Delegate Example.swift
Created July 21, 2014 15:19
Swift - Delegate Protocol Example
import UIKit
protocol TodoDelegate {
func sendCompleted(todo: Todo)
}
class Notifications : TodoDelegate {
var message: String?
var sent: Bool = false
@pocketkk
pocketkk / Swift UIFactory.swift
Last active August 29, 2015 14:04
Swift - UIFactory
// Playground - noun: a place where people can play
import UIKit
class BaseUIDefaults {
class var sharedInstance : BaseUIDefaults {
struct Static {
static let instance : BaseUIDefaults = BaseUIDefaults()
}