Skip to content

Instantly share code, notes, and snippets.

View fitomad's full-sized avatar
👋
Swift + ML & DL + Azure + AWS

Adolfo fitomad

👋
Swift + ML & DL + Azure + AWS
View GitHub Profile
@fitomad
fitomad / background_sound.swift
Created January 30, 2018 23:25
Enable iOS app to play sound in background
//
// MARK: - Step 1. Configuration
//
/*
You need to enable one feature in order to allow our app play sounds in *background* mode.
Select the Capabilities tab of project's main target, go to Background Modes section and select:
**Audio, AirPlay and Picture in Picture
//
// MARK: - CoreML Methods
//
extension TablaViewController
{
/**
Predice el doble de un número usando un modelo `CoreML`
/// Modelo ML
private lazy var model: TablaModel = TablaModel()
@fitomad
fitomad / double_ml.py
Created January 19, 2018 18:50
Modelo que predice el doble de un valor dado. Usan progresión lineal para la predicción
from sklearn.linear_model import LinearRegression
# N veces
X_train = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]
# Resultado
y_train = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
model = LinearRegression()
model.fit(X_train, y_train)
@fitomad
fitomad / linear_coreml.py
Last active December 21, 2017 21:28
El modelo más simple y su posterior exportación para su uso en CoreML
from sklearn.linear_model import LinearRegression
# N veces
X_train = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]
# Resultado
y_train = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
model = LinearRegression()
model.fit(X_train, y_train)
@fitomad
fitomad / codable.swift
Created December 20, 2017 15:37
Example about Codable protocol in Swift 4
import Foundation
//
// MARK: - Venue struct representation
//
/**
Different venue types.
*/
public enum Kind: String, Codable
@fitomad
fitomad / autoclosure.swift
Created November 13, 2017 12:54
Example about @autoclosure in Swift
/*
An autoclosure is a closure that is automatically created to wrap an expression that’s being passed as an argument to a function.
It doesn’t take any arguments, and when it’s called, it returns the value of the expression that’s wrapped inside of it
*/
let greeting: () -> (String) = {
print("You can do other things here...")
return "Hi everyone!"
@fitomad
fitomad / magnetometer-sample.swift
Created October 23, 2017 08:04
Detect when your iPhone or iPad is near a magnet or ferrous material
import CoreMotion
import Foundation
let queue: OperationQueue = OperationQueue()
queue.qualityOfService = .utility
let motionManager: CMMotionManager = CMMotionManager()
motionManager.magnetometerUpdateInterval = 0.5
motionManager.startMagnetometerUpdates(to: queue, withHandler: { (data: CMMagnetometerData?, error: Error?) -> Void in
// Creamos el LivePhotos Player.
const player = LivePhotosKit.Player(document.getElementById('livephotos-layer'));
player.photoSrc = 'images/live/waves.jpg';
player.videoSrc = 'images/live/waves.mov';
//
// Eventos
//
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo LivePhotosKit JS</title>
<meta charset="utf-8">
</head>
<body>
<div id="livephotos-layer" style="width: 1024px; height: 720px;"></div>
</body>