Skip to content

Instantly share code, notes, and snippets.

View ozgurshn's full-sized avatar

Ozgur Sahin ozgurshn

View GitHub Profile
@ozgurshn
ozgurshn / ObjProtocolInSwift.swift
Last active June 19, 2016 12:00
Ensuring Objective-C class implemented Swift optional protocol method
@objc protocol VideoRangeSliderDelegate
{
func videoRange (videoRange:VideoRangeSlider, didChangeLeftPosition:CGFloat, rightPosition:CGFloat)
optional func videoRange(videoRange:VideoRangeSlider, didGestureStateEndedLeftPosition:CGFloat, rightPosition:CGFloat)
}
// Usage ensuring call if method is implemented
delegate?.videoRange?(self, didGestureStateEndedLeftPosition: self.leftPosition, rightPosition: self.rightPosition)
@ozgurshn
ozgurshn / Networking.swift
Last active July 8, 2019 09:07
Networking Request in Xcode 8.0 Playground.
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let url = URL(string: "http://ip.jsontest.com/")!
let session = URLSession.shared()
let q = session.dataTask(with: url) { data, response, error in
do {
@ozgurshn
ozgurshn / IBInspectableGradient.swift
Last active February 27, 2017 21:58
Live gradient rendering on XCode Storyboard with IBInspectable
import UIKit
@IBDesignable
class CustomView: UIView {
@IBInspectable var gradient:Bool = false {
didSet {
if gradient
{
let topColor = UIColor(red: 3/256, green: 51/256, blue: 75/256, alpha: 1.0)
@ozgurshn
ozgurshn / RoundedView.swift
Created February 27, 2017 22:00
Set corderRadius on XCode StoryBoard
import UIKit
@IBDesignable
class CustomView: UIView {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
@ozgurshn
ozgurshn / RoundedandGradient.swift
Created February 27, 2017 23:24
IBInspectable for Rounded and Gradient UIView
import UIKit
@IBDesignable
class CustomView: UIView {
var fromColor: UIColor?
var toColor: UIColor?
var gradientLayer: CAGradientLayer?
@ozgurshn
ozgurshn / DrawRoutesonMapKit.swift
Last active June 18, 2017 14:13
Draw route between two core location point
func drawRoutes(sourceLocation:CLLocationCoordinate2D , destinationLocation:CLLocationCoordinate2D)
{
let sourcePlacemark = MKPlacemark(coordinate: sourceLocation, addressDictionary: nil)
let destinationPlacemark = MKPlacemark(coordinate: destinationLocation, addressDictionary: nil)
let sourceMapItem = MKMapItem(placemark: sourcePlacemark)
let destinationMapItem = MKMapItem(placemark: destinationPlacemark)
@ozgurshn
ozgurshn / ProtocolWithDelegateOutlet.swift
Last active June 18, 2017 14:13
Protocol with Delegate Outlet to use directly in Storyboard
@objc protocol LocationSelectorDelegate: class {
func showMap(tag: Int)
}
@IBDesignable
class LocationSelectorView: UIView {
@IBOutlet weak var delegate: LocationSelectorDelegate?
@ozgurshn
ozgurshn / finetunedResnet.ipynb
Last active December 8, 2021 09:35
Resnet50 finetuning and saving model as CoreML model.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ozgurshn
ozgurshn / resnetModelGetModel.py
Last active June 21, 2018 22:39
Resnet50 model fine-tuned
def get_model():
input_tensor = Input(shape=(224, 224, 3)) # this assumes K.image_data_format() == 'channels_last'
# create the base pre-trained model
base_model = ResNet50(input_tensor=input_tensor,weights='imagenet',include_top=False)
for layer in base_model.layers:
layer.trainable=False
def compile_model(compiledModel):
compiledModel.compile(loss=keras.losses.categorical_crossentropy,
optimizer=Adadelta(),
metrics=['accuracy'])