Skip to content

Instantly share code, notes, and snippets.

@simonkim
simonkim / SwiftUIViewToViewEvent.swift
Last active January 16, 2024 12:53
Sending Event from SwiftUI View to View using Combine
import SwiftUI
import Combine
import PlaygroundSupport
struct ContentView: View {
var emitter = PassthroughSubject<(), Never>()
var body: some View {
VStack {
Text("Hello, world!")
.padding()
@simonkim
simonkim / DateConversionThroughCalendarTests.m
Last active August 10, 2018 12:15
NSDate comparison between original and converted through components and a calendar
//
// DateConversionThroughCalendarTests.m
// TestOnNSDateDateTests
//
// Created by Simon Kim on 10/08/2018.
// Copyright © 2018 SeoGiwon. All rights reserved.
//
#import <XCTest/XCTest.h>
@simonkim
simonkim / CaptureDeviceDiscovery.swift
Created June 8, 2018 05:46
How to check if an iOS camera support 4K capture
/*
* Does not require camera access permission
* Usage:
let tool = CaptureDeviceDiscovery()
let front = tool.videoCaptureDevice(at: .front)?.supportsSessionPreset(AVCaptureSession.Preset.hd4K3840x2160) ?? false
let back = tool.videoCaptureDevice(at: .back)?.supportsSessionPreset(AVCaptureSession.Preset.hd4K3840x2160) ?? false
self.labelStatusFront.text = front ? "Supported" : "Not supported"
self.labelStatusBack.text = back ? "Supported" : "Not supported"
@simonkim
simonkim / AVFEditor.swift
Created July 7, 2017 08:43
Swift version of AVCustomEdit sample clone without Custom Compositor
import Foundation
import AVFoundation
struct AVFTransition {
let duration: CMTime = CMTime(seconds: 1.0, preferredTimescale: 1000)
/// tracks must contain 2 elements
func instruction(at startTime: CMTime, tracks: [AVAssetTrack]) -> AVMutableVideoCompositionInstruction {
let timeRange = CMTimeRangeMake(startTime, self.duration)
let instTrans = AVMutableVideoCompositionInstruction()
@simonkim
simonkim / guard-let-vs-if-nil.swift
Created September 26, 2016 01:35
guard let vs. if nil
//: guard let example
func printifnonnil(text: String?) {
if text == nil {
return
}
// syntatically, unwrapping still required since text is still an optional
print(text!)
}
@simonkim
simonkim / CMBlockBufferHelper.swift
Created September 6, 2016 15:12
Sample code for creating NSData backed CMBlockBuffer using customBlockAllocator, in Swift.
//
// CMBlockBufferHelper.swift
//
// Created by Simon Kim on 2016. 9. 6..
// Copyright © 2016년 DZPub.com. All rights reserved.
//
import Foundation
import CoreMedia
/**
@simonkim
simonkim / rtp-sync-ntp.md
Last active January 25, 2024 16:40
RTP - Synchronizing media streams

RTP Note

Synchronizing media streams

Implementation of NTP is not required to use RTP.

An implementation is not required to run the Network Time Protocol in order to use RTP. -- 4. Byte Order, Alignment, and Time Format, [RFC 3550 RTP: A Transport Protocol for Real-Time Applications][1]

However, if NTP timestamp implemented in RTCP, it can be used to synchronize media streams even from different host!

@simonkim
simonkim / gist:6293029
Created August 21, 2013 10:56
4sq venue search api
<div id="names">
</div>
<script>
var query = escape('coffeingurunaru');
$.getJSON('https://api.foursquare.com/v2/venues/search?intent=global&query='
+ query
+ '&client_id=2POUFAUU4ZBJ2MTDOY3S2YHR2NIT52FYW0LUTPHBMNTJFJNQ&client_secret=YFDZI1YWV3ZI5S5SPM2DZJEQIEBPIDJ5XFZBWTIKIQZVQNYM&v=20120101',
function(data) {
$.each(data.response.venues, function(i,venues){
@simonkim
simonkim / sshow_load_img
Last active December 20, 2015 09:40
Loading an image dynamically and drawing in <canvas> without a static <img> tag in JavaScript
/* Application of HTML5 Canvas Image Tutorial at http://www.html5canvastutorials.com/tutorials/html5-canvas-images/ */
function sshow_load_img1(src, loaded) {
/* Loading image dynamically using jQuery */
var img = $("<img />").attr('src', src )
.load(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
alert('broken image!');
} else {
/* img is a jQuery object. Take DOM Element object out of it using .get(index) */