Skip to content

Instantly share code, notes, and snippets.

@kechan
kechan / Mathematics.swift
Last active September 25, 2017 05:17
Math-like Operators in Swift
// Paste this in Playground
infix operator ∘
prefix operator ∑^
typealias ItoD = (Int) -> Double
func *(lhs: Int, rhs: Double) -> Double {
return Double(lhs)*rhs
}
@kechan
kechan / CoreDataPlayground.swift
Last active September 27, 2017 20:26
CoreData in Playground
// Paste this in Playground
import CoreData
let url = Bundle.main.url(forResource: "HikingApp", withExtension: "momd")
let model = NSManagedObjectModel(contentsOf: url!)
let container = NSPersistentContainer(name: "HikingApp")
@kechan
kechan / NSCodingPlayground.swift
Last active September 27, 2017 20:38
NSCoding Archiving with Playground
let docsDir = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
print(docsDir)
let archiveURL = docsDir.appendingPathComponent("landmark")
print(archiveURL.path)
class LandmarkClass : NSObject, NSCoding {
var name = ""
init(name: String) {
self.name = name
@kechan
kechan / Unit.swift
Last active September 27, 2017 20:37
Some units conversion
extension Double {
var km: Double { return self } // This is stored as km, everything else will need conversion instead.
var mile: Double { return 0.6214 * self }
}
10.km
10.mile
let x = 10.0 // if user unit is miles
let dist = x/1.mile
@kechan
kechan / MyTensorflow
Created March 26, 2018 05:43
Tensorflow
a = tf.constant(2)
b = tf.constant(3)
x = tf.add(a, b)
writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
with tf.Session() as sess:
print(sess.run(x))
writer.close()
@kechan
kechan / pca_aug.py
Last active April 12, 2018 03:11
PCA Color Augmentation
import numpy as np
# original image is 224x224x3 of dtype uint8
renorm_image = np.reshape(original_image, (original_image.shape[0]*original_image.shape[1],3))
renorm_image = renorm_image.astype('float32')
renorm_image -= np.mean(renorm_image, axis=0)
renorm_image /= np.std(renorm_image, axis=0)
@kechan
kechan / keras-transfer-learning-with-feature-caching.ipynb
Created May 20, 2018 20:28
Keras Transfer Learning with feature caching.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kechan
kechan / keras-transfer-learning.ipynb
Created May 20, 2018 20:31
Keras Transfer Learning.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kechan
kechan / keras-transfer-learning-bug.ipynb
Created May 21, 2018 03:36
Keras Transfer Learning Bug.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.