Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.
Edit Xcode Scheme and add a pre-action script.
Copy the contents of preaction.sh
into the pre-action script box.
module Enumerable | |
def normalize | |
magnitude = Math.sqrt(reduce(:+)) | |
return self if magnitude.nan? | |
map { |x| x.to_f / magnitude } | |
end | |
def similarity(arr) | |
return 0.0 if arr.count != count | |
similarity = Math.sqrt(zip(arr).map { |d| d.first * d.second }.reduce(:+)) |
Installation procedure for pre-build actions to automatically populate Xcode Info.plist with dynamic data.
Edit Xcode Scheme and add a pre-action script.
Copy the contents of preaction.sh
into the pre-action script box.
extension UICollectionView { | |
func indexPathsForCloseItems(offset: Int) -> [IndexPath] { | |
var indexes = indexPathsForVisibleItems.sorted(by: { $0.row < $1.row }) | |
for x in indexes { | |
print("had: \(x)") | |
} | |
if let index = indexes.last { |
class LinkedListNode<T> { | |
var next : LinkedListNode<T>? | |
var value: T | |
var count : Int { | |
return next == nil ? 1 : next!.count + 1 | |
} | |
init(_ value: T, _ next: LinkedListNode<T>?=nil) { |
import Foundation | |
// Given some sorted dates find out if the set contains 5 dates within 30 days of eachother. | |
// I.e. Given a user's login dates, find out if they were logged in 5 or more times in 30 days. | |
extension Date { | |
static func parse(_ str: String) -> Date { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "yyyy-MM-dd" | |
return dateFormatter.date(from: str)! |
protocol EnumCollection : Hashable {} | |
extension EnumCollection { | |
static func enumerated() -> AnySequence<Self> { | |
typealias S = Self | |
return AnySequence { () -> AnyIterator<S> in | |
var raw = 0 | |
return AnyIterator { | |
let current = withUnsafePointer(to: &raw) { | |
$0.withMemoryRebound(to: S.self, capacity: 1) { $0.pointee } |
import UIKit | |
extension UIColor { | |
static func rgba(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat) -> UIColor { | |
return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a) | |
} | |
static var lightBackground: UIColor { return .rgba(246, 246, 246, 1) } | |
static var text: UIColor { return .rgba(51, 51, 51, 1) } | |
} |
# Question: https://www.dropbox.com/s/4dlhs6x69cmj8uv/Screenshot%202017-04-29%2012.21.05.png?dl=0 | |
# Time limit: 30min | |
# Finished in 28min | |
# It should be possible to load the tree in one pass. I just didn't have time to rewrite that part. | |
require "rubygems" | |
require "json" | |
locations = JSON.parse(STDIN.read) | |
class Node |