Skip to content

Instantly share code, notes, and snippets.

View standinga's full-sized avatar

standinga

View GitHub Profile
@standinga
standinga / Browser.swift
Created November 30, 2020 06:58
IOS/OSX Networking initial browser
//
// Client.swift
// MultiConnect
//
// Created by michal on 29/11/2020.
//
import Foundation
import Network
@standinga
standinga / ContentView.swift
Created November 29, 2020 09:50
IOS/OSX Networking initial view
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button("Server") {
server?.start()
}
Spacer()
Button("Client") {
@standinga
standinga / Server.swift
Last active November 30, 2020 06:57
IOS/OSX Networking initial server
//
// Server.swift
// MultiConnect
//
// Created by michal on 29/11/2020.
//
import Foundation
import Network
import UIKit
func combineAsyncCalls(completionHandler: @escaping (String)->()) {
var text = ""
let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.global().async {
fetchData(0, delay: 0.4) {
text += $0
semaphore.signal()
}
fetchData(1, delay: 0.2) {
text += $0
const express = require('express')
const app = express()
const port = 3000
const increment = function () {
counter ++
setTimeout(increment, 1000);
}
var maxAge = 4
import Foundation
URLCache.shared.removeAllCachedResponses() // start each "experiment" with empty cache
let timer = Timer(timeInterval: 1, repeats: true) { _ in
fetch(title: "useProtocolCachePolicy", policy: .useProtocolCachePolicy)
fetch(title: "returnCacheDataElseLoad", policy: .returnCacheDataElseLoad)
fetch(title: "reloadIgnoringLocalCacheData", policy: .reloadIgnoringLocalCacheData)
// fetch(title: "returnCacheDataDontLoad", policy: .returnCacheDataDontLoad)
}
const express = require('express')
const app = express()
const port = 3000
const recursive = function (req, res) {
counter ++
setTimeout(recursive, 300);
}
recursive()
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
@standinga
standinga / CVPixelBuffer+CMSampleBuffer+Copy.swift
Created December 31, 2019 04:38
Deep Copying of CMSampleBuffer and CVPixelBuffer
//
// CVPixelBuffer+CMSampleBuffer+Copy.swift
// VideoDelaySwift
//
// Created by michal on 16/07/2019.
// Copyright © 2019 michal. All rights reserved.
//
import AVFoundation
@standinga
standinga / PlayerView.swift
Created December 16, 2019 19:36
MTKView sometimes crashes when drawing CVImageBuffer
import AppKit
import AVFoundation
import MetalKit
class PlayerView: MTKView {
private var ciImage: CIImage? {
didSet {
renderImage()
}