This file contains hidden or 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 | |
// siri 說出來的2進位字串 | |
let whatSirirSays = ["11100110", "10101001", "10011111", "11100101", "10101111", "10000110"] | |
extension Int8 { | |
init(string str: String){ | |
var rtn: Int8 = 0 | |
var i: Int = 0 | |
for anUnicodeScalar in str.unicodeScalars{ | |
//將字串型態的單一 bit 轉成 00000000, 或 00000001 |
This file contains hidden or 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
//在 ~/.bash_profile 放這個: | |
alias nuke="rm -rf ~/Library/Developer/Xcode/DerivedData/" |
This file contains hidden or 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
let x = 1 | |
if x > 0 { | |
print("> 0") | |
} else if x < 0 { | |
print("< 0") | |
} else { | |
print("== 0") | |
} |
This file contains hidden or 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
let x = 1 | |
switch x { | |
case _ where x > 0: | |
print("> 0") | |
case _ where x < 0: | |
print("< 0") | |
default: | |
print("== 0") | |
} |
This file contains hidden or 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
let x: Int = 1 | |
switch x { | |
case greaterThan(0): | |
print("positive") | |
case lessThan(0): | |
print("negative") | |
default: | |
print("0") | |
} |
This file contains hidden or 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
//pattern 是 case 後接的參數,value 是 switch 後面接的參數 | |
func ~=(pattern: String, value: Int) -> Bool { | |
return pattern == "\(value)" | |
} | |
//這個會被代入 ~= 函數裡的 value | |
let x = 1 | |
switch x { | |
//這個會被代入 ~= 函數裡的 pattern | |
case "1": |
This file contains hidden or 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 ~=<T: Comparable, U: Equatable>(pattern: T, value: U) -> Bool { | |
return true | |
} |
This file contains hidden or 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
/* | |
第一個參數是一個會輸出 Bool 的函數,也就是 case 後面接的東西。 | |
第二個參數會被放入第一個函數型態的參數中,藉以輸出一個 Bool 值 | |
*/ | |
func ~=<T>(pattern: T->Bool, value: T) -> Bool { | |
return pattern(value) | |
} | |
func greaterThan<T: Comparable>(a:T)(b: T) -> Bool { |
This file contains hidden or 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
// | |
// main.swift | |
// SquareWaveGenerator | |
// | |
// Created by dolphin on 2016/8/7. | |
// Copyright © 2016年 dolphin. All rights reserved. | |
// | |
import Foundation | |
import AudioToolbox |
This file contains hidden or 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
from pgoapi import pgoapi | |
from s2sphere import Cell, CellId, LatLng | |
import time | |
def get_cell_ids(lat, long, radius = 10): | |
origin = CellId.from_lat_lng(LatLng.from_degrees(lat, long)).parent(15) | |
walk = [origin.id()] | |
right = origin.next() |
OlderNewer