This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#Making Sequences work for you | |
// | |
// 今回のトピックはSwift2.0以降の`SequenceType`というプロトコルと、その内部的な動きについて紹介します。`class`や`struct`を`SequenceType`プロトコルに準拠させると、`for in`ループや`map`, `filter`などを使えるようになります。 | |
// | |
//さあ、始めましょう! | |
struct Unique<T: Comparable> { | |
private var backingStore: [T] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Prefecture: Int { | |
case Hokkaido = 1, Aomori = 2, Iwate = 3, Miyagi = 4, Akita = 5, | |
Yamagata = 6, Fukushima = 7, Ibaraki = 8, Tochigi = 9, Gunma = 10, | |
Saitama = 11, Chiba = 12, Tokyo = 13, Kanagawa = 14, Niigata = 15, | |
Toyama = 16, Ishikawa = 17, Fukui = 18, Yamanashi = 19, Nagano = 20, | |
Gifu = 21, Shizuoka = 22, Aichi = 23, Mie = 24, Shiga = 25, Kyoto = 26, | |
Osaka = 27, Hyogo = 28, Nara = 29, Wakayama = 30, Tottori = 31, | |
Shimane = 32, Okayama = 33, Hiroshima = 34, Yamaguchi = 35, Tokushima = 36, | |
Kagawa = 37, Ehime = 38, Kochi = 39, Fukuoka = 40, Saga = 41, Nagasaki = 42, | |
Kumamoto = 43, Oita = 44, Miyazaki = 45, Kagoshima = 46, Okinawa = 47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
private func reorderAndNormalized(swapElement indexA: Int, withElement indexB: Int, normalizeBlock: ((Int, Element) -> Element)) -> [Element]? { | |
guard indexA >= 0 && indexA < count else { return nil } | |
guard indexB >= 0 && indexB < count else { return nil } | |
var newItems = self | |
(newItems[indexA], newItems[indexB]) = (newItems[indexB], newItems[indexA]) | |
return newItems.enumerate().map { index, item in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import CFNetwork | |
public class FTPUpload { | |
fileprivate let ftpBaseUrl: String | |
fileprivate let directoryPath: String | |
fileprivate let username: String | |
fileprivate let password: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap { | |
fileprivate var backingStore: [Int] = [Int]() | |
public var count: Int { | |
return backingStore.count | |
} | |
} | |
// MARK: - Indexing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SoundListViewController.swift | |
// SoundSampler | |
// | |
// Created by Nicholas Maccharoli on 2016/12/06. | |
// Copyright © 2016年 Nicholas Maccharoli. All rights reserved. | |
// | |
import UIKit | |
import AudioToolbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Prefecture: Int { | |
case hokkaido = 1, aomori = 2, iwate = 3, miyagi = 4, akita = 5, | |
yamagata = 6, fukushima = 7, ibaraki = 8, tochigi = 9, gunma = 10, | |
saitama = 11, chiba = 12, tokyo = 13, kanagawa = 14, niigata = 15, | |
toyama = 16, ishikawa = 17, fukui = 18, yamanashi = 19, nagano = 20, | |
gifu = 21, shizuoka = 22, aichi = 23, mie = 24, shiga = 25, kyoto = 26, | |
osaka = 27, hyogo = 28, nara = 29, wakayama = 30, tottori = 31, | |
shimane = 32, okayama = 33, hiroshima = 34, yamaguchi = 35, tokushima = 36, | |
kagawa = 37, ehime = 38, kochi = 39, fukuoka = 40, saga = 41, nagasaki = 42, | |
kumamoto = 43, oita = 44, miyazaki = 45, kagoshima = 46, okinawa = 47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@IBDesignable final class ProgressBarView: UIView { | |
@IBInspectable var barColor: UIColor = UIColor.ex.red | |
@IBInspectable var trackColor: UIColor = UIColor.ex.gray | |
@IBInspectable var barThickness: CGFloat = 8.0 | |
@IBInspectable var barPadding: CGFloat = 0.0 | |
@IBInspectable var trackPadding: CGFloat = 0.0 | |
@IBInspectable var progressValue: Int = 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- My personal solutions for problems 1 through 10 of | |
- https://wiki.haskell.org/99_questions/1_to_10-} | |
-- Problem 1: Find the last element of a list | |
problemOne :: [a] -> a | |
problemOne x = last x | |
-- Problem 2: Find the second to last element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func recursiveFib(position: Int) -> Int { | |
if position == 0 || position == 1 { | |
return position | |
} | |
return recursiveFib(position: position - 1) + recursiveFib(position: position - 2) | |
} | |
func dynamicFib(position: Int) -> Int { | |