Skip to content

Instantly share code, notes, and snippets.

View miguelfermin's full-sized avatar

Miguel Fermin miguelfermin

View GitHub Profile
@miguelfermin
miguelfermin / reverseString.swift
Last active January 31, 2016 03:36
A simple function that reverses a string. It demonstrates the use of "inout" variables and Array's "reduce" method. The use of "inout" here also demonstrates that you can still use value types in place of reference types without loosing the ability to have functions updating the actual variable values.
func reverseString(inout string: String) {
var chars = Array(string.characters)
var temp: Character!
for i in 0..<chars.count/2 {
temp = chars[i]
chars[i] = chars[chars.count - (i + 1)]
chars[chars.count - (i + 1)] = temp
}
string = chars.reduce("") {$0 + "\($1)"}
}
@miguelfermin
miguelfermin / MAFDark.dvtcolortheme
Last active April 4, 2016 03:50
Dark Xcode theme. Add file to path: "/Library/Developer/Xcode/UserData/FontAndColorThemes/"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@miguelfermin
miguelfermin / sameCharacters.swift
Created January 31, 2016 16:21
A simple function that returns true if two strings have the same exact characters -regardless of order- or false otherwise.
func sameCharacters(string stringOne: String, string stringTwo: String) -> Bool {
let stringOneCharacters = stringOne.characters
let stringTwoCharacters = stringTwo.characters
// Early exit 1
if stringOneCharacters.count != stringTwoCharacters.count {
return false
}
var charMatched = false
@miguelfermin
miguelfermin / fitbitViewController.swift
Last active January 31, 2016 23:22
Snippet of a view controller with logic to authenticate to a Fitbit account. Note: the code is functional but it requires a Storyboard and a JSON file, see notes within code.
//
// ViewController.swift
// FitBitClient
//
// Created by Miguel Fermin on 1/17/16.
// Copyright © 2016 MAF Software, LLC. All rights reserved.
//
import UIKit
import SafariServices
@miguelfermin
miguelfermin / Reduce.swift
Created March 1, 2016 11:00
Swift Functional Programming: Reduce
// Swift Functional Programming: Reduce
//
// By Miguel Fermin on 2016.01.28
//
// Reference: http://www.raywenderlich.com/82599/swift-functional-programming-tutorial
import UIKit
// Manual Reduction:
// Take the even numbers between 1 and 10 and compute their sum.
@miguelfermin
miguelfermin / Map.swift
Created March 1, 2016 11:03
Swift Functional Programming: Map
// Swift Functional Programming: Map
//
// By Miguel Fermin on 2016.01.28
//
// Reference: https://www.weheartswift.com/higher-order-functions-map-filter-reduce-and-more/
import UIKit
// The map method solves the problem of transforming the elements of an array using a function.
@miguelfermin
miguelfermin / Filter.swift
Created March 1, 2016 11:06
Swift Functional Programming: Filters
// Swift Functional Programming: Filters
//
// By Miguel Fermin on 2016.01.27
//
// Reference: http://www.raywenderlich.com/82599/swift-functional-programming-tutorial
import Cocoa
/* Find all the even numbers between 1 and 10 */
@miguelfermin
miguelfermin / sieve.swift
Created March 1, 2016 11:07
Sieve of Eratosthenes Algorithms
//: Playground - noun: a place where people can play
import UIKit
/* Sieve of Eratosthenes Algorithms
*
* In mathematics, the sieve of Eratosthenes one of a number of prime number sieves, is a simple, ancient algorithm
* for finding all prime numbers up to any given limit.
*
* Pseudocode to find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:
@miguelfermin
miguelfermin / MAFSegueHandlerType.swift
Last active March 15, 2016 06:56
MAFSegueHandlerType: This protocol implements best Swift practices to simplify the use of segues throuhout the app
//
// MAFSegueHandlerType.swift
// MAFFinance
//
// Created by Miguel Fermin on 8/1/15.
// Copyright © 2015 Miguel Fermin. All rights reserved.
//
import UIKit
@miguelfermin
miguelfermin / MAFStoryBoardHandlerType.swift
Created March 15, 2016 07:02
MAFStoryBoardHandlerType.
//
// MAFStoryBoardHandlerType.swift
// MAFFinance
//
// Created by Miguel Fermin on 10/20/15.
// Copyright © 2015 MAF Software LLC. All rights reserved.
//
import UIKit