Skip to content

Instantly share code, notes, and snippets.

View ming-chu's full-sized avatar
:octocat:
Focusing

Kenneth Chu ming-chu

:octocat:
Focusing
View GitHub Profile
@gragera
gragera / gist:fab8a2eaa11dc63b9b9f
Last active September 3, 2018 13:15
Using swift generics for easier storyboard ViewController instantiation
import UIKit
extension UIStoryboard {
func instantiate<T>(identifier: String, asClass: T.Type) -> T {
return instantiateViewControllerWithIdentifier(identifier) as! T
}
func instantiate<T>(identifier: String) -> T {
return instantiateViewControllerWithIdentifier(identifier) as! T
@mayoff
mayoff / ViewController.m
Created June 14, 2013 23:53
Example of using auto layout to make a container view as tall as its tallest subview, but no taller. For http://stackoverflow.com/q/17117799/77567 .
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController {
UIView *containerView;
NSArray *subviews;
@lesstif
lesstif / pngquant-compile.sh
Created August 29, 2019 07:38
compile script for pngquant on RHEL/CentOS and Amazon Linux
#!/bin/bash
git clone https://github.com/kornelski/pngquant
cd pngquant
git checkout -b 2.12.3
sudo yum install libpng-devel -y
make
sudo make install
@muukii
muukii / MTKCIImageView.swift
Created September 28, 2015 05:32
CIImageView (Using Metal)
//
// MTKCIImageView.swift
// Fil
//
// Created by Muukii on 9/27/15.
// Copyright © 2015 muukii. All rights reserved.
//
import Foundation
import Metal
@bgayman
bgayman / FilterCam.swift
Last active September 25, 2022 00:42
Setup AVCaptureSession with CIFilter
//
// ViewController.swift
// CameraFilter
//
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
@ideawu
ideawu / AVFoundation write read audio file frame by frame
Last active November 4, 2022 20:53
AVFoundation write/read audio file frame by frame
#import <AVFoundation/AVFoundation.h>
#import "Recorder.h"
@interface Recorder()<AVCaptureAudioDataOutputSampleBufferDelegate>{
AVCaptureDevice *audioDevice;
AVCaptureDeviceInput *audioInput;
AVCaptureAudioDataOutput* _audioDataOutput;
dispatch_queue_t _captureQueue;
AVURLAsset *_asset;
@zrxq
zrxq / CropVideo.m
Created March 27, 2014 20:08
Crop video to square with a specified side respecting the original video orientation
@import MobileCoreServices;
@import AVFoundation;
@import AssetsLibrary;
// ...
- (void)cropVideoAtURL:(NSURL *)videoURL toSquareWithSide:(CGFloat)sideLength completion:(void(^)(NSURL *resultURL, NSError *error))completionHander {
/* asset */
@MihaelIsaev
MihaelIsaev / CameraViewController.swift
Created April 16, 2015 19:30
This is the example of camera view for iOS written in Swift
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@IBOutlet weak var myView: UIView!
var session: AVCaptureSession?
var device: AVCaptureDevice?
var input: AVCaptureDeviceInput?
@Sunlighter
Sunlighter / README.md
Last active August 28, 2023 20:35
Installing Python 3.7 in Amazon Linux 2

Installing Python 3.7 in Amazon Linux 2

This is a way to build Python 3.7 from source and temporarily install it in Amazon Linux 2 without overwriting the system Python and without interfering with the Python in amazon-linux-extras.

At the time of this writing, Amazon Linux 2 offers Python 2.7.14 and (through the extras) Python 3.6.2, but Python 3.7.0 was just released.

  1. Start Amazon Linux 2 and sign in. (I recommend a c5.large instance.)
@brennanMKE
brennanMKE / ProcessBuffer.Swift
Last active November 2, 2023 09:25
Process a CMSampleBuffer to modify the audio using an AVAssetReader and AVAssetWriter in Swift
func processSampleBuffer(scale: Float, sampleBuffer: CMSampleBuffer, writerInput: AVAssetWriterInput) -> Bool {
guard let blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer) else {
return false
}
let length = CMBlockBufferGetDataLength(blockBuffer)
var sampleBytes = UnsafeMutablePointer<Int16>.allocate(capacity: length)
defer { sampleBytes.deallocate(capacity: length) }
guard checkStatus(CMBlockBufferCopyDataBytes(blockBuffer, 0, length, sampleBytes), message: "Copying block buffer") else {
return false