Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / gist:cc24d1fead1d9ce779a1
Created March 6, 2015 17:26
Testing Equatable function between base class and its subclass but != seems not working as expected?
// Creature
class Creature : Equatable {
}
func ==(lhs: Creature, rhs: Creature) -> Bool {
return lhs === rhs
}
// Monster
@codelynx
codelynx / simd+ext.swift
Last active November 17, 2021 18:56
swift: float4x4 extension to scale, rotate, translate 4x4 matrix
//
// simd+ext.swift
//
// Created by Kaz Yoshikawa on 11/6/15.
//
//
import Foundation
import simd
import GLKit
@codelynx
codelynx / Vector3D+Vector2D.swift
Last active November 7, 2015 14:35
Swift 2.0: Vector3D Vector2D
//
// Geometry.swift
// ZKit
//
// Created by Kaz Yoshikawa on 11/6/15.
//
//
import Foundation
import CoreGraphics
@codelynx
codelynx / String+Z.swift
Last active December 5, 2015 23:36
common file/path related method
//
// String+Z.swift
// ZKit
//
// Created by Kaz Yoshikawa on 11/10/15.
//
//
import Foundation
@codelynx
codelynx / ZGeoUtils.swift
Created December 4, 2015 00:11
swift: Geometric Utility
//
// ZGeoUtils.swift
// ZKit
//
// Created by Kaz Yoshikawa on 2015/02/08.
// Copyright (c) 2015 Electricwoods LLC. All rights reserved.
//
import Foundation
import CoreGraphics
@codelynx
codelynx / NSScanner+Z.swift
Created December 11, 2015 00:35
NSScanner Utility
import Foundation
extension NSScanner {
func scanStringFromSet(strings: Set<String>) -> String? {
for string in strings {
if self.scanString(string, intoString: nil) {
return string
}
}
@codelynx
codelynx / .swift
Created January 14, 2016 18:43
switch statement example
for thing in things {
switch thing {
case 0 as Int:
print("zero as an Int")
case 0 as Double:
print("zero as a Double")
case let someInt as Int:
print("an integer value of \(someInt)")
case let someDouble as Double where someDouble > 0:
print("a positive double value of \(someDouble)")
@codelynx
codelynx / NSFileHandle+Z.swift
Last active July 6, 2016 18:33
Utility methods Reading and Writing Integer, Float, Double for NSFileHandle
//
// NSFileHandle+Z.swift
// ZKit
//
// Created by Kaz Yoshikawa on 2/18/16.
//
//
import Foundation
@codelynx
codelynx / String+Color.swift
Last active March 24, 2016 07:09
convert from hexadecimal string to UIColor
//
// String+Color.swift
// ZKit
//
// Created by Kaz Yoshikawa on 3/24/16.
// Copyright © 2016 Electricwoods LLC Inc. The MIT License.
//
import Foundation
import UIKit
@codelynx
codelynx / ThemableViewController.swift
Created March 19, 2016 12:21
Declaring variable to keep UIViewController that conforms to protocol Themeable
protocol Themeable {
var viewController: UIViewController { get }
}
extension Themeable where Self: UIViewController {
var viewController: UIViewController { return self }
}
class ThemeableViewController: UIViewController, Themeable {}
let themeable: Themeable = ThemeableViewController()