Skip to content

Instantly share code, notes, and snippets.

View Drusy's full-sized avatar

Kévin Renella Drusy

View GitHub Profile
@agrippa1994
agrippa1994 / playground.swift
Created January 4, 2016 22:05
Bonjour Discovery OS X iOS
import Foundation
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
extension NSData {
func castToCPointer<T>() -> T {
let mem = UnsafeMutablePointer<T>.alloc(sizeof(T.Type))
self.getBytes(mem, length: sizeof(T.Type))
return mem.move()
@jkosoy
jkosoy / CGSize+AspectFunctions.swift
Last active June 3, 2023 18:11
Aspect Fill and Aspect Fit calculations in Swift
// port of http://stackoverflow.com/a/17948778/3071224
import UIKit
import Foundation
extension CGSize {
static func aspectFit(aspectRatio : CGSize, var boundingSize: CGSize) -> CGSize {
let mW = boundingSize.width / aspectRatio.width;
let mH = boundingSize.height / aspectRatio.height;
@ka010
ka010 / gist:235253db3fccfac53910
Last active March 5, 2020 04:39
Convert an AVFrame to CVPixelbuffer
-(void)getPixelBuffer:(CVPixelBufferRef *)pbuf {
@synchronized (self) {
if(!_pFrame || !_pFrame->data[0])
return;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
// [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
// [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
@(_pFrame->linesize[0]), kCVPixelBufferBytesPerRowAlignmentKey,