Skip to content

Instantly share code, notes, and snippets.

Avatar
🤠
Sailing the seas of Swift

Nicholas Maccharoli Nirma

🤠
Sailing the seas of Swift
View GitHub Profile
View H99_1_10.hs
{- 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
View ProgressBar.swift
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 {
View Prefectures.swift
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
@Nirma
Nirma / SoundListViewController.swift
Last active Oct 11, 2020
Display all available System Sounds for iOS, plays sound when tapped.
View SoundListViewController.swift
//
// SoundListViewController.swift
// SoundSampler
//
// Created by Nicholas Maccharoli on 2016/12/06.
// Copyright © 2016年 Nicholas Maccharoli. All rights reserved.
//
import UIKit
import AudioToolbox
View Heap.swift
class Heap {
fileprivate var backingStore: [Int] = [Int]()
public var count: Int {
return backingStore.count
}
}
// MARK: - Indexing
@Nirma
Nirma / FTPUpload.swift
Last active Oct 12, 2021
Upload a file via FTP on iOS or macOS
View FTPUpload.swift
import Foundation
import CFNetwork
public class FTPUpload {
fileprivate let ftpBaseUrl: String
fileprivate let directoryPath: String
fileprivate let username: String
fileprivate let password: String
View SwapAndNormalize.swift
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
@Nirma
Nirma / Swift_Japanese_Prefectures_enum.swift
Last active Apr 4, 2016
Japanese prefectures as a Numbered Swift Enum!
View Swift_Japanese_Prefectures_enum.swift
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
View Swift_Sequences_Hatena_Example.swift
//#Making Sequences work for you
//
// 今回のトピックはSwift2.0以降の`SequenceType`というプロトコルと、その内部的な動きについて紹介します。`class`や`struct`を`SequenceType`プロトコルに準拠させると、`for in`ループや`map`, `filter`などを使えるようになります。
//
//さあ、始めましょう!
struct Unique<T: Comparable> {
private var backingStore: [T] = []
View Break Larger Array up into slices
extension Array {
func forEachSlice(sliceSize: Int, block: [Element] -> Void) {
guard sliceSize > 0 && self.count > 0 else {
return
}
var currentSlice = [Element]()
defer {