Skip to content

Instantly share code, notes, and snippets.

View ivanlesko's full-sized avatar

Ivan Lesko ivanlesko

View GitHub Profile
func configureSlomoCaptureFormats(formats: [AVCaptureDeviceFormat]) {
var bestFormat: AVCaptureDeviceFormat?
var bestFrameRateRange: AVFrameRateRange?
for format in device.formats as! [AVCaptureDeviceFormat] {
// We only want to use 420f media sub types to get the best dynamic range.
let mediaSubtype = CMFormatDescriptionGetMediaSubType(format.formatDescription)
if mediaSubtype == k420f {
// let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
// this ALMOST crops a CMSampleBufferRef.
//
// SampleBufferHelper.m
// sampleBufferBS
//
// Created by Ivan Lesko on 2/25/16.
// Copyright © 2016 Ivan Lesko. All rights reserved.
//
// From: http://stackoverflow.com/a/30724543/2526115
// Adds the ability to remove a certain object based on value from an array
extension RangeReplaceableCollectionType where Generator.Element : Equatable {
// Remove first collection element that is equal to the given `object`:
mutating func removeObject(object : Generator.Element) {
if let index = self.indexOf(object) {
self.removeAtIndex(index)
}
PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in
_ = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(outputFileURL)
}, completionHandler: { (success: Bool, error: NSError?) -> Void in
if success {
print("successfully saved video to camera roll")
do {
let _ = try NSFileManager().removeItemAtPath(outputFileURL.path!)
print("Successfully removed saved video file from local directory")
} catch let error as NSError {
@ivanlesko
ivanlesko / gist:008878c97072b9149fc2
Created December 14, 2014 05:45
Ivan's Sublime key bindings
// Gotta have 'em...
[
{ "keys": ["shift+enter"], "command": "move_to", "args": {"to": "eol", "extend": false} },
// Toggle auto-save
{ "keys": ["ctrl+shift+s"], "command": "auto_save" },
// Auto indent
{ "keys": ["ctrl+i"], "command": "reindent"}
@ivanlesko
ivanlesko / gist:78e0c5afc49feb3bf10f
Created December 14, 2014 05:42
Better .bash_profile
export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
export EDITOR='subl -w'
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
export PS1='⚡ '
@ivanlesko
ivanlesko / AudioTapProcessor
Last active August 29, 2015 14:05
Audio Tap Processor
/*
File: MYAudioTapProcessor.h
Abstract: Audio tap processor using MTAudioProcessingTap for audio visualization and processing.
Version: 1.0.1
*/
#import <Foundation/Foundation.h>
@class AVAudioMix;
@class AVAssetTrack;
@ivanlesko
ivanlesko / Debugging.h
Last active August 29, 2015 14:02
Include this file in your prefix.pch or any header for a better NSLog. It is based on ashikahmad's Better NSLog: https://gist.github.com/ashikahmad/4658632
//
// Debugging.h
//
// Created by Ivan Lesko on 6/24/14.
// Copyright (c) 2014 Ivan Lesko. All rights reserved.
//
/**
* Debugging.h is a nice macro that defines a better NSLog.
* Instead of showing the Project name and timestamp, it shows the Class, method, and line number the NSLog is called.