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
<html>
<head>
<title>La prueba</title>
<style>
.btn-hide
{
visibility: hidden;
}
.btn-show
// Números del 0 al 10 pero con el **5** un poco *descolocaldo*
let numeros: [Int] = [ 0, 1, 2, 3, 4, 6, 7, 8, 9, 5, 10 ]
// Swift 3.1
let menores = numeros.prefix(while: { $0 < 5 })
let mayores = numeros.drop(while: { $0 < 5 })
dump(menores)
/*
import Foundation
extension Array where Element: Comparable
{
/**
Saludamos en orden a todos los integrantes del `Array`.
*/
public func saluteAllElements() -> Void
{
let sorted_elements: [Element] = self.sorted(by: { $0 < $1 })
<!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>
// 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
//
@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
@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!"
import Foundation
let tweet: String = "Detectar etiquetas y usuario en un tuit con #Swift. También podemos recoger los usuario como @fitomad o @AppStore. #SwiftLang #iOSDev #macOSDev"
// Estos caracteres no nos interesan...
var skip_set: CharacterSet = CharacterSet.whitespacesAndNewlines
skip_set.formUnion(CharacterSet.punctuationCharacters)
// ...excepto estos, que son para usuarios y etiquetas y no debemos excluirlos.
skip_set.remove(charactersIn: "@#_")
let fixed_array: [Int] = [ 2, 1, 4, 3, 6, 5, 8, 7, 10, 9]
var mutable_array: [Int] = [ 2, 8, 10, 3, 6, 5, 4, 7, 1, 9]
let new_fixed_array = fixed_array.sort()
mutable_array.sortInPlace()
print("> mutable: \(mutable_array.descriptionWithSeparator(", "))")
print("> fixed: \(fixed_array.descriptionWithSeparator(", "))")
print("> new fixed: \(new_fixed_array.descriptionWithSeparator(", "))")
@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