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 / 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)
//
// 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 / 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
// An array with Int, Double and String types inside
let items: [Any] = [ 32, 32.0, "32" ]
for item in items
{
switch type(of: item)
{
case is Int.Type:
print("Type Int: \(item)")
//
// New `joined` and `split` functions in Swift 4.1
//
// More info at Swift [Array Documentacion](https://developer.apple.com/documentation/swift/array)
//
import Foundation
// The sample data...
let data: [String] = [ "Col1", "Col2", "Col3", "Col4", "Col5"]
@fitomad
fitomad / repeat_array.swift
Created March 14, 2018 11:11
Array extension that insert an element n-times in the array with a gap between each element's insertion.
extension Array
{
/**
Insert an element n-times in the array
with a gap between each element's insertion.
```
var numbers: [String] = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
numbers.repeat("X", gap: 3, fromTheBeginning: false)
```
@fitomad
fitomad / first-word-duplicated.swift
Created April 15, 2018 22:21
Obtain the first word duplicated in a phrase.
let phrase: String = "If you know what you know if I..."
let words = phrase.split(separator: " ")
/// Check if a given word is includen in a string
/// before the own word.
func containsWord(_ word: String, offsetLimit limit: Int) -> Bool
{
return words.enumerated()
.filter({ $0.offset < limit })
.map({ String($0.element) })
@fitomad
fitomad / stack-playground.swift
Created May 17, 2018 21:14
Swift Stack Data Structure
import Foundation
public struct Stack<Element>
{
private var storage: [Element]
public init()
{
self.storage = [Element]()
}