Skip to content

Instantly share code, notes, and snippets.

View trilliwon's full-sized avatar
🎯
Focusing

WonJo trilliwon

🎯
Focusing
View GitHub Profile
extension Array where Element: Hashable {
func counter() -> [Element: Int] {
return self.reduce(into: [:]) { counts, elem in counts[elem, default: 0] += 1 }
}
}
@trilliwon
trilliwon / swift-string-subscript.swift
Created September 23, 2018 04:59
Swift string subscript using Int value as index
extension String {
subscript(i: Int) -> Character? {
guard i < self.count else {
return nil
}
return self[self.index(self.startIndex, offsetBy: i)]
}
}
@trilliwon
trilliwon / cameraVideoScreenShot.m
Created September 26, 2018 17:46 — forked from zapsleep/cameraVideoScreenShot.m
AVFoundation Camera ScreenShot snippet
- (void)setupCaptureSession
{
NSError *error = nil;
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureDevice *device = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo];
@trilliwon
trilliwon / swift-array.swift
Created September 29, 2018 06:08
Swift Array Syntax
import Foundation
// MARK: Creating Array
var someInts = [Int]()
print("someInts is of type [Int] with \(someInts.count) items.")
// Prints "someInts is of type [Int] with 0 items."
someInts.append(3)
// someInts now contains 1 value of type Int
print("Swift is awesome ;;")
print("Swift", "is", "awesome", separator:" ")
print("Swift", "is", "awesome", separator:" ", terminator:".")
// Console
// Swift is awesome ;;
// Swift is awesome
// Swift is awesome.
@trilliwon
trilliwon / get-row-col.swift
Last active October 3, 2018 15:33
get-row-col.swift
func rowAndCol(s: Int, N: Int) -> (Int, Int) {
var s = s - 1
var row = N - (s / N) - 1
var col = row % 2 != N % 2 ? s % N : N - 1 - (s % N)
return (row, col)
}
let range = 0..<N
for row in range.reversed() {
let reversed: [Int] = range.reversed()
func isAlpha(char: Character) -> Bool {
switch char {
case "a"..."z":
return true
case "A"..."Z":
return true
default:
return false
}
}
@trilliwon
trilliwon / imageViewTransition.swift
Created November 30, 2018 09:28
transition images
UIView.transition(with: self.backgroundImageView,
duration: 0.7,
options: [.transitionCrossDissolve],
animations: { self.backgroundImageView.image = toImageA },
completion: { _ in swap(&toImageA, &toImageB) })
}
@trilliwon
trilliwon / xcrun-simctl.sh
Created December 1, 2018 07:52
screenshot, video recoding simulator xcode
xcrun simctl io booted screenshot 1r.png
xcrun simctl io booted recordVideo apppreview.mp4
ctrl + c # to stop
# https://shashikantjagtap.net/simctl-control-ios-simulators-command-line/
//
// ViewController.swift
// Playback
//
// Created by kyle.jo on 12/12/2018.
// Copyright © 2018 kyle.jo. All rights reserved.
//
import AVFoundation
import UIKit