Skip to content

Instantly share code, notes, and snippets.

View jeremycochoy's full-sized avatar

Jeremy Cochoy jeremycochoy

View GitHub Profile
init(from list: [T] = []) {
cursor = list.first
rightList = list
}
/// Convert to a swift array
func toList() -> [T] {
if let c = cursor {
return leftList + [c] + rightList.reversed()
} else {
struct ListZipper<T> {
private var leftList: [T] = []
private var rightList: [T] = []
/// Cursor to the selected Track
var cursor: T? = nil
}
@jeremycochoy
jeremycochoy / encode.rb
Created February 21, 2019 17:14
Encode polyline
def encode(points, precision = 1e5)
result = ""
last_lat = last_lng = last_timestamp = 0
# Convert each point (lat, lng, ts) to a string
points.each do |point|
# Convert to integer
lat = (point[0] * precision).round
lng = (point[1] * precision).round
timestamp = point[2]
# Compute the difference with the previous point
@jeremycochoy
jeremycochoy / sample.rb
Created February 21, 2019 17:01
Split strings back into smaller chunks
coordinates = []
word = ""
polyline.each_byte do |b|
# Add the character b to the current chunk
word << b
next unless b < 0x5f # While we are below the _ ascii code
# Add the chunk to the list of coordinates represented by a string
coordinates << word
word = ""
end