Skip to content

Instantly share code, notes, and snippets.

@nthState
nthState / combineVSAsyncAwait
Last active August 15, 2022 12:17
CombineVsAsyncAwait
struct Product: Decodable {
let title: String
}
class MyCombine {
func getWithCombine() -> AnyPublisher<Product, Error> {
let url = URL(string: "https://dummyjson.com/products/1")!
@nthState
nthState / PlayStation5DualSenseCoreHaptics.swift
Created July 2, 2021 19:55
Run Core Haptics on PS5 Dual Sense
import Foundation
import GameController
import CoreHaptics
/**
Ensure the controller supports Haptics, then play
*/
class PlayStationHaptics {
var engine: CHHapticEngine?
@nthState
nthState / PlayPattern.swift
Created June 25, 2021 09:18
Play Haptics with Syncing to Haptrix macOS App
import CoreHaptics
import HaptrixSync
func playHapticsFile() {
guard let url = Bundle.main.url(forResource: "myfile", withExtension: "ahap") else {
print("could not load file")
return
}
import CoreHaptics
func playHapticsFile() {
guard let url = Bundle.main.url(forResource: "myfile", withExtension: "ahap") else {
print("could not load file")
return
}
do {
let vibe: NSArray = [true, 1000, false, 250, true, 1200]
let dict = [
"Intensity": 0.7,
"VibePattern": vibe
] as [String : Any]
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dict)
#import <AudioToolbox/AudioToolbox.h>
void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID,id arg,NSDictionary* vibratePattern);
@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()
}
}
@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));
}
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