Skip to content

Instantly share code, notes, and snippets.

struct Fib {
var current: Int = 1;
var last: Int = 0;
mutating func next() {
let tmp = current;
current += last;
last = tmp;
print("Current: \(current) Last: \(last) ");
@nthState
nthState / Multiply
Created July 10, 2015 12:25
Accelerate vDSP_vsmul
let array_size:Int = 6
let input:[Float] = [1,2,3,4,5,6]
var output = [Float](count: array_size, repeatedValue: 0.0)
vDSP_vsmul(input, 1, [5], &output, 5, vDSP_Length(array_size))
@nthState
nthState / gist:dd63694681f36895d1050b5395187e6d
Created April 22, 2016 09:18
Quadratic UIView animation
self.topConstraint.constant = 0.0
UIView.animateWithDuration(2, delay: 1, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
CATransaction.begin()
CATransaction.setValue(2, forKey: "kCATransactionAnimationDuration")
let f = CAMediaTimingFunction(controlPoints: 0.43, 0, 0.57, 1) //quad ease in out
CATransaction.setAnimationTimingFunction(f)
self.view.layoutIfNeeded()
CATransaction.commit()
0xF58b65CB859e4f113F639864Bb8D779b34084aFc
@nthState
nthState / Dijkstra.swift
Created January 25, 2018 21:10
Dijkstra Algorithm
/**
My attempt at Dijkstra Algorithm
https://www.youtube.com/watch?v=0nVYi3o161A
https://www.youtube.com/watch?v=5GT5hYzjNoo
*/
import UIKit
class Node : CustomDebugStringConvertible, Hashable, Equatable
//: Playground - noun: a place where people can play
import UIKit
func quickSort(ls:[Int]) -> [Int]
{
guard ls.count > 1 else { return ls }
let pivot = ls[ls.count/2]
O(1) - dictionary lookup
O(n) - linear, 100 items = 1 second, 200 = 2 seconds
O(n2) - nested
O(2n) - exponential
O(logN) - binary search, binary tree
@nthState
nthState / marchingAnts.fsh
Created April 15, 2018 19:33
Marching Ants
/**
Drag marching ants on SKShapeNode stroke
https://stackoverflow.com/questions/16838907/drawing-marching-ants-using-directx
*/
void main() {
float w = ((int)(v_tex_coord.x + v_tex_coord.y + (u_time*4)) % 8);
gl_FragColor = (w < 4 ? vec4(1,1,1,0) : vec4(0.48,0.84,0.99,1));
}
@nthState
nthState / VerticalProgress.swift
Created July 10, 2018 14:33
Vertical Progress Bar with stepper
import Foundation
import UIKit
@IBDesignable class VerticalProgressionBar : UIView {
@IBInspectable var sections: Int = 1 {
didSet {
build()
}
}