Skip to content

Instantly share code, notes, and snippets.

:octocat:
Swift + Machine Learning + Big Data

Adolfo fitomad

:octocat:
Swift + Machine Learning + Big Data
Block or report user

Report or block fitomad

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fitomad
fitomad / repeat_array.swift
Created Mar 14, 2018
Array extension that insert an element n-times in the array with a gap between each element's insertion.
View repeat_array.swift
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)
```
View array_swift41.swift
//
// 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"]
View typeof.swift
// 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)")
@fitomad
fitomad / background_sound.swift
Created Jan 30, 2018
Enable iOS app to play sound in background
View background_sound.swift
//
// 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
View model_extension_snippet.swift
//
// MARK: - CoreML Methods
//
extension TablaViewController
{
/**
Predice el doble de un número usando un modelo `CoreML`
View model_declaration_snippet.swift
/// Modelo ML
private lazy var model: TablaModel = TablaModel()
@fitomad
fitomad / double_ml.py
Created Jan 19, 2018
Modelo que predice el doble de un valor dado. Usan progresión lineal para la predicción
View double_ml.py
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 Dec 21, 2017
El modelo más simple y su posterior exportación para su uso en CoreML
View linear_coreml.py
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 Dec 20, 2017
Example about Codable protocol in Swift 4
View codable.swift
import Foundation
//
// MARK: - Venue struct representation
//
/**
Different venue types.
*/
public enum Kind: String, Codable
View autoclosure.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!"
You can’t perform that action at this time.