Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / YObservable.swift
Last active November 15, 2016 19:17
Lightweight utility code to implement change propagation mechanism from observable objects to observer objects. Take 2
// YObservable
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@codelynx
codelynx / FileHandle+Z.swift
Last active June 19, 2023 00:32
enumerate lines from FileHandle (NSFileHandle) in swift3 – good for enumerating huge text file line by line
//
// FileHandle+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / ZDownloader.swift
Created November 25, 2016 04:29
Utility piece of code for downloading architecture using URLDownloadTask
//
// ZDownloader.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / NSObject+ZType.swift
Last active December 2, 2016 04:30
type accessible extension [swift3]
//
// ZType.swift
// ZKit [swift 3]
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / Sequence+Z.swift
Last active November 21, 2019 03:37
extension for Sequence protocol to build an array based on a paired items according to the current sequence.
//
// Sequence+Z.swift
// ZKit [Swift 5]
//
// The MIT License (MIT)
//
// Copyright (c) 2019 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / GeoUtils.swift
Created December 21, 2016 16:32
Piece of code for calculating the intersection of two 2D vectors
//
// GeoUtils.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / MTLTexture+Z.swift
Created December 28, 2016 14:58
Piece of Utility code to make CGImage from MTLTexture under (BGRA8Unorm)
//
// MTLTexture+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / あ.swift
Created January 2, 2017 08:20
sample touch stroke "あ" coordinate with swift code
typealias Point = (
touchType: Int, location: (CGFloat, CGFloat), preciseLocation: (CGFloat, CGFloat), majorRadius: CGFloat, majorRadiusTolerance: CGFloat, timestamp: TimeInterval,
force: CGFloat, maximumPossibleForce: CGFloat, altitudeAngle: CGFloat, azimuthAngle: CGFloat, azimuthUnitVector: (CGFloat, CGFloat)
)
[[ Point(2, (355.03125, 684.459045410156), (355.03125, 684.459045410156), 0.25, 0.0, 0.0, 0.333333333333333,4.16666666666667, 0.793895081677709, 1.04037475585938, (0.505897030655754, 0.862593875687563)),
Point(2, (355.296875, 683.854614257812), (355.296875, 683.854614257812), 0.25, 0.0, 0.0129999999990105, 0.2078125,4.16666666666667, 0.793895081677709, 1.04037475585938, (0.505897030655754, 0.862593875687563)),
Point(2, (355.5625, 683.39599609375), (355.5625, 683.39599609375), 0.25, 0.0, 0.0169999999998254, 0.145052083333333,4.16666666666667, 0.793895081677709, 1.04037475585938, (0.505897030655754, 0.862593875687563)),
Point(2, (355.703125, 683.125061035156), (355.703125, 683.125061035156),
@codelynx
codelynx / quadraticBezierLength.swift
Created February 9, 2017 09:03
Calculate quadratic bezier curve length in Swift
func quadraticBezierLength(_ p0: CGPoint, _ p1: CGPoint, _ p2: CGPoint) -> CGFloat {
// cf. http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/
let a = CGPoint(p0.x - 2 * p1.x + p2.x, p0.y - 2 * p1.y + p2.y)
let b = CGPoint(2 * p1.x - 2 * p0.x, 2 * p1.y - 2 * p0.y)
let A = 4 * (a.x * a.x + a.y * a.y)
let B = 4 * (a.x * b.x + a.y * b.y)
let C = b.x * b.x + b.y * b.y
let Sabc = 2 * sqrt(A + B + C)
@codelynx
codelynx / XPlatform.swift
Created May 15, 2017 04:57
CrossPlatform Utility code for iOS and macOS in Swift
//
// XPlatform.swift
// XPlatform
//
// Created by Kaz Yoshikawa on 12/25/16.
// Copyright © 2017 Electricwoods LLC. All rights reserved.
//
import Foundation