Skip to content

Instantly share code, notes, and snippets.

Lee Morgan leemorgan

Block or report user

Report or block leemorgan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@leemorgan
leemorgan / arrayExtension.swift
Created Aug 16, 2015
Array extension where Element: Int
View arrayExtension.swift
extension Array where Element: Int {
func foo() {
}
}
var anArray = [Int]()
anArray.foo() // '[Int]' does not have a member named 'foo'
@leemorgan
leemorgan / Fibonacci.swift
Last active May 8, 2019
Fibonacci series in Swift
View Fibonacci.swift
// Fibonacci series
// F[n] = F[n-1] + F[n-2]
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
// Find the fibonacci number for n interations
func fibonacci(n: Int) {
var num1 = 0
var num2 = 1
@leemorgan
leemorgan / AutoAssets.md
Last active Aug 29, 2015
Xcode build script to generate a Swift file enumerating the project's assets
@leemorgan
leemorgan / autoBuildNumber
Created Jun 22, 2015
Auto-populate project build number based on current date and time
View autoBuildNumber
# @desc Auto-populate the build number based on the current date and time.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Target Dependencies"
now=`date +%y.%m.%d.%H%M`
buildNumber=$(printf "%s" $now)
@leemorgan
leemorgan / Clamp.swift
Last active May 6, 2018
clamp() in Swift
View Clamp.swift
///Returns the input value clamped to the lower and upper limits.
func clamp<T: Comparable>(value: T, lower: T, upper: T) -> T {
return min(max(value, lower), upper)
}
//-----------------------------------------------
// Example usage
let proposedIndex = 6
@leemorgan
leemorgan / Xcode Project Line Count
Created Oct 19, 2014
Count the lines of code in a Xcode project
View Xcode Project Line Count
# Count the lines of code in a Xcode project
find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" ")" -print0 | xargs -0 wc -l
You can’t perform that action at this time.