Skip to content

Instantly share code, notes, and snippets.

View castillejoale's full-sized avatar

Alejandro Castillejo castillejoale

  • San Francisco, California
View GitHub Profile
@castillejoale
castillejoale / InterpolationAlgorithm.swift
Last active April 24, 2022 22:46
Swift - interpolation function
import simd
static func interpolate(desiredX: inout [Float], y: inout [Float]) -> [Float] {
let n = desiredX.count - 1
let stride = vDSP_Stride(1) //Int Type Alias
let denominator = Float(n) / Float(y.count - 1)
let control: [Float] = desiredX.map {
let x = Float($0) / denominator
let smoothStep = Float(simd_smoothstep(0, 1, simd_fract(x)))
import UIKit
import AVFoundation
//Dictionary string-> Dictionary
let dictionaryString = "{\ncode=0;\nphotoLink=\"\";\nplayerLastName=\"\";\nplayerName=\"\";\n}"
var arrayOfElements = dictionaryString.characters.split{$0 == "\n"}.map(String.init)
arrayOfElements.removeLast()
import UIKit
import AVFoundation
//JSON String -> Dictionary
let jsonText = "{\"anotherKey\":\"anotherValue\",\"aKey\":\"aValue\"}"
var dictonary:NSDictionary?
if let data = jsonText.dataUsingEncoding(NSUTF8StringEncoding) {
import UIKit
import AVFoundation
//Dictionary -> JSON String
let dictionary = ["aKey": "aValue", "anotherKey": "anotherValue"]
var theJSONText:String?
do {
func winDetection() -> Bool {
//Check rows
for i in 0...2 {
if((board[3*i] == board[3*i + 1]) && (board[3*i] == board[3*i + 2]) && !(String(board[3*i]) == "EMPTY")){
print("Someone won at row:")
print(i)
print( board[i])
return true
}