Skip to content

Instantly share code, notes, and snippets.

@t0rn
t0rn / copy_appropriate_google-service-info-plist.sh
Last active November 9, 2017 10:14 — forked from tylermilner/copy_appropriate_google-service-info-plist.sh
A shell script to selectively copy your GoogleService-Info.plist into your app bundle based on the current build configuration.
# Name of the resource we're selectively copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
# Get references to dev and prod versions of the GoogleService-Info.plist
# NOTE: These should only live on the file system and should NOT be part of the target (since we'll be adding them to the target manually)
GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Dev/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Prod/${GOOGLESERVICE_INFO_PLIST}
# Make sure the dev version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_DEV}"
@t0rn
t0rn / BalancedStrings.swift
Last active August 3, 2018 17:27
String extension for balancing by "open" and "close" substrings. String balanced algorithm using Swift
protocol StackProtocol {
associatedtype ElementType
var isEmpty: Bool { get }
mutating func pop() -> ElementType?
mutating func push(_ value: ElementType)
}
extension Array where Element == Int {
var equilibriumIndexes: [Element]? {
var idxs = [Element]()
var sum = reduce(0,+)
var leftSum = 0
let count = self.count
for i in 0..<count {
sum = sum - self[i]
if leftSum == sum {
idxs.append(i)
let xs = [3,5,1,4,6,3,9,11,1,0,3]
let ys = ["t","e","a","z","o","v","p"]
extension Array where Element: Comparable {
func selectionSort() -> [Element] {
guard self.count > 1 else {return self}
var result = self
for index in (0..<count - 1) {
var indexLowest = index
import Foundation
/// A list is either empty or it is composed of a first element (head)
/// and a tail, which is a list itself.
///
/// See http://www.enekoalonso.com/projects/99-swift-problems/#linked-lists
class List<T> {
var value: T
var nextItem: List<T>?
@t0rn
t0rn / Loop_LinkedList.swift
Created October 25, 2018 16:26
Loop in Linked List With Swift
import Foundation
class LinkedList<T> {
class Node<T> {
var value: T
var next: Node?
init (value: T){
self.value = value
}
import Foundation
protocol DelegateProtocol: class {
}
protocol Delegatable {
associatedtype DelegateType: DelegateProtocol
var delegate: DelegateType? { get set }
extension Collection where Element: Collection {
func transposed() -> [[Element.Element]]? {
guard let maxCount = self.map({$0.count}).max() else {return nil}
var result = [[Element.Element?]](repeating: [Element.Element?](repeating: nil, count: self.count), count: maxCount)
for (r,row) in self.enumerated() {
for (c,v) in row.enumerated() {
result[c][r] = v
}
}
return result
extension UITableView {
func updateTableHeaderView(with view: UIView?) {
guard
let view = view
else {
tableHeaderView = nil
return
}
let containerView = UIView()
containerView.translatesAutoresizingMaskIntoConstraints = false