Skip to content

Instantly share code, notes, and snippets.

@yllan
yllan / FloatingPointExact.swift
Created November 28, 2019 13:12
Calculate the exact value of flaoting point number
// 特殊的數字我沒處理,會 fail。例如 subnormal 或者 NaN
// 用法: 0.94.exact() // "0.939999999999999946709294817992486059665679931640625"
//
// main.swift
// FloatingPoint
//
// Created by Yung-Luen Lan on 2019/8/27.
// Copyright © 2019 yllan. All rights reserved.
//
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP2dNTRrLtCSzxQ8WpSrTngstjOLQ3xxFpdKcdYZN3YD yllan@YMBP.local
@yllan
yllan / line2data.swift
Created June 19, 2019 03:17
Encode MKPolyline to Data
func encode(line: MKPolyline) -> Data {
return Data(buffer: UnsafeBufferPointer(start: line.points(), count: line.pointCount))
}
func decode(data: Data) -> MKPolyline {
let buf = UnsafeMutableBufferPointer<MKMapPoint>.allocate(capacity: data.count / MemoryLayout<MKMapPoint>.size)
data.copyBytes(to: buf)
return MKPolyline(points: buf.baseAddress!, count: buf.count)
}
@yllan
yllan / encodable_polyline.swift
Created June 18, 2019 07:51
How to encode MKPolyline
import MapKit
extension MKPolyline: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
for idx in 0..<self.pointCount {
let p = self.points()[idx]
try container.encode(p.x)
try container.encode(p.y)
}
}
@yllan
yllan / encodable_polyline.swift
Created June 18, 2019 07:51
How to encode MKPolyline
import MapKit
extension MKPolyline: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
for idx in 0..<self.pointCount {
let p = self.points()[idx]
try container.encode(p.x)
try container.encode(p.y)
}
}
@yllan
yllan / template.html
Last active May 1, 2020 14:02
Email Template
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>眠豆腐 Sleepy Tofu :: 手工床墊專門製造所</title>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="padding: 0;">
<div id="wrapper" dir="ltr" style="background-color: #f7f7f7; margin: 0; padding: 70px 0 70px 0; width: 100%; -webkit-text-size-adjust: none;">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%"><tr>
<td align="center" valign="top">
1, 4, 12, 2, 3, 6, 8, 9, 5, 7, 10, 11,
1, 4, 12, 2, 3, 8, 6, 9, 7, 5, 10, 11,
1, 4, 12, 2, 3, 8, 6, 9, 7, 10, 5, 11,
1, 4, 12, 2, 3, 8, 6, 11, 5, 10, 7, 9,
1, 4, 12, 2, 3, 8, 11, 6, 5, 10, 7, 9,
1, 4, 12, 2, 3, 11, 8, 5, 9, 7, 6, 10,
1, 4, 12, 2, 3, 11, 8, 9, 5, 7, 10, 6,
1, 4, 12, 2, 8, 3, 6, 9, 7, 5, 10, 11,
1, 4, 12, 2, 8, 3, 6, 9, 7, 10, 5, 11,
1, 4, 12, 2, 8, 3, 6, 11, 5, 10, 7, 9,
@yllan
yllan / crash.log
Created September 27, 2018 02:44
Xcode 10 crash log
Process: Xcode [4673]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: Xcode
Version: 10.0 (14320.25)
App Item ID: 497799835
App External ID: 828536089
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [4673]
User ID: 501
@yllan
yllan / yllan.md
Created August 23, 2018 03:42
yllan intro

現任職於博智雲端科技用python寫web app,下班後的身份是台灣城市單車聯盟理事、Cocoaheads Taipei發起人、業餘macOS/iOS開發者。 上一個生涯目標是推廣熱愛的蘋果,已達成。接下來的生涯目標是推廣熱愛的單車多元文化,用單車來改變城市。 曾主辦「沈默的騎行」呼籲重視交通安全,以及「台北裸騎」。

//
// Signer.swift
// Sign
//
// Created by Yung-Luen Lan on 2018/8/17.
// Copyright © 2018 yllan. All rights reserved.
//
import Foundation