Skip to content

Instantly share code, notes, and snippets.

View m25lazi's full-sized avatar

Mohammed Lazim m25lazi

View GitHub Profile
@m25lazi
m25lazi / Inceptionv3.swift
Last active August 5, 2017 06:41
Prediction API generated by Xcode from Inceptionv3 model
/**
Make a prediction using the convenience interface
- parameters:
- image: Input image to be classified as RGB image buffer, 299 pixels wide by 299 pixels high
- throws: an NSError object that describes the problem
- returns: the result of the prediction as Inceptionv3Output
*/
func prediction(image: CVPixelBuffer) throws -> Inceptionv3Output {
let input_ = Inceptionv3Input(image: image)
return try self.prediction(input: input_)
@m25lazi
m25lazi / UIImage+Inceptionv3.swift
Created August 5, 2017 06:46
UIImage extension for using in Inception
extension UIImage {
func buffer() -> CVPixelBuffer? {
return UIImage.buffer(from: self)
}
static func buffer(from image: UIImage) -> CVPixelBuffer? {
// as explained in https://www.hackingwithswift.com/whats-new-in-ios-11
// ...
}
@m25lazi
m25lazi / keybase.md
Last active February 13, 2019 10:15
Keybase verification

Keybase proof

I hereby claim:

  • I am m25lazi on github.
  • I am m25lazi (https://keybase.io/m25lazi) on keybase.
  • I have a public key ASBXJ0Ym5z7ej1MlruGNMGncqXHyjm-mVtZ328UxyJC1xQo

To claim this, I am signing this object:

@m25lazi
m25lazi / wpa_supplicant.conf
Created November 5, 2017 13:55
Headless setup - rPI Zero W
network={
ssid="Your WiFi SSID"
psk="Correct Password for the same"
}
@m25lazi
m25lazi / User-1.swift
Last active September 15, 2018 07:18
import Foundation
import UIKit
internal class ImageDownloader {
let url: URL
init(url: URL) {
self.url = url
}
func fetch(then completion: @escaping (UIImage?, Error?) -> Void) {
/// Injecting fetcher to the fetch API, so that we get control of downloading outside of the User class
func fetchProfileImage(fetcher: ImageDownloader, then completion: @escaping (Bool)-> Void) {
fetcher.fetch { (image, error) in
if let fetchError = error {
print("Failed to fetch Image with error - \(fetchError)")
completion(false)
} else if let fetchedImage = image {
print("Image fetched")
self.iProfileImage = fetchedImage
completion(true)
/// Mock Subclass of ImageDownloader
/// Fetch API will return what you were passed while init.
internal class MockImageDownloader: ImageDownloader {
typealias MockResponse = (UIImage?, Error?)
/// Mocked response. Pass this as part of init and this will be the response of fetch API
let mockedResponse: MockResponse
init(url: URL, response: MockResponse) {
/// Interface that fetches image from a source.
/// Image can be fetched from a web service or even from a local source.
internal protocol ImageFetcher {
func fetch(then completion: @escaping (UIImage?, Error?) -> Void)
}
/// User Model
public class User {
// Stores the
public var name: String
/// Interface that fetches image from a source.
/// Image can be fetched from a web service or even from a local source.
internal protocol ImageFetcher {
func fetch(then completion: @escaping (UIImage?, Error?) -> Void)
}
/// ImageFetcher implementation to fetch image from web service
internal class ImageDownloader: ImageFetcher {
let url: URL
init(url: URL) {
/// Mock Subclass of ImageDownloader
/// Fetch API will return what you were passed while init.
internal class MockImageDownloader: ImageFetcher {
typealias MockResponse = (UIImage?, Error?)
/// Mocked response. Pass this as part of init and this will be the response of fetch API
let mockedResponse: MockResponse
init(url: URL, response: MockResponse) {